我想制作一个应用程序,如果用户尝试卸载我的应用程序,我想在其中接收信号或其他任何东西 有什么办法吗? 请帮忙
这是我的演示应用程序 list
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uninstalldefence"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.uninstalldefence.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.example.uninstalldefence.BootReceiver"
android:label="Bilal" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="Package" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RESTART_PACKAGES" />
<Uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
这是我的广播接收器。但它没有用 你能提供任何帮助吗? 包 com.example.uninstalldefence;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.widget.Toast;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Receive install the radio
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
String packageName = intent.getDataString();
System.out.println("installed:" + packageName
+ "package name of the program");
Toast.makeText(context.getApplicationContext(), "Added!",
Toast.LENGTH_LONG).show();
}
// Receive uninstall broadcast
if (intent.getAction().equals("android.intent.action.PACKAGE_REMOVED")) {
String packageName = intent.getDataString();
System.out.println("uninstall:" + packageName
+ "package name of the program");
Toast.makeText(context.getApplicationContext(), "Removed!",
Toast.LENGTH_LONG).show();
}
}
}
最佳答案
Is it possible to detect Android app uninstall?
这是一个帖子。我不知道您的确切应用程序,但您可以让用户在每次启动应用程序时广播一个唯一的 ID。通过这种方式,您可以收集您拥有的“活跃”用户数量,而不是人们如何安装您的应用。
1) 如文档中所述,在安装您的应用程序之前无法运行代码。
Broadcast Action: An existing application package has been removed from the device. The data contains the name of the package. The package that is being installed does not receive this Intent. http://developer.android.com/reference/android/content/Intent.html#ACTION_PACKAGE_REMOVED
关于Android 应用程序卸载监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24660638/