Android 广播接收器MY_PACKAGE_更换从未呼叫
我有以下应用程序场景: 1) 自动更新的应用程序 2) 该设备已根化 3) 检查版本是否联机,如果新版本联机,则下载并安装“apk”文件 一切正常,但新版本安装后应用程序不会重新启动。我试图设置MY_PACKAGE_替换的广播接收器,但它从未被调用。应用程序安装新的并停止,但应用程序中的接收器从未触发 我做错了什么 守则: 显示 应用程序更新部分Android 广播接收器MY_PACKAGE_更换从未呼叫,android,broadcastreceiver,auto-update,Android,Broadcastreceiver,Auto Update,我有以下应用程序场景: 1) 自动更新的应用程序 2) 该设备已根化 3) 检查版本是否联机,如果新版本联机,则下载并安装“apk”文件 一切正常,但新版本安装后应用程序不会重新启动。我试图设置MY_PACKAGE_替换的广播接收器,但它从未被调用。应用程序安装新的并停止,但应用程序中的接收器从未触发 我做错了什么 守则: 显示 应用程序更新部分 Process p; try { //Runtime
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());
}
解决了强>
问题是安装在前一个版本之上的新版本没有设置广播接收器 如果新应用程序未运行,则无法接收新应用程序的意图,最好的解决方案是使用另一个应用程序B接收意图并运行新应用程序A。已解决!问题是安装在前一个版本之上的新版本没有设置广播接收器!!!我不能让它工作-你用的是什么android版本?我的也不工作,现在从android O开始,我们不能使用INTENTOk替换的软件包,同样的问题也可以在一些华硕设备上发现,请参考,android.intent.action.PACKAGE被替换的软件包被弃用并被android.intent.action.MY_替换()此外,您似乎不再需要在清单接收者声明中使用。()
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);
}}
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());
}