I am trying to pass a url to a specific app using the ACTION_SEND intent, I want to by pass the chooser and just go straight to the app i desire but it doesn't seem to take the url unless i use the chooser..
private void shareIt(){
Intent pC = new Intent(Intent.ACTION_SEND);
pC.setType("text/plain");
pC.putExtra(Intent.EXTRA_TEXT, "http://www.bob.com");
pC.setType("text/plain");
pC.setClassName("com.sec.print.mobileprint","com.sec.print.mobileprint.UI.WebPrint");
//startActivity(pC);
startActivity(Intent.createChooser(pC,"Share jon"));
}
if i comment out the last line and comment back in the line before it.. it opens the app i want bypassing the chooser, but the app opens to google instead of bob.com.. if i leave it as is.. it brings up the chooser and should i choose the app it goes to bob.com .. how can i get it to go to bob.com while bypassing the chooser?
I suspect that the Intent.setClassName method you’re calling takes an unqualified class name as its second argument (after all, why bother repeating the package name qualification?). Alternatively, you can use setClass instead.
Are you sure you need to pass the URL via EXTRA_TEXT and not by pC.setData(Uri.parse("http://www.bob.com");?
Related
After setting up an app for deep linking. by creating an activity to launch when the link is opened in the browser. How do I go about getting the link that the browser used to start the intent?
Let us say the app catches the URL: "https://example.com/foo/bar?param=1&data=extra".
In the Activity launched I want to use the URL which opened the app. I am thinking maybe something like int the activity perform
Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
I dont know the variable to access the lauch URL from Uri data
It turns out I was on the right track all I do is
data.getQuery();
To get the last part of "https://example.com/foo/bar?param=1&data=extra" ie "param=1&data=extra"
Otherwise, call another function of data like.function() to get other aspects of the URI eg the whole URL that led to the opening of the activity
Stackoverflow makes you think half the time I always find the answer Immediately after I post a question.
I have searched a lot on this.
But, I have my code working to open my app using a custom intent URL. This URL is usually delivered via email.
When I click on the link, it opens my app fine and everything seems to be working; however, it opens in the context of the email application.
For example, if I click on the link from Gmail, when I open multitasking, I have to click on Gmail to return back to the app that just opened.
I would think it should open my app and I can continue using Gmail while my other app is running.
Any thoughts on this?
Make your URL look like this:
intent:#Intent;launchFlags=0x10000000;component=com.mycompany.myapp/com.mycompany.myapp.MyActivity;end
This URL contains the launchFlag for Intent.FLAG_ACTIVIY_NEW_TASK, so this will launch your app in a separate task (outside of the email client or browser or whatever).
EDIT: Add additional details based on OP's comment
You say that you are using a URL like this: http://com.my.app/5058749
In that case you must have used an Intent filter to get Android to open your app by specifying an <intent-filter> on a certain <activity> in your manifest. There are several things you can do to deal with the problem of the launched Activity ending up in the same task as the Activity that launched it:
1) If the Activity is always intended to be the root (starting, first) Activity of a task, you can put the following code in onCreate() after the call to super.onCreate():
if (!isTaskRoot()) {
// Activity was launched into another task. Restart it in its own task
Intent intent = new Intent(this, this.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return;
}
2) You can set the launch mode of this Activity to singleTask in the manifest by adding
android:launchMode="singleTask"
to the <activity> definition. This will cause the Activity to be launched in its own task but this launch mode has other consequences that are more subtle and so you need to be careful about using it. In general I don't like to suggest this because it tends to create more problems than it solves.
3) You can determine if your app was launched from the browser or email client by examining the Intent used to start it in onCreate() (The Intent will have the data set to the URL when launched via the browser or email client). You can then decide if you want to restart it in its own task by using the code I've supplied in option 1 above.
Add Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_CLEAR_TOP flags(intent.SetFlags() to your intent. Your actitivty will be opened in a new task and this activity will be the root of your new stack.
This is the default behavior with android, but to override it, you need to pass
Intent.FLAG_ACTIVITY_NEW_TASK
Intent.FLAG_ACTIVITY_CLEAR_TOP
with your intent.
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
Is it possible to receive an explicit intent with the component option set?
Example:
Starting activity: Intent { action=android.intent.action.VIEW data=http://example.org flags=0x10000000 comp={com.android.browser/com.android.browser.BrowserActivity} }
The reason why i want to this this is because i want receive this intent above, launch another browser than the default one, and drop the intent before it starts the default browser. In another words, i want to make another browser the default one.
If this is impossible, any other ideas how i can accomplish this?
Thanks!
1) You can explicitly launch alternative browser by calling something like startActivity(new Intent(this, OtherBrowser.class)) from Activity.
2) You can't override the default browser, but you can provide a browser alternative that user could choose when opening http://something. Just have a look at intent-filters that the default Browser declares (from Android sources).
I would like to launch an app the user selects from within my application. However, I'm not sure how I'd go about doing this. I've tried this:
Intent intent = new Intent();
intent.setAction(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
startActivity(intent);
But this seems to throw an error and force close my application. I also tried adding:
<action android:name="Contacts.Intents.SHOW_OR_CREATE_CONTACT"/>
in the AndroidManifest file, but to no avail.
A look at Logcat shows that it's an "IOexception - no such file or directory". A couple of questions arise from this. I read through the Android docs and noticed that the Contact.Intents class is deprecated. However, it's successor, ContactContracts is aimed at API level 5 whereas I'm targeting API level 3. Could this be the problem? Also, I've hardcoded this application into the code. Is there a way to retrieve the intents of any application the user selects so that they can be launched?
You need to pass extra information into the intent to tell Android what you want to show or create. Otherwise Android doesn't know what activity to start and (presumably in your case) throws an ActivityNotFoundException.
For a contact, you use the generic Intent.ACTION_INSERT_OR_EDIT then use the MIME type of an individual contact (Contacts.People.CONTENT_ITEM_TYPE).
For example:
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(People.CONTENT_ITEM_TYPE);
intent.putExtra(Contacts.Intents.Insert.PHONE, "+1234567890");
intent.putExtra(Contacts.Intents.Insert.PHONE_TYPE, Contacts.PhonesColumns.TYPE_MOBILE);
That will bring up the contacts app, prompting you to select an existing contact to add the phone number to, or to create a new contact.
You don't need to add anything special to your manifest to start external activities. Only if you were to directly manipulate the contacts ContentProvider would you need to add the appropriate CONTACT permissions to your manifest.
I use this code for that purpose:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.Settings");
startActivity(intent);
This will launch the Settings app, you can use these also:
intent.setClassName("com.android.music", "com.android.music.MediaPlaybackActivityStarter");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsContactsEntryActivity");
intent.setClassName("com.android.contacts", "com.android.contacts.DialtactsActivity");
The first starts the default music app, the second the contacts, and the third the dialer.
Hope this helps.
You need to pass in valid arguments to the apps you start. A lot of apps expect the data URI and / or certain extras to be valid.
Please try the following code:
Intent intent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT);
this.startActivity(intent);
(sorry if there is something wrong on the syntax, I dont have android in this computer)
And remove the action from the manifest. that is not needed.
The action method is used for something else.
For more info, please look at the android site: http://developer.android.com/reference/android/content/Intent.html
Daniel
The activity you are calling should appear not only in the Manifest for its own package, but in the Manifest for the CALLING package, too.