Install APK programmatically on android

前端 未结 1 797
暖寄归人
暖寄归人 2020-12-14 04:47

I\'ve been trying to get an android application to install an APK on the sdcard programmatically but I\'m running into a little trouble.

This is how I\'m doing it:

相关标签:
1条回答
  • 2020-12-14 05:19

    You can add a receiver to your AndroidManifest.xml to listen to broadcasts if a new app is installed. Like this:

    <receiver android:name=".PackageReceiver">
        <intent-filter>
            <action android:name="android.intent.action.PACKAGE_ADDED" />
            <action android:name="android.intent.action.PACKAGE_CHANGED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="package" />
        </intent-filter>
    </receiver>
    

    This class then gets called when a new package is installed:

    public class PackageReceiver extends BroadcastReceiver {
    
      @Override
      public void onReceive(Context context, Intent intent) {
        // handle install event here
      }
    }
    
    0 讨论(0)
提交回复
热议问题