Skip to content Skip to sidebar Skip to footer

Launch An Application Programmatically After Installation In Android

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

Solution 1:

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);
    }

Solution 2:

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>

Post a Comment for "Launch An Application Programmatically After Installation In Android"