1

I have developed an application(Test)such that whenever the application has updates with the latest version it will download and install the latest .apk file.

Now I want the latest version of application to launch/open by itself after updating. For now I am manually launching the application after update. I want it to do by itself.

Please Help..

Thanks

Shruti Joshi
  • 53
  • 1
  • 10
  • Let the Play Store handle the updates... – Phantômaxx Feb 16 '16 at 08:15
  • 1
    I am not placing my app in play store. This is a non market app..!!!!. – Shruti Joshi Feb 16 '16 at 08:24
  • 1
    So why do you bother to update it? Or, since you will have 4 or 5 users, just send them the new apk via eMail. – Phantômaxx Feb 16 '16 at 08:26
  • Thats not the standard way i believe. I cannot count on my users. I am working for a product. There may be n number of users – Shruti Joshi Feb 16 '16 at 08:29
  • 2
    Hello @ShrutiJoshi did you got any success with it,? I am also looking for the same functionality for my app. I believe when you install an apk, you need to start it once to register it in Android System. and thn all your recivers become active. – asadnwfp Aug 20 '18 at 07:46

2 Answers2

3

Android throws broadcast on installing app . You could receive it in receiver and launch from there.

<receiver
    android:name="com.your.receiver"
    android:enabled="true"
    android:exported="true" >
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                    <data android:scheme="package"/> 
                </intent-filter>
     </receiver>

 <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />

In receiver add this :

@Override
    public void onReceive(Context context, Intent intent) {
        //start activity
        Intent i = new Intent();
        i.setClassName("com.pkg", "com.pkg.yourStartActivity");
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
Manishika
  • 5,478
  • 2
  • 22
  • 28
  • This solution worked for me, and i managed to relaunch my app after i reinstalled programatically. That was 2 month ago. Now i switched to android 8 and its not working... Is that related? Or maybe i missing something? – Moshe Yamini Jul 08 '20 at 09:25
  • @MosheYamini Were you missing something ? – SysHex Jun 23 '21 at 10:07
0

This is the intent filter you have to set for your broadCastReceiver

 <receiver android:name="com.your.receiver">
            <intent-filter>
                <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
            </intent-filter>
        </receiver>
Pedif
  • 144
  • 8