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
Related
I have an app that can send a normal intent by calling startActivity with:
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("audio/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, Uri.fromFile(filepath));
startActivity(sharingIntent);
But i want my app on whatsapp attach menu (Audio Item specifically) like this related discussion example: Returning an Image to whatsapp
So, i used the code below, my app is showed on menu but when i do the share steps i get whatsapp "Share failed, please try again" error message. Others similar apps do the steps with the final step showing the Whatsapp Recorder dialog to apply sound on chat.
On this second feature (whatsapp internal intent-filter sharing) i use the same intent but with this:
setResult(RESULT_OK, buildSoundShareIntent(soundId));
finish();
instead of startActivity
Is there something specific and hidden that i dont find?
The solution is below my noose all the time, its simple: call the Intent constructor with action and data (Uri.fromFile(File)):
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND, Uri.fromFile(file));
setResult(sharingIntent);
In camera Settings; set storage to "Ext. SD card". Also, move any older photos you want to share to Ext. SD card. This worked perfectly with me. Hope it will work for you.
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);
I have been taking a look over stackoverflow but I did't find a definition about what is "createChooser" and why I can use and in whick kind of situations is good to use it.
Thanks in advance.
For example: you have a share picture option in your application.
You define an intent like this:
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
File downloadedPic = new File(
Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS),
"q.jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
Than when you call:
startActivity(picMessageIntent);
all applications on your phone capable of getting this picture will be listed.
If you want to custimize the title of that list, you can use createChooser like this:
startActivity(Intent.createChooser(picMessageIntent, "Send your picture using:"));
When startActivity(intent) is called for the first time from your app the user sees a list of all apps capable to handle this intent.
There is also an option to always handle this intent using one of the apps from the list. If this option is used then the list will never be shown again.
If you use createChooser in your intent then the "always use this app" option is not shown. The user always sees this list.
This method is used when you want to create a Custom Action using an Intent... Just like what android provides ACTION_VIEW etc... but here when there are multiple choices to perform an an Action this chooser will bring up a dialog which will have all available options and let the user select one... here is an example
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.
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);