I have buttons in my app that launch Android Chooser intents (ACTION_VIEW, etc.) And i was wondering how to use an Espresso idling resource. to wait and detect display of the dialog and how to cancel it and return after.
I am not asking for code per se .. just wondering how to do it?
e.g.
onView(withId(R.id.ad_email_button)).perform(click());
this button opens the intent
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
So how to cancel the dialog so the test doesn't hang and verify the appropriate system dialog was shown?
As far as I know using Espresso we are limited to actions and verifications inside specific Activity. But I found out that we can access UiAutomator as well and perform BACK action to dismiss alert dialog:
InstrumentationRegistry.getInstrumentation().getUiAutomation()
.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
Looks like the answer is to use UIAutomator for these tests:
https://developer.android.com/tools/testing-support-library/index.html#features
Related
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
I saw 2 questions about this here in stackoverflow but none of them was clear enough and with good code example.
i would be greatful if someone will explain me how i can acheive my goal and supply a good code sample.
my issue if wasn't understood from the title, is that i am handling the android.intent.action.SENDTO intent but also starts and activity with that intent and i don't want to see my application when i am already in my application clicking on a button for instance.
I have heard about queryIntentActivities and successfuly filtered my application from the list by its packageName but i don't know how to fire the "Complete action using" dialog with the new modified List.
I prefer to use the default "Complete action using" with the option to "make this application the default application for this action" but if creating a custom dialog is the only option, it would be excalent if you also will explain how to enable this option in the custom dialog.
thanks
but i don't know how to fire the "Complete action using" dialog with the new modified List.
You would have to create your own dialog (or dialog-themed activity) for this. The standard Android chooser dialog has no such filtering option.
if creating a custom dialog is the only option, it would be excalent if you also will explain how to enable this option in the custom dialog.
You can't. Only the operating system can make an application be the default for this action.
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.
My boss asked me to prove that my application behaves properly when summoned by another application (dunno why he asked that).
So I have two apps here, one launches a second one. How I launch the specific app I want? Using Intent launch seemly any generic app that reaches a certain goal, not the app I really want.
Give this a try.
Intent secondIntent = new Intent();
secondIntent.setAction(Intent.ACTION_MAIN);
secondIntent.setClassName("com.example", "com.example.YourSecondApp");
startActivity(secondIntent);
I should point out that com.example should be the package of your second application (the one you want to call) and com.example.YourSecondapp is the class name where you have your onCreate() method.
Intent secondApp = new Intent("com.test.SecondApp");
startActivity(secondApp);
Check out for more examples
http://developer.android.com/resources/faq/commontasks.html#opennewscreen
Create one Intent using the following code
Explicit Intent
When you know the particular component(activity/service) to be loaded
Intent intent = new Intent();
intent.setClass("className/package name");
start<Activity/Service>(intent);
Imlicit Intent
When we do not have the idea which class to load and we know the Action to be perform by the launched application we can go with this intent.
Action needs to set, and the Android run time fallows the intent Resolution technique and list out(one or more components) the components to perform the action. from the list out components (if more than one), user will get the chance to launch his chosen application
I was wondering if anyone can tell if how to pop a dialog screen up over a native Android screen?
I currently have an application that traps an outgoing call and stops it, I then want to pop up a dialog that would take over from the dialler screen and alert the user that there attempt to call has been blocked and allow them have some new options from the dialog.
I know that some people will say that I should use notifications instead but I'm aware of that and its not the way that it should work, I need to be able to pop up a dialog when the call gets trapped.
This is my dialog code so far
AlertDialog LDialog = new AlertDialog.Builder(context)
.setTitle("Call Blocked")
.setMessage("Call Blocked, reroute call?")
.setPositiveButton("ok", null).create();
LDialog.show();
I presume I have to somehow get the context to be that of the dialler screen?
Can anyone offer any help and assistance or links to tutorials?
Thanks in advance
For my application I used an activity with the Dialog theme.
You can declare the theme in the manifest file :
<activity android:name="PopupActivity"
android:launchMode="singleInstance" android:excludeFromRecents="true"
android:taskAffinity="" android:theme="#android:style/Theme.Dialog" />
use launcheMode="singleInstance" and taskAffinity="" if your popup is detached from your main application. Otherwise user may click the back button and return to the previous activity of your application.
excludeFromRecents="true" to avoid your popup to appear in recent tasks (long press home)
theme="#android:style/Theme.Dialog" to set the Dialog theme.
How to get the equivalent of launchMode = singleTask in code
I have not seen a clear explanation of how to set these flags programmatically, so I will include my results here. tldr: you have to set FLAG_ACTIVITY_NEW_TASK and FLAG_ACTIVITY_MULTIPLE_TASK.
If you launch this directly from your app, your dialog will appear on top of your app's last Activity. But if you use a PendingIntent broadcast by AlarmManager to launch your "dialog", you have time to switch to a different app so you can see that your "dialog" will appear over that other app, if the style is set appropriately to show what is behind it.
Obviously one should be responsible about when it is appropriate to display a dialog on top of other apps.
public class MyReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// you have to set these flags here where you receive the broadcast
// NOT in the code where you created your pendingIntent
Intent scheduledIntent = new Intent(context, AlertAlarmActivity.class);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
scheduledIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
context.startActivity(scheduledIntent);