I'm developing a non-public Android app, i.e. the app won't be available in the global Android Market. The app will be installed on a limited number of clients, e.g. by using an apk file.I Have an .apk in SD Card and I am trying to update my application from my application. For that, I'm Using Intent
My Code
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory().getPath()+"/" +"Test.apk")), "application/vnd.android.package-archive");
startActivity(intent);
NOTE : It is working fine, but after updating it, application will be closed.
The question is "How to Prevent This ?"
I'm also use Broadcast Receiver For Re-Open my app
public class AutoStart extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
     if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
            Intent i = new Intent(context, ABCActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
    }else{
        
         Intent i = new Intent(context, XYZActivity.class);
         i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         context.startActivity(i);
    }
}
Problem 1 :- Can't Re-Open Activity When
"android.intent.action.PACKAGE_ADDED",
"android.intent.action.PACKAGE_INSTALL",
"android.intent.action.PACKAGE_CHANGED"
<receiver
        android:name=".AutoStart"
        android:enabled="true"
        android:exported="true" >
       
        <intent-filter android:priority="100" >
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
        
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <data android:scheme="package" />
        </intent-filter>
        
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_INSTALL" />
            <data android:scheme="package" />
        </intent-filter>
        
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <data android:scheme="package" />
        </intent-filter>
        
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_REPLACED" />
            <data android:scheme="package" />
        </intent-filter>
        
    </receiver>
"android.intent.action.BOOT_COMPLETED" Working Properly
Permissions Given
1 >     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
2 >     <uses-permission android:name="android.permission.RESTART_PACKAGES" />
3 >     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />