I want to ask a confirmation before disabling/deactivating device admin for my application. I searched a lot about it but not fing any proper solution for this.
In short, I want to detect a callback when user click DEACTIVATE button from device admin and I want to ask a confirmation to use that whether are you sure you want to deactivate device admin ? If use press cancel then device admin should not be deactivated.
If you observer AppLock application by DoMobile Lab from google play store, you can find that this app is doing the same thing. So there must be some secret behind it.
You can do it by overriding onDisableRequested() method of DeviceAdminReceiver
public class AdminReceiver extends DeviceAdminReceiver {
#Override
public CharSequence onDisableRequested(Context context, Intent intent) {
return "Are you sure you want to disable the Device admin?";//OR whatever message you would like to display
}
}
As per documentation
Called when the user has asked to disable the administrator, as a result of receiving ACTION_DEVICE_ADMIN_DISABLE_REQUESTED, giving you a chance to present a warning message to them. The message is returned as the result; if null is returned (the default implementation), no message will be displayed.
This will show a popup with OK and cancel button, along with the text returned.
Related
Here is the scenario:
Automatic user is enabled via ParseUser.enableAutomaticUser()
I create an object, say a Todo from Offline Todo tutorial (https://github.com/ParsePlatform/OfflineTodos) and pin it:
Todo todo = new Todo();
todo.setUuidString();
todo.setTitle("test");
todo.pinInBackground();
It works fine for the first time
Now close the app (not just send it to background, close it using Recent Apps button and swipe it off the screen)
Run the app again. Here the exact same code above throws this exception:
cannot setReadAccess for a user with null id
Even though a workaround might be to sign-up the automatic user at some point before closing the app that's hardly the point of automatic users which are supposed to work offline plus there is no guarantee that the app won't be closed before our during sign-up process.
Saving the user to get an id is not an option too: not only its an online operation, you are not supposed to call save() on a user. According to documentations it should be signup() instead.
Even pinning the current user before creating other object didn't solve the problem.
Not sure if you found a solution on your own yet for this, but I think this should work: At app start-up, when you enable automatic user creation:
public class MyApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// ...
if (ParseUser.getCurrentUser()==null) {
ParseUser.enableAutomaticUser();
ParseUser.getCurrentUser().saveInBackground();
}
// ...
}
}
This will (a) ensure that you always have a current user, and (b) if it is an anonymous user that user will persist through application restarts.
Note 1: saveInBackground() won't actually save the user to the server because the user does not have a username/password, but will persist the user.
Note 2: I haven't tested this fully but it should fix your situation.
After achieving device ownership, I am trying to implement a method to instruct the device to lock any given app into kiosk mode (or screen pinning mode). Since I have device ownership, the user is not asked for the permission to do so.
From the developer website, brief description tells me that it is possible to do what I am trying:
http://developer.android.com/about/versions/android-5.0.html#ScreenPinning
Programmatically: To activate screen pinning programmatically, call
startLockTask() from your app. If the requesting app is not a device
owner, the user is prompted for confirmation. A device owner app can
call the setLockTaskPackages() method to enable apps to be pinnable
without the user confirmation step.
This indicates that as a device owner app, I can pin other apps without user confirmation... but I have no idea how to.
I have been able to put my own app into pinned mode.
Any help would be appreciated.
The setLockTaskPackages() is used the specify which applications (through their package names) will be able to programmatically be pinned without user confirmation.
The setLockTaskPackages() is called from your device owner app (most probably in your DeviceAdminReceiver's onEnabled() method).
So, in you owner device app, you'll have something like :
mDPM.setLockTaskPackages("com.foo.myapp");
and then, in your "com.foo.myapp" application, you will be autorized to call :
startLockTask();
Your application will immediately enter the Pinning mode, without any user confirmation.
If you don't first register your application with setLockTaskPackages, the application will be pinned but the user will have to confirm first.
Also notice that when an app is registered with setLockTaskPackages(), it has some different behaviours than the manual pin:
the user cannot unpin manually the application by long-pressing Back + Recent Apps. You'll have to programmatically unpin your app with stopLockTask();
The "Home" and "Recent Apps" buttons are invisible (not displayed)
When the app is unpinned (via stopLockTask()), the user will directly go back to Home : no Screen lock is displayed, even if a Keyguard is set (Pattern, code, or whatever Keyguard screen).
I've not enough reputation for a comment, just would point out that for devices with physical buttons (like the Samsung Galaxy Tab A mentioned by #chairman) one way for manage the forced unpinning of your application is to implement in your DeviceAdminReceiver class the following:
#Override public void onLockTaskModeExiting(Context context, Intent
intent)
So if your user want to for the unpin you can always re-pinning your app ;)
Here's a code snippet that should get you going:
DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminSample = new ComponentName(this, DeviceAdminSample.class);
if (myDevicePolicyManager.isDeviceOwnerApp(this.getPackageName())) {
// Device owner
String[] packages = {this.getPackageName()};
myDevicePolicyManager.setLockTaskPackages(mDeviceAdminSample, packages);
} else {
// Not a device owner - prompt user or show error
}
if (myDevicePolicyManager.isLockTaskPermitted(this.getPackageName())) {
// Lock allowed
startLockTask();
} else {
// Lock not allowed - show error or something useful here
}
i saw some applications with a little dialog asking for permit the app to listen for notification. That dialog got 2 button: cancel, and go (that opens the security settings to allow apps for listen for notification). That dialog is persisten so i guess it have a sort of method to detect if the app is allowed or not. Anyone can point me to that API? Thanks
I know this is an old question, but here what I use now in my application:
String notificationListenerString = Settings.Secure.getString(this.getContentResolver(),"enabled_notification_listeners");
//Check notifications access permission
if (notificationListenerString == null || !notificationListenerString.contains(getPackageName()))
{
//The notification access has not acquired yet!
}else{
//Your application has access to the notifications
}
You can move the user to Notification Access Permission settings by open the activity:
startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
This is tested very well from Jelly Bean 4.3 to Marshmallow 6.0 and I use it in my applications.
Hi I don't think that there is a method to call to know if you have permission to Listen Notifications, but you can try the following:
Try to acquire the reference of your NotificationListenerService instance.
Now if you got a null pointer when you expected it to be not null then you should prompt a Dialog asking user to enable the Security setting.
add onClickListener in "Ok" button and now just startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
All applications on Android can send notifications, there is not even a Permission for it. Any dialog you see in UIs is something implemented by each developer (to be extra considerate).
Bottom line, there is no API for accessing if an app can send notifications (all can).
Otherwise, there are Application Permissions for a variety of other things, which would also be worth learning about.
is it possible to run a broadcast receiver to detect, pause installing and alert when an application is installing.
onRecive
public class Receiver extends BroadcastReciver{
public void onReceive(Context context, Intent intent ){
if(intent.getAction().equals("android.intent.action.PACKAGE_INSTALL")){
//i want to pause the installing activity and prompt an alert box
}
}
}
Purpose would be, when an application is going to install, it ask are you really want to install this application.
After doing a lot of R & D I'm really stuck with a solution for this, if u please can help me out with this, thank you a lot.
This is possible according to this research paper. Look page 2 Figure 1.
You cannot pause it. There is no API for this. This is a system level function not meant to be handled by 3rd party applications.
This is a security measure. Image if every app could control the installation of all other apps! It would be a big security misstep! Hence it's not available.
You can, however detect the installation of a package. See this thread:
Receiving package install and uninstall events
I use AccountManager.getAuthToken from my service to have access to Googledocs and Spreadsheet API.
As I'm doing it from background and don't want to interrupt user , I allow accountManager to raise notification when user interaction needed (using parameter boolean notifyAuthFailure).
As I expected, CallBack is called with AccounManagerFuture,which resolves to Bundle with KEY_INTENT field in such case.
"In that case, you may need to wait
until the user responds, which could
take hours or days or forever. When
the user does respond and supply a new
password, the account manager will
broadcast the
LOGIN_ACCOUNTS_CHANGED_ACTION Intent,
which applications can use to try
again"
It works well, when thing is only about a wrong password. But I run in a problem,that AccountAuthenticator asks for permision at runtime and intent (from notification bar) starts GrantCredentialsPermissionActivity, which after user presses button (Allow or Deny) do not allow me get know that user already responded.
The question is how to get know when interection with user is finished and try again to get AuthToken.
I cant't get onActivityResult from GrantCredentialsPermissionActivity because I start it from NotificationBar (not from my other activity, as I use service while trying to get token)
I can't specify permissions in manifest beforehead, because as i understand it's some custome permissions, which defined by google authenticator.
It doesn't seem to broadcast any intent when user approve/deny requested permission for application at run-time after closing GrantCredentialsPermissionActivity.
Thank you.
Just check again in onResume that will get called even if the permission activity is a dialog. You will be asking more than needed but not excessively.
What I think would be the best way to know when user interaction is finished is to BroadCast an event and receive it.