In my application I have the necessity to know when the user grants the "Draw over other apps" permission. Is there a way to know it?
Since I can only send the user to the settings page to enable it using the Settings.ACTION_MANAGE_OVERLAY_PERMISSION intent action, I'd expect a system broadcast or something like that.
Unfortunately there isn't a system broadcast, but you can use canDrawOverlays (Context context):
An app can use this method to check if it is currently allowed to draw
on top of other apps. In order to be allowed to do so, an app must
first declare the SYSTEM_ALERT_WINDOW permission in its manifest. If
it is currently disallowed, it can prompt the user to grant it this
capability through a management UI by sending an Intent with action
ACTION_MANAGE_OVERLAY_PERMISSION.
You can check it directly in your onActivityResult:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (Settings.canDrawOverlays(this)) {
//Permission is granted
}
}
}
Related
I've used keyguard manager inside my app to perform some action if and only if the user authenticates using his default device lock credentials, now what is happening is that my device has both fingerprint and pattern/pin lock enabled and when the keyguard manager checks the authentication using isKeyguardSecure method, it starts an activity for result and opens the intent using .createConfirmDeviceCredentialIntent...Now in this intent it asks for the fingerprint by default and gives an option for pin/pattern...I want to disable the fingerprint option in my app, and do not want to remove the fingerprint security from the device itself, just disable it for that particular app or intent.
This is my code:
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
Intent screenLockIntent = keyguardManager.createConfirmDeviceCredentialIntent(title, description);
startActivityForResult(screenLockIntent, LOCK_REQUEST_CODE);
Getting the result in this method
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(LOCK_REQUEST_CODE == requestCode){
if (resultCode == RESULT_OK) {
//Authentication is successful
My App works now
} else {
//Authentication failed
}
}
}
Screenshot showing the fingerprint authentication which I want to remove
This all is working fine, I just want to remove the fingerprint authentication for this particular app and just use the pin/password option...
Thanks in advance ;-)
You can't do that if you are using createConfirmDeviceCredentialIntent(), as this is a system intent and you can't change it. Generally, the screen lock is manged by the OS and will support whatever has been set up (face, fingerprint, iris, PIN, etc.)
You could implement a custom PIN only screen in your app, but that's tricky to do and generally less secure than the one provided by the OS.
I'm trying to open a pdf file from my app , on my device currently installed 3 3rd party apps to open pdf file. when the system asks me on witch of them to open the pdf, how can i know if the user selects one and presses "ok" or "decline"? my actions defined by if he accepts or declines
This is in my class :
String path="...../file.pdf";
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "application/pdf");
startActivityForResult(intent, 225);
And then in the activity :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Check which request we're responding to
if (requestCode == 225) {
// Make sure the request was successful if (resultCode == RESULT_OK)
} else {
}
}
screen shot for example
You can find all of the apps on the device that can service your Intent using the following code:
List<ResolveInfo> pkgAppsList = context.getPackageManager().queryIntentActivities( mainIntent, 0);
You can use the information from this to query the packages and learn their display name and icons (SO has plenty of answers how to do that).
You can create your own Dialog from within your app that looks identical to the system dialog. In this way you'll be able to track hits and pass the intent to the selected package directly.
Good luck!
how can i know if the user selects one and presses "ok" or "decline"?
You can't. ACTION_VIEW that is used to open a pdf in an external app does not give back any information. You can use startActivityForResult() but it will not have any effect because a result will not be set. Also see ACTION_VIEW documentation.
You should redesign your concept/logic so that it does not depend on this information.
I have created an app which continuously run in background and show an floating overlay TextView(By using the permission android.permission.SYSTEM_ALERT_WINDOW).
I have problem in Lenovo android devices, when other applications try to request for user permission there is an alert dialog says "Screen Overlay Detected". While I have test the same application on Redmi 3S Prime device the "Allow" button in permission dialog is not clickable, until I have turned off the Floating Overlay TextView in my application.
So is there any solution to resolve this device specific issue? One of the possible solution may be disable floating TextView while permission dialog is visible to user and show floating overlay when permission dialog is closed, but the problem is how can I detect the permission dialog open/close state for other foreground application from my app.
Please suggest...
Unfortunately it seems that this is inherent to the Android OS, and as far as I know there is no way to detect when another app is requesting permissions. The general flow for interacting with other apps is to send intents to them in a push manner, so theoretically it could be done if the other apps send an intent to your app to disable the overlay, though this is not a practical solution.
I could be completely wrong, but I am yet to see a programmatic solution to this problem. The best you can probably do is warn your users that your app may cause this problem, and provide them with a quick temporary disable button.
how can I detect the permission dialog open/close state from my app??
Implement Method Mentioned Below, to run this check at the onCreate of the first Activity
public final static int PERM_REQUEST_CODE_DRAW_OVERLAYS = 1234;
/**
* Permission to draw Overlays/On Other Apps, related to
'android.permission.SYSTEM_ALERT_WINDOW'
in Manifest
Resolves issue of popup in Android M and above "Screen overlay detected- To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
If app has not been granted permission to draw on the screen, create an Intent &
set its destination to
Settings.ACTION_MANAGE_OVERLAY_PERMISSION
&
* add a URI in the form of
"package:"
to send users directly to your app's page.
Note: Alternative Ignore URI to send user to the full list of apps.
public void permissionToDrawOverlays() {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, PERM_REQUEST_CODE_DRAW_OVERLAYS);
}
}
}
Called on the activity, to check on the results returned of the user action within the settings
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PERM_REQUEST_CODE_DRAW_OVERLAYS) {
if (android.os.Build.VERSION.SDK_INT >= 23) { //Android M Or Over
if (!Settings.canDrawOverlays(this)) {
// ADD UI FOR USER TO KNOW THAT UI for SYSTEM_ALERT_WINDOW permission was not granted earlier...
}
}
}
}
NOTE:Above code and extract is taken from following gist.
Hope this Helps!!!..
Just clear data of the Es explorer from device then after restart device.
I think these two links could help you.
firstlink
secondlink
Try to use for debug build -- targetSdkVersion 22.
After signed APK (for all targetSdkVersion(s)) application will work fine.
I am creating 'my own launcher. In that case I want to putQuick search bar` in my home screen i.e. Google now launcher.
How can I do that. I have gone through multiple threads but not found any relevant answer.
I don't want to show the widget picker.I want asap user install this launcher search bar should be there.
Thanks in advance.
I really recommend you to clone Launcher3 repository from AOSP.
https://android.googlesource.com/platform/packages/apps/Launcher3/
If you checkout nougat-mr5 branch you can look at the code to show searchbar by taking the component from GMS package and including it as a row element. Please look for QSB in the code.
The search bar is not displayed because the launcher doesn't have permissions to show the widget.
As you probably already figured out, if a user explicitly adds the search bar widget to any screen, he will be prompted to give the permission, and the search bar on top also appears.
The problem is that getOrCreateQsbBar method in Launcher class (I assume you forked Launcher3) doesn't ask for permissions if it can't instantiate the widget, it instead silently fails. The problem is in this snippet inside of getOrCreateQsbBar:
if (!AppWidgetManagerCompat.getInstance(this)
.bindAppWidgetIdIfAllowed(widgetId, searchProvider, opts)) {
mAppWidgetHost.deleteAppWidgetId(widgetId);
widgetId = -1;
}
Instead of just resetting widgetId to -1 you want to ask for permissions to install the widget and call getOrCreateQsbBar again. Here's an example code that asks for permission:
boolean hasPermission = appWidgetManager.bindAppWidgetIdIfAllowed(widgetId, searchProvider);
if (!hasPermission)
{
mAppWidgetHost.deleteAppWidgetId(widgetId);
widgetId = -1;
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, searchProvider);
startActivityForResult(intent, REQUEST_BIND);
}
Then overload onActivityResult in the Launcher class, something along the lines of:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_BIND) {
mSearchDropTargetBar.setQsbSearchBar(getOrCreateQsbBar());
}
}
There is an example of how to use Drive API https://developers.google.com/drive/quickstart-android. It works well, but I have some trouble while trying to implement uploading file to GDrive from background service.
In all examples which I found, in case when we receive UserRecoverableAuthException we need to start new Activity using Intent from that Exception (UserRecoverableAuthException#getIntent()) to take user to the OAuth2 permission page.
When we do this from Activity, we just use startActivityForResult, and as result we can use onActivityResult to know that the user finished his interaction and we can retry.
But in case, if I want to work with Drive API from Service, and there is user interaction needed, all I can do is provide Notification to user with PendingIntent. And there is no any callback for me to know when user closes OAuth2 permission page.
Can you please suggest any approach to this? Maybe I miss something? Maybe there is some broadcast I have to catch or etc?
Thank you.
Start an activity from the notification where you'll be handling the activity result of the permission activity. Handle the result and and optionally finish the activity.
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
if (resultCode == Activity.RESULT_OK) {
// permission is given
finish();
} else {
or show error
}
}