MTu*_*ash 5 android auto-update broadcastreceiver
我有以下应用程序场景:1) 一个自行更新的应用程序 2) 设备已植根 3) 在线检查版本,如果新版本在线,它会下载“apk”文件并安装它
一切正常,但新版本安装后应用程序不会重新启动。我试图设置 MY_PACKAGE_REPLACED 广播接收器,但它从未被调用。应用程序安装新的并停止,但应用程序中的接收器从未被触发。
我究竟做错了什么?
代码:清单
<receiver android:name=".receivers.OnUpgradeReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
我尝试了带有 DATA 部分的接收器清单代码而没有......但它仍然不起作用!!
广播接收器类
public class OnUpgradeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String msg="intent:"+intent+" action:"+intent.getAction();
Log.e("OLE","RECEIVEEEEEEEEEEEEEEEEEEEEEED: "+msg);
}}
Run Code Online (Sandbox Code Playgroud)
APP更新部分
Process p;
try {
//Runtime.getRuntime().exec (new String[]{"su", "-c", "pm install -r " + apkLocation + "party.net"});
// Preform su to get root privledges
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("/system/bin/pm install -r"+apkLocation+"\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
Log.e("OLE","Sucess :-)");
}
else {
Log.e("OLE","Fail 1");
}
} catch (InterruptedException e) {
Log.e("OLE","Fail 2");
}
} catch (IOException e) {
Log.e("OLE","Fail 3 "+e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
解决了! 问题是在上一个上面安装的新版本没有设置广播接收器!!!
| 归档时间: |
|
| 查看次数: |
1833 次 |
| 最近记录: |