简体   繁体   中英

How to autostart app after install app in android?

I am update my app from server, first download from my server then ask for install after I select install then not ask for open or done why?


Explanation of my issue...

I have one app remember not in playstore. It store in my own server. I set update process for it.

  1. First check version.
  2. version not match then download from my server.
  3. After download it auto install.
  4. At installation time I get install button when I pressed Install button then it install background and current app closed.
  5. After installation it not give me Open or Done option for open app.

My problem is 5th point.

Copy below code in Menifest.xml file

  <receiver
    android:name="com.example.extraApp.InstallReceiver"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.PACKAGE_INSTALL" />
        <action android:name="android.intent.action.PACKAGE_ADDED" />
        <data android:scheme="package"/>
    </intent-filter>
</receiver>

Creat new java class copy below code in it

public class InstallReceiver extends BroadcastReceiver{    
@Override
public void onReceive(Context context, Intent intent) {
    try {
        Intent new_intent = context.getPackageManager().getLaunchIntentForPackage("com.example.updaterjschtest");
        context.startActivity(new_intent);
    } catch (Exception e) {
        e.printStackTrace();
    }   
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM