Android Intents
Android Intents
If your application creates photos or videos and you would like your users to share them using Instagram, you can use Android Intents to open your media in Instagram's sharing flow.The examples below create an Implicit Intent which will then prompt the user to select the application they wish to send the media to. When triggered, Instagram will immediately present the user with the crop screen.
| Intent Parameter | Description |
|---|---|
| Intent.EXTRA_STREAM | media path on device |
Sharing an image
| Requirement | Value |
|---|---|
| Photo Format | jpeg, gif, png |
String type = "image/*";
String filename = "/myPhoto.jpg";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
createInstagramIntent(type, mediaPath);
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
Sharing a video
| Requirement | Value |
|---|---|
| Minimum Duration | 3 seconds |
| Maximum Duration | 10 minutes |
| Video Format | mkv, mp4 |
| Minimum Dimensions | 640x640 pixels |
String type = "video/*";
String filename = "/myVideo.mp4";
String mediaPath = Environment.getExternalStorageDirectory() + filename;
createInstagramIntent(type, mediaPath);
private void createInstagramIntent(String type, String mediaPath){
// Create the new Intent using the 'Send' action.
Intent share = new Intent(Intent.ACTION_SEND);
// Set the MIME type
share.setType(type);
// Create the URI from the media
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
0 Response to "Android Intents"
Posting Komentar