PACKAGE_ADDED
とPACKAGE_INSTALL
インテントを受信できるBroadcastReceiverを作成する必要があります。
InstallBroadcastReceiver.Class
public class InstallBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(Intent.ACTION_PACKAGE_ADDED)
||action.equals(Intent.ACTION_PACKAGE_INSTALL)){
notifyServerForApplicationInstall(context, intent);
}
}
private void notifyServerForApplicationInstall(Context context,Intent intent){
//send the data to your server here
}
}
受信者をAndroidManifest
ファイルに登録する
<receiver
android:name=".InstallBroadcastReceiver"
android:exported="false"
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_INSTALL" />
<data android:scheme="package" />
</intent-filter>
</receiver>
マニフェストでこの権限を与えることを忘れないでください:
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>