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.
My code for Receiver:
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
}
}
}
Manifest:
<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.
I think
intent.getExtra("com.android.settings.ApplicationPkgName")
should have the package nameWhen 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.
The receiver code will be something like this :
i dont know if its acceptable
setting package by getting packagename from the context of activity
and to get package name
I personally think this behavior is annoying. And for sure it's redundant: there are other mechanisms already on place that tackle the same problem (screen locking, encryption).
I'd only use extra checks when operations are on your side (ie.: delete account, change email, etc).
If I didn't make it to discourage you to do that here's another post that solves the same problem following a similar direction.