Disable touch outside of the Bluetooth system Alert - Android - android

I am new in android development.
I have a BluetoothAdapter, if bluetooth not enabled automatically asks the window for allow/deny. It is woking fine but, when tap on outside of the alert will dismiss the alert. How can I disable the dismissal of the alert when tap out side of the alert window.
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, BluetoothState.REQUEST_ENABLE_BT);

What you have is an Activity, so you should call setFinishOnTouchOutside(false) from your activity if you want to keep your dialog open when the background activity is clicked.

Related

Android - close InputMethodPicker programmatically

I want to show Android's InputMethodPicker for a fixed time and if the user does't interact with it, close it.
After opening with InputMethodManager's showInputMethodPicker method I was wondered how to close it programmatically.
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showInputMethodPicker
I have tried simulating backPress but it closes the calling activity instead.
Thanks.
This is my solution that works perfectly
Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
sendBroadcast(intent);
this can used for various system dialog

AlertDialog after tapping on Android notification

When a notification appears in the Android notification bar, the action for tapping on it is defined by the PendingIntent that was used while creating it, right?
But instead of launching an activity when the user taps on the notification, I would rather like to show an AlertDialog only. Is this possible?
The AlertDialog should ask: "Close notification" or "Show again in 1h" and so on.
Is there a way to show this AlertDialog only or do I have to launch an Activity, anyway?
You have to make an activity that does not set a contentView and just pops the Dialogue.
And remember to finish(); the activity when the dialogue is dimissed.

Closing intent selection dialog (after user selection)

I use an Navigation intent in my app like:
uri= String.format(Locale.ENGLISH,"http://maps.google.com/maps?daddr=%f,%f",latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
EventMapOfflineActivity.this.startActivity(intent);
Works perfectly, the user can select the app (s)he wants to start.
But, after the selection the dialog won't close itself and after returning to the app sometimes the user has to press the back button up to 4x to close that dialog.
So is there any way to get the Android OS to close that dialog?
Or do we have to respect that Android way of doing it?
I would do that in the onStop() Handler of my app which is called when the user selected an app to start in the dialog (with a flag set to true on the click to go to navi and resettet to false in the onStop() )
I just think that the Android OS would not like messing with its dialogs, or is there a CLEAN way to do this?
Thanks in advance
But, after the selection the dialog won't close itself and after returning to the app sometimes the user has to press the back button up to 4x to close that dialog.
This is most likely a problem with your firmware, either due to bugs from the device manufacturer or bugs in some modded firmware that you have installed upon your device.
So is there any way to get the Android OS to close that dialog?
Android automatically closes the dialog.

Android Services, Activities and Handlers?

Im developping an Android Service in Android that needs to pop-up a new dialog box for confirmation.
I can popup a new activity using Intent and Context
Intent myIntent = new Intent(context, ConfirmationActivity.class);
But then I need to handle the option selected in the dialog box (OK or Cancel).
Any suggestion?
Note: Not developing for smartphones.
Update: I need to return the result to the place I call the Dialog.
A service should not pop up anything at all. Imagine the user is in the middle of a phone call when your dialog pops up.
If you need a confirmation from the user the best thing you can do is to use the NotificationManager and use a PendingIntent to launch an Activity. The Activity can still have a dialog style if you like.
Control flows back from the Activity to your Service then, so when the user presses ok or cancel you would either call a bound interface or use SharedPreferences to tell the service about the user's choice.

how to schedule a task, pop up an alert and go to phone home screen?

I want to schedule a task, rise an alert box to notify the user then "quit" my application and automatically go to the phone home screen. But I dont know how to do that. I tried following code but it's not working. May someone help me? Thanks.
timer.schedule(task, calendar.getTime());
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
f.alert(context, title, msg + "Task scheduled for: " calendar.getTime());
The alert method is one I wrote from alertDialog and it's working fine. But no alert is shown when I execute the code. Maybe I'm using the wrong context?
[EDIT]
There is the whole story. I've two scenarios. I allow the user to run the task now or later. If he choose "Now", he get a screen with the progress bar telling him to wait until task is done. Else if he choose "Later" I want to schedule the task with Timer, show an alert or a toast, then go to the home screen. The task waiting background to be executed. So, to skip the progress bar (waiting for right time to run the task), I want to "quit" the application then go to the phone home screen.
You have to show the alert before you start the home activity -- your activity is paused immediately when you call startActivity. You probably want to use a Toast and not an AlertDialog there since you almost certainly don't need any user input at this point; if you are dead set on using an AlertDialog you'll have to either hold off switching to the home activity until they click "OK" on it, or start a new activity with a transparent theme to house the dialog appearing over the home screen.

Categories

Resources