Dismissing Android's system dialogue which was triggered by my app - android

The scenario is as follows:
First, my app executes the example code for requesting user's approval to make the device Bluetooth-discoverable. This request opens up some kind of a system dialog, which asks the user "An app wants to make your phone visible to other Bluetooth devices for X seconds" and the user has to either accept or reject the request.
While that dialog is still showing (meaning that the user didn't interact with it yet), and in the meantime something else has happened in my app, then I want to be able to dismiss the dialog or cancel that request, on behalf of the user. Like "forget it, that's not relevant any more".
Is that possible in any way?

Related

Package installer dialog dismissible?

I am working so some demo app store. This app can detect deep link and install app from link. Before installing app user gets dialog (at least on Android 11 and 12) where he/she can click on Install or Cancel. Dialog is opened by PackageInstaller. I am using BroadcastReceiver to receive installation status (for example PackageInstaller.STATUS_PENDING_USER_ACTION). When user clicks on cancel or install or some error happens I receive a status.
But user can click outside of dialog. Dialog is smilingly dismissed and no status is reported back.
Is there way to get status? Or to make dialog non dismissible?
EDIT: dialog is create by PackageInstaller and I don’t have control it's properties.
Directly - no, but you can:
Track onResume event to detect when it's closed (it requires some filtering to avoid false detection);
Wrap it into some proxy activity and use startActivityForResult/onActivityResult to start that EXTRA_INTENT from STATUS_PENDING_USER_ACTION. resultCode is always 0, but you'll have an closing event at least.

How to dismiss permissions dialog programmatically?

When the user pauses/closes the screen, while a permissions prompt dialog is active, the dialog persists over the locked screen when the user tries to use the phone again (and needs to make a choice for the dialog to go away).
Although a detail, it does not look very nice, and I would like to dismiss that prompt dialog in onPause(). How can I do that? Perhaps I should programmatically choose to deny permissions in onPause() instead?
From another point of view, it is also not very nice that user can't continue his task when returning to your app.
So, persistent dialog is a feature and the point is that user decides when to deny or accept permissions - it's the best to not do anything programmatically

Responding to a phone book access request programmatically

I am working on a test application that is going to be used for automated bluetooth device testing. My application basically connects a phone to a Bluetooth device so that the device can be tested with an Android device, the nature of the testing isn't relevant to this question really.
My issue is, one of the Bluetooth devices I am working with has voice prompts that will speak the name of your phone contact when getting an incoming call from them. In order to do this the Bluetooth device needs access to the Android's phone book. So the first time the device connects, I get a dialog message that pops up with a Phone book access request, saying the device is requesting access to contacts and call history. I am trying to find a way to respond to this request inside of the test application, the idea of this application is that it is supposed to be automated, so I don't want to have to have somebody come by the phone and click yes to this request, but I definitely need to respond yes or else the voice prompts won't work properly.
I am able to find when the request pops up using the onWindowFocusChanged function, and I confirmed using the debugger that this function is called when the request pops up. At first I thought maybe I could dismiss it with ACTION_CLOSE_SYSTEM_DIALOGS, but as it turns out this won't work, and even if it did dismiss the dialog (and it doesn't dismiss it), according to the documentation this Intent only requests that a dialog is dismissed and ultimately the dialog will decide how it wants to handle that.
//This function will be called when the dialog is shown.
#Override
public void onWindowFocusChanged(boolean isTrue) {
super.onWindowFocusChanged(isTrue);
if (!isTrue) {
Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
this.sendBroadcast(closeDialog);
}
}
Dismissing it isn't really what I wanted to accomplish anyways because I want to be able to chose the yes option so my device gets access to the contacts properly. My other idea, which is sort of a hack would be to just figure out where on the screen the notification is located and inject a touch event at the location of the yes option. This is not really how I want to do it because I would have to basically figure out the location with trial and error because I don't believe I can get access to the dialog from inside an app to figure out it's exact location. Also it would constrain me to only being able to use whatever specific devices I took the time to find the coordinates of the yes button.
Any ideas?

Android App - navigating to phone settings and returning

My first question, (but long time lurker on StackOverflow) so please don't be too scathing.
I am creating an Android App that has the capability of using a web service to update an SQLite database. Of course, this can only happen if the phone has internet connectivity. I understand how to navigate to the phone settings from the App, but I would like to know if the phone is now connected to the internet upon the user returning to the App.
I have considered using the onStart() and onResume() methods, but is there any way to determine where the user 'came from'. A good example would be the Google Maps/Navigation App. If the user is in Google Maps and presses the Navigation icon, it opens the Navigation App/activity and if GPS is not on, a dialog box shows asking the user if he or she wants to be taken to the GPS settings. They can choose OK, turn on GPS and press the back button to return to the Navigation App. If GPS is now on, they can proceed, otherwise the App shows the dialog box again.
This is good, except the user is allowed to continue, in my case, if there is no internet connectivity. But if there is initially no connectivity, and the user goes away and turns it on, and comes back, then I want to call the method to call the service.
I only want the internet check to happen on opening the App, and upon returning from the phone settings. If I use the onStart() method, the check will happen every time the user opens the activity.
So my question is, how do I check that there is internet connectivity only in the onCreate() method AND when the user returns from the phone settings?
Thanks in advance.

Want to add a startup notification Droid app

I am looking to add a Notification when the app is started. That will ask the user if they have a WiFi or unlimited connection. If they pick yes then they can go into the app, if no then the app closes with a message 'Try again later...'
To find out if wifi is available, you don't need to ask the user, you can ask the OS to give you that information using this method:
http://developer.android.com/reference/android/net/NetworkInfo.html#getTypeName%28%29
If you wish, you can also check if there is a connection using isConnected() and if you want to test if the connection is working, you could make a network call to confirm.
If you want to have the user confirm (I don't think you need to) then create an activity that runs when the app starts, it asks them to confirm, and then depending on their selection either starts the app's main activity, or shows a message and exits.
I don't know the details of your app, but if it were me I would probably:
- Automate the network detection
- If there's no network, run the app as usual, but just grey out and disable the main UI, and show a message like "Please connect to a Wifi network".
- Consider including a user interface within the app that the user can use to turn on wifi.
I think that's much tidier than just exiting the app, as that means if they get the "no wifi" warning the app assists them by providing an option to enable it.

Categories

Resources