【发布时间】:2016-07-22 06:26:02
【问题描述】:
我希望人们能够从我的 Android 应用程序向我的 Instagram 帐户发送直接消息。 在 Instagram 上发送直接消息的目的是什么?
谢谢
【问题讨论】:
标签: java android android-intent instagram
我希望人们能够从我的 Android 应用程序向我的 Instagram 帐户发送直接消息。 在 Instagram 上发送直接消息的目的是什么?
谢谢
【问题讨论】:
标签: java android android-intent instagram
你可以使用下面的代码
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);
share.putExtra(Intent.EXTRA_STREAM, [URI of photo]);
share.putExtra(Intent.EXTRA_TEXT, [Text of caption]);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
}
【讨论】:
要将纯文本分享给 Instagram DM(直接),请使用以下内容:
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Assd") // set uri
shareIntent.setPackage("com.instagram.android")
startActivity(shareIntent)
或者您也可以使用文件代替:
String type = "video/*";
...
intent..putExtra(Intent.EXTRA_STREAM, [URI of photo]);
【讨论】: