Assuming I know that the Gallery has an album with a certain name X, what intent or broadcast can I make to open Album X with the Gallery app?
There are plenty of examples showing how to select a picture from the Gallery, but I don't see any describing how to accomplish the above.
Thanks.
try this
Intent intent = new Intent();
intent.setType("image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Main.this.startActivity(intent);
program will browser all application are support with image file
but user can set default program
If you prepared the Gallery which is called X, yes you can do it.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.package.Xapp");
if (launchIntent != null) {
launchIntent.setData("PHOTO ID OR ANYTHING ELSE");
startActivity(launchIntent);
}
After then you can set data in intent. And X app parses intent data and you can open it.
Otherwise, you can't this action. You only call the app, If the application does not provide API support for send data with intent.
Related
I am implementing an android app, which will synchronize images from selected folder to server (as Google Photo). I want that user will select folder by clicking on button. I can achieve this by creating my own view. But, if implicit intent can any implicit intent action by which I can show user only images folder from device?
Try,
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 100);
change EXTERNAL_CONTENT_URI constant accordingly.
I currently have a button that, when pressed, the user gets asked to choose a camera app and allows him/her to take a picture.
Firstly, I want to get rid of the choice so that when the button is pressed the user is immediately in the camera interface. This is the code I'm using right now (after having tried many solutions online), which does prompt the user to choose a camera:
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
try {
PackageManager pm = this.getPackageManager();
final ResolveInfo mInfo = pm.resolveActivity(i, 0);
Intent intent = new Intent();
intent.setComponent(new ComponentName(mInfo.activityInfo.packageName, mInfo.activityInfo.name));
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(intent);
} catch (Exception e) {
Log.i("TAG", "Unable to launch camera: " + e);
}
I have skimmed through a few articles that say it is not possible to launch the Android native/default camera without a chooser - however, I see apps like Facebook and WhatsApp that are able to do this so I'm sure it is possible.
As always I appreciate any help. Thanks in advance!
There are two ways to access the camera in Android- you can send an intent to an existing app, as you are doing here, or you can build a custom camera feature within your app. It is much easier to use existing apps, but as you have seen, the user must choose that app. Facebook and WhatsApp are probably using a custom camera feature.
http://developer.android.com/guide/topics/media/camera.html#custom-camera
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.
when i click the button i start a activity for youtube video like this:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM")));
if i use this its redirect to the intent chooser to open that video url on browser or youtube app. how to select the default app as youtube programmatically?
my output should open that video directly on youtube player. how? any idea?
Asking for a specific Activity is risky, as YouTube may change their package name which will follow with your application breaking.
Also - there is no guarantee that the YT player is installed on all Android Devices.
To circumvent, here is a code that searches for a youtube activity. If it finds it, it returns an intent to use it directly, otherwise, it keeps a "generic" intent that will result in the system intent chooser to be displayed.
/**
* #param context
* #param url To display, such as http://www.youtube.com/watch?v=t_c6K1AnxAU
* #return an Intent to start the YouTube Viewer. If it is not found, will
* return a generic video-play intent, and system will display a
* chooser to ther user.
*/
public static Intent getYouTubeIntent(Context context, String url) {
Intent videoIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
final PackageManager pm = context.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
for (int i = 0; i < activityList.size(); i++) {
ResolveInfo app = activityList.get(i);
if (app.activityInfo.name.contains("youtube")) {
videoIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
return videoIntent;
}
}
return videoIntent;
}
You are using a implicit intent, which can match more than one receiver, thus the chooser. You could try switch to an explicit intent model, if you can figure out how to target the youtube activity directly. See developer documentation on explicit vs. implicit intents.
However, it seems the reason for the intent chooser is to let each user decide for themselves which player to use. Is there a good reason you want to bypass this? What if someone has installed a different video player that they prefer?
Edit: To call an explicit intent, you need to know the name of the activity you are trying to start, and you pass additional details as extras i.e.:
Intent intent = new Intent(this, YouTubeViewerActivity.class);
intent.addExtra("URI", Uri.parse("http://www.youtube.com/watch?v=cxLG2wtE7TM"));
startActivity(intent);
However, I totally made up the fact that there is a YouTubeViewerActivity class. As I said, typically if you are asking some outside service, like the YouTube app, to perform an action you use the implicit intent model like you have, so the user has control over what application is used.
I'm interested in capturing media to use in my activity in two ways:
1) capturing immediately from the supplied app. (like Using the camera activity in Android)
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
this.startActivityForResult(camera, PICTURE_RESULT);
2) browse a picture/video/audio gallery and pick from the list.
I notice I can call up for the photo gallery
Intent intent = new Intent(Intent.ACTION_VIEW, target);
startActivity(intent);
But how about for video only? audio only? How will I get the URI from any of them?
a FEW problems, you need to do startActivityForResult..
But just take a look at this post, its already been done by lots of people.
Android ACTION_IMAGE_CAPTURE Intent