问题
I have the following app scenario: 1) an app which updates by itself 2) the device is rooted 3) the checks for the version online and if new version is online it downloads the 'apk' file and installs it
Everything works fine but the APP does not restart after the new version install. I tried to set the MY_PACKAGE_REPLACED Broadcast Receiver, but it is never called. The app install new and stops but the receiver in the app is never triggered.
What am I doing wrong?
The code: MANIFEST
<receiver android:name=".receivers.OnUpgradeReceiver">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
I tried the receiver manifest code with the DATA part and without ... and it still does not work!!
BROADCAST RECEIVER CLASS
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);
}}
APP UPDATE PART
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());
}
SOLVED! The problem was that the new VERSION which was installed above the previous one did not have the broadcast receiver set!!!
来源:https://stackoverflow.com/questions/39024683/broadcast-receiver-my-package-replaced-never-called