发送Instagram直接消息的意图

4
我希望我的安卓应用程序中的用户能够直接向我的Instagram帐户发送私信。 在Instagram上发送私信的意图是什么? 谢谢。
2个回答

0
您可以使用以下代码。
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"));
}

请参阅官方文档

同时也请参阅thisthis


0

要在Instagram直接消息中分享纯文本,请使用以下方法:

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]);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接