Android- write system settings UI alternative - java

My Android app currently enables WRITE_SETTINGS in its Manifest. When the app makes an intent Settings.ACTION_MANAGE_WRITE_SETTINGS, it shows a system dialog enabling the user to set the permission for the app to modify system settings. I would like to change this dialog however because I do not like the layout of the system generated screen. In addition, I would like to enable battery optimization on the app as well, and that has its own separate system dialog. The system dialog takes up the whole screen and can be confusing for the user to use, especially when there are two screens displayed in succession.
I would like to use my own XML layout or a popup for the dialog and letting the user enable/disable these permissions as needed. Is there a way to do that and not have the app launch the system dialog?

You can't change the system dialog for settings, media projection, runtime permissions... It's a system dialog, it can't be changed to prevent abuse.
The best you can do is explain to the user what's expected of them before you start showing these system dialogs.
The system dialog [...] can be confusing for the user to use, especially when there are two screens displayed in succession.
Explain what needs to happen before each step.
Explain what you need from the user in your app, in your visual style, then show one system dialog.
After user confirms it explain the next thing in your app, then show another system dialog.
Avast Anti-Theft (not affiliated) uses this approach when setting the app - it needs to enable its device admin and listen for notifications, both are controlled in system UI.

Related

Android Settings permissions not not acting as they should

I need to ask for permission from the user. One of the permissions I need is ACTION_MANAGE_OVERLAY_PERMISSION and the other is Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION. When asking for it as you can see in the code below, it takes the user to the Settings screen so the user could tick the permission from there.
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);
On some Android phones and Android versions, it takes the user straight to the specific application setting (the app that it is called from) on other devices it opens up the list of applications from which the user has to find the app and then tick the permission. In most cases on Androids lower than 10 it opens up the specific app settings window and when it's 10 or higher, it opens up the list.
Is there a way to make it consistently open the current application setting that is open?
I tried adding:
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
But that did not help either.
And secondly, is there a way to ask for this and other Settings permissions without opening the Settings menu and instead of doing it in a dialog inside the application?
If not then is there a way to ask for multiple Settings permissions one after another because my application requires two Settings type permissions.
EDIT
Here is what I meant by the specific application settings vs the list.
On the left picture, all apps are listed and on the right picture the specific app is opened (happens if you click on the app in the list).
Now in some cases, it directly opens the right picture but mostly it opens the left. Is there a way to force open the right picture at all times?
Is there a way to force open the right picture at all times?
No.
The Settings app usually is modified substantially by the device manufacturer. They can do whatever they want. This includes ignoring the Uri or outright removing third-party access to this screen, where the latter is what the documentation is warning against:
In some cases, a matching Activity may not exist, so ensure you safeguard against this.
If you make your own Android firmware, you could ensure that this Intent action behaves as you want, for whatever devices run your firmware.

Is there a way to detect when a popup window appears in Android

I started a project of a windows program that connects to an android phone and gives the user information
about it, so I want to display all of the popups that appere on the phone. to do this I need the app version of the program to catch them somehow and give me the name of the app that sent the popup and the popup's contant. is it possible?
it would be kind of security issue if any app could do that... you can try with AccessibilityService with some permissions for reading screen/running Activities and checking style of every Activity is this "popup", but note that some of them are just DialogFragments. So I doubt you can recognize "popups" this way in a reliable way. Look for AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED for more info

How to show dialog when app is in background in android app like collect app

image
I am sharing a link from another app like youtube to my app but Now it opens my app and then saves the link. My need is to not save the link without opening the app
There are two solutions:
You don't need dialog or anything like it. Just make the activity fully transparent, process data and finish it. Optionally, you can show Toast as a feedback. It would look and feel like everything is processed in the background.
You need dialog or some kind of UI. For this, you can use floating windows that you can show over other apps. Many apps use this approach such as Pocket, etc. There is complete guide on how to do it: https://localazy.com/blog/floating-windows-on-android-1-jetpack-compose-room

Dialog box for Device administration permission Android

I have a screen lock app like if you tap on it, it will turn off the screen. But it needs to be device administrator which I do manually for it. I want it to show a dialog box when you open the app which will take you to the device administrator settings. Like in the image.I want to a button in dialog which will take me here
This should solve your issue. Check it out and see if it fits.
How to open device administrators settings in android?
Generally speaking you need to find if there is an exported activity on your device that let's you call an intent to launch that settings page.

Home button brings back to my app

I am making a car launcher application, which contains shortcuts to other apps, when i'm in another app i'd like to press the home button and go back to my launcher
So basically i need to override the home button outside of my app,the override has to work only when my app is opened in the background so when i close my app the home button will work as usual taking you to your default launcher
Can i implement something like this or i'm asking too much?
There is no way to intercept the home button on Android, unless you make your app the home screen. This is for security reasons, so that malicious apps cannot take over your device by overriding all the buttons that can exit. The home button is the one sure shot way to be able to leave any app.
In short, no it's not possible, and even if it were, it is a serious disruption in what a user expects out of an app's behavior.
If you go the route of making your app act be a replacement home screen you'll have to include in the install instructions for the users to set your app as the default launcher.
Then the home button would take them to your app. In order to get it to switch back to the default launcher when they are not in "car" mode would be a bit tricky but you could prolly achieve it with some sort of fork activity that checks if car mode is enabled if so go to your car mode launcher if not go to the default launcher (it gets trickier if the user already has a different 3rd party launcher) So essentially your app will always be the home screen app no matter if car mode is enabled or not, but if it is not then you manually start the "normal" home screen.

Categories