java 使用android意图将文本与图像共享到instagram
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32640765/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sharing text with image to instagram using android intent
提问by ammcom
I know that this question has been asked several times before, I am trying to add caption to image shared to instagram using send intent
我知道之前已经多次问过这个问题,我正在尝试使用发送意图为共享到 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;
Has someone ever managed to make it work?
有没有人设法让它工作?
Is it not supported or has the support been revoked?
是不支持还是已经取消支持?
回答by Paul Lammertsma
There was an official statement from Instagram (mid-2015)announcing that pre-populated captions would no longer be accepted in the iOS and Android apps:
Instagram(2015 年年中)发表了一份官方声明,宣布 iOS 和 Android 应用程序将不再接受预先填充的字幕:
Beginning today, the iOS Hooks and Android Intents will stop accepting captions passed by third party apps. This is a non-breaking change: existing mobile apps that utilize pre-filled captions will continue to be able to use this flow to share media through the Instagram apps, but now Instagram will ignore the caption text. To create a caption for a photo or video shared by a third party app, users will have to enter a caption manually, the same way they already do when sharing content using the Instagram native apps.
从今天开始,iOS Hooks 和 Android Intents 将停止接受第三方应用程序传递的字幕。这是一个不间断的变化:使用预填充字幕的现有移动应用程序将继续能够使用此流程通过 Instagram 应用程序共享媒体,但现在 Instagram 将忽略字幕文本。要为第三方应用分享的照片或视频创建标题,用户必须手动输入标题,就像他们在使用 Instagram 原生应用分享内容时所做的一样。
Looking at the Instagram documentation for Android, indeed we see that there's no mention of providing the conventional Intent.EXTRA_TEXT
string extra in the intent as is customary for other apps. Their sample is limited to only providing a Uri:
查看适用于 Android 的 Instagram 文档,我们确实看到没有提到Intent.EXTRA_TEXT
像其他应用程序那样在意图中提供额外的常规字符串。他们的样本仅限于提供一个 Uri:
// Add the URI to the Intent.
share.putExtra(Intent.EXTRA_STREAM, uri);
// Broadcast the Intent.
startActivity(Intent.createChooser(share, "Share to"));
I'm sorry to say that it simply isn't possible, and we're at the discretion of Facebook in making this decision.
很抱歉,这根本不可能,我们由 Facebook 自行决定做出此决定。
回答by Ricardo Schaffer
Until it`s not solved by Instagram, I copy the text to the clipboard and instruct the user to paste it
在 Instagram 没有解决之前,我将文本复制到剪贴板并指示用户粘贴
回答by patel jigar
@Override
public void onSingleImageSelected(Uri uri, String tag) {
fileProfileImage = uri.getPath();
compressProfileImage();
imgShareTosocial.setVisibility(View.VISIBLE);
Glide.with(getApplicationContext()).load(uri).into(imgShareTosocial);
}
@SuppressLint("CheckResult")
private void compressProfileImage() {
File file = new File(fileProfileImage);
new Compressor(this)
.compressToFileAsFlowable(file)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<File>() {
@Override
public void accept(File file) throws Exception {
compressProfileImage = file;
String imagePath = compressProfileImage.getAbsolutePath();
tvSelectMedia.setText(imagePath);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});
}
private void shareToInstagram() {
path = tvSelectMedia.getText().toString().trim();
Intent intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
if (intent != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.instagram.android");
try {
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(MediaStore.Images.Media.insertImage(getContentResolver(), path, "Step Up", "Step Up")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
shareIntent.setType("image/jpeg");
startActivity(shareIntent);
} else {
// bring user to the market to download the app.
// or let them choose an app?
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" + "com.instagram.android"));
startActivity(intent);
}
}
回答by Martín Huergo
I'm with the same problem. I think is not possible at this time.
我有同样的问题。我认为目前是不可能的。
In https://instagram.com/developer/mobile-sharing/android-intents/only talk about Intent.EXTRA_STREAM, so i suppose that it's the only available.
在https://instagram.com/developer/mobile-sharing/android-intents/ 中只谈论 Intent.EXTRA_STREAM,所以我想它是唯一可用的。
Here is my code:
这是我的代码:
Intent instagramIntent = new Intent(Intent.ACTION_SEND);
instagramIntent.setType("image/*");
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
instagramIntent.putExtra(Intent.EXTRA_STREAM, uri);
instagramIntent.setPackage("com.instagram.android");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(instagramIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for(ResolveInfo resolveInfo: resolvedInfoList){
if(resolveInfo.activityInfo.packageName.startsWith("com.instagram.android")){
instagramIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name );
resolved = true;
break;
}
}
if(resolved){
startActivity(instagramIntent);
}else{
Toast.makeText(PromocionarMain.this, "Instagram App is not installed", Toast.LENGTH_LONG).show();
}
回答by siliconeagle
Instagram have stopped accepting pre-populated capitions to increase the quality of content in the system. See this post.
Instagram 已停止接受预先填充的字幕以提高系统中的内容质量。看到这个帖子。
http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing
http://developers.instagram.com/post/125972775561/removing-pre-filled-captions-from-mobile-sharing