我已经使用了许多Google解决方案,但没有任何解决方案可以解决我的问题。我正在尝试做的是在用户尝试卸载我的应用程序时为用户输入pin /密码。
我看到了this链接,但我遇到了这个解决方案的2个问题,如下所示:
我在“我的应用程序”中注册了广播接收器,当我在设置中打开“我的应用程序”时,它似乎不起作用,但与其他应用程序一起正常工作。我的代码如下:
public void onReceive(Context context, Intent intent) {
/// fetching package names from extras
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("com.android.systemapplication")){
// User has selected our application under the Manage Apps settings
// now initiating background thread to watch for activity
new ListenActivities(context).start();
}
}
}
}
当我用一些不同的包名替换包名时,设置屏幕可以在广播接收器中检测到,然后在运行(线程)中它没有检测到卸载程序活动,请参阅我的ListenActivities如下:
public void run(){
Looper.prepare();
while(!exit){
// get the info from the currently running task
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(MAX_PRIORITY);
String activityName = taskInfo.get(0).topActivity.getClassName();
Log.d("topActivity", "CURRENT Activity ::"
+ activityName);
// here "activityName" is "com.android.launcher" if I select
// package name it is "com.android.launcher2.launcher".
if (activityName.equals("com.android.packageinstaller.UninstallerActivity")) {
// User has clicked on the Uninstall button under the Manage Apps settings
//do whatever pre-uninstallation task you want to perform here
exit = true;
Toast.makeText(context, "Done with preuninstallation tasks... Exiting Now", Toast.LENGTH_SHORT).show();
} else if(activityName.equals("com.android.settings.ManageApplications")) {
// back button was pressed and the user has been taken back to Manage Applications window
// we should close the activity monitoring now
exit=true;
}
}
Looper.loop();
}
我看到很多解决方案但没有成功。如果它已被弃用,请显示一些Android文档,因为我可以看到防病毒可以像我要求的那样做。代码会更有帮助。 ?任何帮助都会有所帮助。