Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open my android program after update

I use https://stackoverflow.com/a/14353076/1327384 to update my android program , but after updating my program it will be closed so I want to reopen it after completing the update process , how can I do that ?

I used this class

package services;
    public class PackageChangeReceiver extends BroadcastReceiver {
         @Override
            public void onReceive(Context ctx, Intent intent) {
            Uri data = intent.getData();
            boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);

            Intent intent1 = new Intent(ctx, service.class);
            ctx.startService(intent1);
            Log.d("service", "Action: " + intent.getAction());
            Log.d("service", "The DATA: " + data);
            }

    }

and this mainfest

 <receiver android:name="services.PackageChangeReceiver" >
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <action android:name="android.intent.action.PACKAGE_ADDED" />

                <data android:scheme="package" />
            </intent-filter>
        </receiver>

but I still receive the intent after I start the app manually

like image 344
Mohammed Subhi Sheikh Quroush Avatar asked Feb 23 '13 21:02

Mohammed Subhi Sheikh Quroush


2 Answers

a) Take a look at android.intent.action.PACKAGE_REPLACED.

b) I believe if your app has a sticky service then this service is restarted after package update.

like image 93
Victor Ronin Avatar answered Sep 20 '22 14:09

Victor Ronin


May be AlarmManager can help? You can set task to start Activity of your app for example in 40 seconds after your apk downloaded and user clicked to install it.

like image 26
Artem Zinnatullin Avatar answered Sep 19 '22 14:09

Artem Zinnatullin