我試圖跟蹤APK安裝。當用戶登錄下載頁面(而不是商店)時,他來自特定的源。當用戶點擊下載時,APK將被安裝。安裝完成後,我需要將安裝映射到用戶在安裝之前來源。有沒有什麼好方法可以做到這一點?如何跟蹤的APK安裝
我的計劃至今:在下載頁面上的用戶IP和屏幕分辨率保存到數據庫中。安裝完成後,將IP和屏幕分辨率傳遞給服務器,並與數據庫中的行進行映射。這是做這件事的好方法嗎?
希望你們能幫助我。
我試圖跟蹤APK安裝。當用戶登錄下載頁面(而不是商店)時,他來自特定的源。當用戶點擊下載時,APK將被安裝。安裝完成後,我需要將安裝映射到用戶在安裝之前來源。有沒有什麼好方法可以做到這一點?如何跟蹤的APK安裝
我的計劃至今:在下載頁面上的用戶IP和屏幕分辨率保存到數據庫中。安裝完成後,將IP和屏幕分辨率傳遞給服務器,並與數據庫中的行進行映射。這是做這件事的好方法嗎?
希望你們能幫助我。
你只需要編寫這樣的廣播接收器,可以接收PACKAGE_ADDED
和PACKAGE_INSTALL
意圖:
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>
Don 「忘記在清單給這個權限:
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
我已經準備一個BroadcastReceiver類:
public class newPackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("DEBUG"," test for application install/uninstall");
}
}
在主活性,我首先註冊一個新的接收器對象,然後,應用程序實例化按鈕安裝。
public void onCreate(Bundle savedInstanceState) {
...
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
filter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
filter.addAction(Intent.ACTION_PACKAGE_INSTALL);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addAction(Intent.ACTION_PACKAGE_REPLACED);
filter.addAction(Intent.ACTION_PACKAGE_RESTARTED);
receiver = new newPackageReceiver();
registerReceiver(receiver, filter);
...
dlButton.setText(R.string.dl_button);
dlButton.setOnClickListener(new AppliDownloadOnClickListener(this));
@Override
public void onDestroy(){
unregisterReceiver(receiver);
super.onDestroy();
}
感謝這麼遠!在ip和屏幕尺寸上映射源代碼是一種好方法嗎?或者有更好的方法嗎? – John 2013-03-03 21:47:39
首先,如果接收器沒有導出,它就不能響應這些廣播。其次,該許可與這些廣播AFAIK無關。第三,這與OP的問題沒有關係,因爲'android.intent.action.PACKAGE_ADDED'沒有發送到已安裝的應用程序,也沒有在OP的Web服務器上運行。 – CommonsWare 2013-03-03 21:54:36
<用途的許可機器人:名稱=「android.permission.INSTALL_PACKAGES」 />僅用於系統應用程序? – Tushar 2013-05-23 19:39:42