【发布时间】:2015-09-29 04:35:13
【问题描述】:
我需要分享文字到 instagram 但我不能使用 android
intent.putExtra(Intent.EXTRA_TEXT,"MY TEXT");
什么都没有发生。请帮我做这件事
【问题讨论】:
-
instagram 的发布意图代码
标签: android android-intent share instagram
我需要分享文字到 instagram 但我不能使用 android
intent.putExtra(Intent.EXTRA_TEXT,"MY TEXT");
什么都没有发生。请帮我做这件事
【问题讨论】:
标签: android android-intent share instagram
Instagram 已停止接受预先填充的字幕,以提高系统中内容的质量。请参阅此帖子。
http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
【讨论】:
用于与任何社交应用共享文本的通用代码:
第一步:获取你要分享的应用的包名:
要获取包名,请在 Windows 中使用 adb logcat -s ActivityManager 此命令并运行应用程序,例如您想要 instagram 的包名,因此运行上述命令并打开 instagram 应用程序,您将在日志中获取包名
注意:上面列出的 adb 命令是针对 windows 的。
对于ubntu,您可以使用adb logcat | grep "ActivityManager"
第 2 步:一旦你得到应用程序的包名,下面就是用于共享文本的通用代码。
try {
Intent shareOnAppIntent = new Intent();
shareOnAppIntent .setAction(Intent.ACTION_SEND);
shareOnAppIntent .putExtra(Intent.EXTRA_TEXT, getResources().getString(R.string.share_body));
shareOnAppIntent .setType("text/plain");
shareOnAppIntent .setPackage(PACKAGE_NAME_OF_APP);
startActivity(shareOnAppIntent );
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ShareAppActivity.this, "APP is not installed", Toast.LENGTH_LONG).show();
}
【讨论】:
很遗憾,Instagram 没有收到来自意图的文本。它只接收EXTRA_STREAM 对象。您只能分享 jpeg、gif、png 格式的图像。由于他们不提供任何您无法以任何其他方式共享的 SDK。
查看 Instagram 开发人员文档 here,他们明确提到接受 Intent 参数为 EXTRA_STREAM
这是在 Instagram 中分享照片的代码
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"));
}
【讨论】:
这是在 Instagram 中分享图像和文本的意图代码。
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_STREAM,uri);
shareIntent.putExtra(Intent.EXTRA_TEXT,"YOUR TEXT TO SHARE IN INSTAGRAM");
shareIntent.setPackage("com.instagram.android");
return shareIntent;
【讨论】: