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.
Related
I am a newbie on Android and I am creating a launcher. I want apps to be removed (uninstalled) so I have a list and I invoke system to uninstall it.
How can I know if the user pressed "Cancel" or "Ok" in the system dialog?
(I know the system will unisntall the app if I press "Ok" or wont if I press "Cancel", I just need to know how to get the answer to remove or not the app of my list [ArrayList]).
If you cant know it, how can I do to remove an app from a list without knowing if the user is going to uninstall it or not?
public void uninstall (int position){
Uri package1 = Uri.parse("package:"+apps_block.get(position).name.toString());
Intent uninstall = new Intent(Intent.ACTION_DELETE, package1);
startActivity(uninstall);
AppDetail toRemove = adapter_block.getItem(position);
adapter_block.remove(toRemove);
}
With this code, the app is always removed from my list even I press "Cancel".
You are removing the item from the list immediately after startActivity(). The user has not even seen the dialog yet by that point.
You could listen for the ACTION_PACKAGE_REMOVED system broadcast, confirm that it was for your requested package, and remove the package from the list at that point. By doing this from your activity via registerReceiver(), you can find out fairly quickly and have easy access to your UI code to update the list.
I have an activity which is purely transparent (user can't see when it gets open).I open this activity from background service whenever I want to open it. After doing some work, I need to close that activity (not finish()).I want to hide or minimize app. Actually, my app opens up for a second and do someWork after doing someWork, it continues to do remaining work (some uploading process) in background i.e. in onPause.I don't want user to know that something opens & closed immediately.
Currently, I am using below code-
public void minimizeApp() {
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
Now, Problem is that If user is using some other app eg, playing game or using Whatsapp, When my app get opens over previous app(Game or Whatsapp) and minimizeApp() is called then it minimises my app along with other app opened in background.
I want to minimize only my app.
You can try the following from the activity/context from where you want to minimise the app:
YourActivity.this.moveTaskToBack(true);
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
Hi in my app I have a dialog that asks if they would like to turn on my accessibility service if it is off. If they hit okay it launches an intent to open to accessibility like this
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);
This works fine however if they hit home from accessibility and then open my app again it doesn't show the dialog or anything but opens directly to accessiblity everytime. The only way to get around it is to hit back till I'm back at my home screen then reopening the app no longer opens to accessibility.
Why does it keep launching my old intent unless I back out? Why can't I hit back and then it not launch the intent again
Thanks for any help
Use flag FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
startActivityForResult(intent, 0);
However if the user launch your app from the history list, it will still show up.
I think the problem is that your activity is still waiting for a result.
If so, calling forceFinish() in your onResume() should fix the problem.
http://developer.android.com/reference/android/app/Activity.html#finishActivity%28int%29
What I am trying to do is replicate what the ToddlerLock app does. I have managed to clear the default launcher with
PackageManager localPackageManager = getPackageManager();
localPackageManager.clearPackagePreferredActivities("com.android.launcher");
and then open the launch select dialog with this
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
this.startActivity(i);
As long as the user checks the "use by default for this action" the home key now sends the user to my app, thus essentially disabling it.
I then use "clearPackagePreferredActivities("com.my_application")" when I exit my app and the user has to choose a new default home app.
My question is how can I choose the default home application (essentially checking the "use by default for this action" check box in code for the "com.android.launcher" package. That way the user does not constantly have to see that dialog box every time they open and close my app.
I think ToddlerLock does this somehow without using clearPackagePreferredActivities
because if I look at the "clear defaults" in the application manager it is not cleared and you only have to go through the set as default dialog box one time on startup and once when you exit to set it back to the normal home screen.
Thanks for your help.
I have implemented the same functionality in different way.
Let's say you have 'LockScreenAcitivity' configured as Home Screen in Manifest.
Launch LockScreenActivity by sending Home Intent.
Android will popup a dialog, to select the default Acitivity
choose your LockScreenActivity from List as default Activity
.....
.....
While closing the Activity don't clear the prefered Activities.
Disable your LockScreenActivity alone by calling PackageManager.setComponentEnabledSetting()
After you disable your LockScreenActivity, android will rollback to previous Prefered Activity (that's your old home screen ).
Next time when you launch your app,
enable your lockscreenActivity again by calling PackageManager.setComponentEnabledSetting()
Launch LockScreenActivity by sending Home Intent.