Make Intent.ACTION_VIEW accept multiple URIs - android

I want to launch some apps which accept geo coordinates (http://developer.android.com/training/sharing/send.html). The problem is that they want different URIs.
Example (pseudo code):
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.addSomeUri("http://maps.google.com/maps/?daddr="+myAddress);
intent.addSomeUri("http://someotherservice.com/?coordinates="+myLat+":"+myLng+"&address=myAddress");
EDIT:
Of course the goal is for both apps to appear in the same activity chooser.
How can I achieve it?

How can I achieve it?
Call startActivity() (or startService() or whatever) once per Uri.

Do you really want to launch every app?
If not, you have simpler way
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:30.0, 120.0"));
startActivity(intent);

Related

Taking audio uri from intent

I'm stuck, and I can't manage to find a solution to it :/
What I'm doing is an app of sounds effects with sounds preloaded and choosen by the user, so I have default buttons with default sounds and the possibility of adding (as many as you want) buttons with sounds choosen by you.
So here's my part of code of the add-button:
public void add (View v){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
startActivity(Intent.createChooser(intent, "Select music"));
}
The output should be an uri and I need to get that (I'll use it to take the path of the file choosen by the user), but I don't know how.
Oh, I understood :)
For those who are trying to find a solution to that as me:
You don't have to use startActivity() but startActivityForResult() and then use the getData() method on the intent parameter of the onActivityResult() callback.
Here's the guide:
https://developer.android.com/training/basics/intents/result.html

Start Wikipedia via Intent

I tried to start the Wikipedia App via Intent but I always get an InvocationTargetException, because the Activity can't be found. I can detect that Wikipedia is installed, but I can't start it. I know that I can also use the Intent Filter and call the Wikipedia URL, but then the user can decide between app and browser (both works different with the search param, which is not very useful) and I want to decide it for the user.
I tried it with following code:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "searchString");
intent.setType("text/plain");
intent.setPackage("org.wikipedia");
Can somebody tell me, what I am doing wrong there or is it just not possible to start the wikipedia app? :-/
Finally I come to a solution after I was looking in the wikipedia code on github (https://github.com/wikimedia/apps-android-wikipedia). The app listens only for View Intents, which means that following code works:
final Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(searchUri);
intent.setPackage("org.wikipedia");
The problem here is, that only URI's for existing articles were handled and no search operation can be used. After watching a little bit more in the code, I found a PageActivity which also listens for ACTION_SEARCH Intents. This would work, when in the AndroidManifest.xml this Intent Filter would be also available.

android, RESULT_OK forcing for Intent.ACTION_VIEW

There is an application. It allows users to watch a lot of videofiles from one web media resource. I know that it is possible to force a result for an activity like in the following example:
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
But it is in case of Activity class inheritance. Is there any possibility to force RESULT_OK (for example) in the following case:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(mp4url), "video/mp4");
startActivityForResult(intent, VIDEO_PLAYBACK_FINISHED);
where mp4url is a String variable, VIDEO_PLAYBACK_FINISHED is an int variable (a keyword for request).
As you can see there is no Activity class to work with. Everithing depends on a Video player users working with.
No, sorry that is not possible, since you are using the device's default media player.
A related question explains that embedding of media players in your app is also not possible.

How do we find the information for launching other app?

I need to allow user to draw/sketch/paint something. There are already many apps(like Skitch, I will use this as an example) that accomplish this task. So I don't want to re-invent the wheel.
In Android, theoretically, we can launch other activity by intent. This is sort of like "pipe" in Unix.
The problem is, I don't know how to get the information for launching Skitch.
To integrate Skitch in my app, I need to know the Action it supports, the returning intent (if any) when it finishes.
I installed Skitch, photoshop, and lots of other touch drawing apps in my device, but this code doesn't work :
Uri data = Uri.fromFile(file);
Intent i = new Intent(Intent.ACTION_EDIT);
i.setData(data);
i.setType("image/*");
startActivityForResult(i, ACTIVITY_DRAW);
I can launch Skitch from my app in the following way: but obviously I can't get any returned result this way(code from here).
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager manager = getPackageManager();
i = manager.getLaunchIntentForPackage("com.evernote.skitch");
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
My question: Is there a standard way to find information for launching a third party app?
Is this site the only way to share/get such information?
Or if you have any suggestions for my problem, please help me.
Thank you!
As you might already know how to call another application Activity from your app ..this way Mentioned Here.
Intent intent = new Intent(Intent.ACTION_RUN);
intent.setComponent(new ComponentName("<packet name>", "<class name>"));
List list = packageManager.queryIntentActivities(intent, packageManager.COMPONENT_ENABLED_STATE_DEFAULT);
if(list.size() > 0)
{
Log.i("Log", "Have application" + list.size());
startActivity(intent);
}
else
{
Log.i("Log", "None application");
}
All your require is Mainly Two Things to call any Activity
1) Package Name of that Activity
2) Activity Class Name
These two informations only can be available if they are opensource or made free to use .. like Zxing,Google Maps Application.
There is another way to start an application activity like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + numberField.getText())); // set the Uri
startActivity(intent);
For this way to use need to know the correct Action for the Activity you want to call and the Correct parameter to pass with.
And again,These information only can be available if they are opensource or made free to use .. like Facebook and Gmail apps to share and post messages.
So If you are searching for anything like which can tell you what you will need to pass to call any specific comercial apps in your device, you wont find it directly.
It's an old question but perhaps it could help somebody to know that Sony's AppXplore application (free) shows the package and name of the activities of every app installed on your device, so you can eventually use them to do explicit Intents.

android linkify intent

I have a ListView that uses Linkify to create a link to another activity in my app. the url looks something like content://com.myapp/activitiy/view?param=blah
this works fine every time.
however, in another view, I'm trying to call some code like this:
Intent i = new Intent("content://com.myapp/activity/view?param=blah");
i.setAction(Intent.ACTION_VIEW);
startActivity(i);
but for some reason this doesn't seem to work. It doesn't trigger my activity (and in fact it blows up if i dont include the setAction() call. How am I supposed to create the Intent such that it acts the same way that Linkify does...?
Now i realize i can setup the extras and then handle it in the activity, but that just seems like duplicated effort. So instead i'll spend the time it would have taken to do that, and post this question. SO any help much appreciated. :)
ah. just figured it out:
String uri = "content://...";
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);

Categories

Resources