问题描述
我想获得的包名和类名接收意图
,但我不能够得到它。
我要让我的应用程序的安全,因此正在卸载之前询问密码。只有谁安装的应用程序,用户知道密码,所以只有他/她可以卸载该应用。
I want to get the package name and class name of the received intent
, But am not able to get it.I want to make my app secure so it asks for password before being uninstalled. Only the user who Installed the app knows the password, so only he/she can uninstall the app.
我的code为接收器:
public class PackageReceiver extends BroadcastReceiver {
@ Override
public void onReceive (Context context, Intent intent) {
if (intent.getAction().equals("android.settings.APPLICATION_DETAILS_SETTINGS")) {
/ / TODO:
//I want here to get this getAction working and then I want to fetch package and class of the intent
}
}
}
清单:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RESTART_PACKAGES"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<Application
android: icon = "@ drawable / ic_launcher"
android: label = "Test">
<Receiver android: name = ". PackageReceiver"
android: label = "@ string / app_name">
<intent-filter>
<action android:name="android.settings.APPLICATION_DETAILS_SETTINGS" />
<data android:scheme="package" />
</ Intent-filter>
</ Receiver>
</ Application>
请让我知道如果我错过任何权限,因为我不能得到这个工作。
Please let me know if I am missing any permission because I can not get this working.
推荐答案
当我们选择设置屏幕内特定的应用程序,该类型的广播:android.intent.action.QUERY_PACKAGE_RESTART与应用程序的包名解雇一个额外的。我想,你可以用它来火密码对话框。
When we select a particular app inside the settings screen, a broadcast of the type : android.intent.action.QUERY_PACKAGE_RESTART is fired with package name of the application as an extra. I think you could use that to fire the password dialog.
接收器code将是这样的:
The receiver code will be something like this :
public void onReceive(Context context, Intent intent) {
String[] packageNames = intent.getStringArrayExtra("android.intent.extra.PACKAGES");
if(packageNames!=null){
for(String packageName: packageNames){
if(packageName!=null && packageName.equals("our_app_package_name")){
//Our app was selected inside settings. Fire Password Dialog.
}
}
}
}
这篇关于接收的意图和QUOT; android.settings.APPLICATION_DETAILS_SETTINGS&QUOT;我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!