0

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?

0xAliHn
  • 18,390
  • 23
  • 91
  • 111
  • I don't understand your question. You say you are already doing the things and then you ask how to do that? Please explain in more detail what you are doing and what you aren't doing, but need assistance with. – David Wasser Jul 22 '16 at 13:05
  • @DavidWasser Yes, I can do it using a third party app like launcher app who is actually responsible for receiving main app package changes broadcast status and send it to the back-end. My question is can i do the same things without any third party app help. Using only my main app. – 0xAliHn Jul 25 '16 at 10:12

1 Answers1

0

You can have your own application catch the broadcast Intent, just like the launcher app. Then you can do what you want. Create a BroadcastReceiver in your application and add these entries to the manifest:

 <receiver android:name=".MyBroadcastReceiver">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
        </intent-filter>
    </receiver>

You don't need the <category> or <data> tags and it is pointless to listen for PACKAGE_REMOVED because if your app is removed you won't get triggered anyway.

David Wasser
  • 93,459
  • 16
  • 209
  • 274
  • I can't receive the broadcast receiver form my application itself. I have implemented this in my application and install it in the device then first uninstall the package(adb uninstall packagename) after that install the apk (adb install apk) but after installing I couldn't get any log in BroadcastReceiver. That means BroadcastReceiver is not calling. – 0xAliHn Aug 01 '16 at 13:15
  • No, if you uninstall and then reinstall this won't work. You said in your question that you are doing an OTA "update". I assumed that you were **updating an existing application**. If your app is being uninstalled and then reinstalled, you can't do anything because your app will need to be started manually first before it can do anything. – David Wasser Aug 01 '16 at 15:07
  • If you don't want to use a third-party tool to manage this, you could write another app yourself. That app would be installed on the device and it would watch for app installs/removals and it could automatically start your app when it gets installed and could automatically update your server (just like the 3rd party app). This would have to be a separate application though. – David Wasser Aug 01 '16 at 15:09
  • Yes, I have already done this and working fine. Problem is I need to have only one app in the device. No third party app. By the way thanks for your help. – 0xAliHn Aug 01 '16 at 18:30
  • This cannot be done with a single application if the application gets uninstalled and reinstalled. Sorry. – David Wasser Aug 01 '16 at 19:59