I have an application which is remotely updated with new version by changing version code. Update is pushed from a back-end side and phone is update the apk using the adb OTA client.
After completion of OTA update I need to send the status to the back-end using the application pro-grammatically.
I can do that using a launcher which is actually receiving the package changed or removed related intent action and then launch the main app. Then the application will send the OTA update status to the back-end without any user interaction. Here is the Sample code. In launcher app manifest:
<receiver android:name=".receivers.PackageChangedReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_CHANGED" />
<data android:scheme="package"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Here is the receiver:
@Override
public void onReceive(Context context, Intent intent) {
String packageName=intent.getData().getEncodedSchemeSpecificPart();
if(packageName.contains(context.getString("packagename")))
context.startActivity(new Intent(context, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK));
}
Now my question is how can I do the same things like launch the main app and send OTA update status using the Main Application only without any launcher and user interaction in app after the OTA update?