Android 分享图片到Instagram故事
使用共享intent我尝试使用下面的代码将图像上传到InstagramAndroid 分享图片到Instagram故事,android,image,android-intent,sharing,Android,Image,Android Intent,Sharing,使用共享intent我尝试使用下面的代码将图像上传到Instagram public static boolean shareBitmap(Context context, Bitmap bitmap, String textToShare, String packageNameOfApp, String intentMessage) { try { File file = new File(cont
public static boolean shareBitmap(Context context, Bitmap bitmap, String textToShare, String packageNameOfApp,
String intentMessage) {
try {
File file = new File(context.getCacheDir(), "Share.jpg");
saveBitmapAtLocation(bitmap, Bitmap.CompressFormat.JPEG, 100, file);
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".fileprovider", file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, contentUri);
String textToAppend = null;
textToAppend = context.getString(R.string.shortenUrl);
if (textToShare != null && !textToShare.isEmpty())
intent.putExtra(Intent.EXTRA_TEXT, textToShare + " " + textToAppend);
else
intent.putExtra(Intent.EXTRA_TEXT, textToAppend);
intent.setType("image/*");
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
if (packageNameOfApp != null) {
if (appInstalledOrNot((Activity) context, packageNameOfApp))
intent.setPackage(packageNameOfApp);
else
return false;
}
context.startActivity(Intent.createChooser(intent, intentMessage));
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
public静态布尔共享位图(上下文上下文、位图位图、字符串textToShare、字符串packageNameOfApp、,
字符串意图消息){
试一试{
File File=新文件(context.getCacheDir(),“Share.jpg”);
saveBitmapAtLocation(位图,bitmap.CompressFormat.JPEG,100,文件);
Uri contentUri=FileProvider.getUriForFile(context,context.getPackageName()+“.FileProvider”,file);
意图=新意图();
intent.setAction(intent.ACTION\u SEND);
intent.putExtra(intent.EXTRA_流,contentUri);
字符串textToAppend=null;
textToAppend=context.getString(R.string.shortenUrl);
if(textToShare!=null&&!textToShare.isEmpty())
intent.putExtra(intent.EXTRA_TEXT,textToShare+“”+textToAppend);
其他的
intent.putExtra(intent.EXTRA\u TEXT,textToAppend);
intent.setType(“image/*”);
List resinfo List=context.getPackageManager().queryInputActivities(intent,PackageManager.MATCH_DEFAULT_仅限);
对于(ResolveInfo ResolveInfo:ResInfo列表){
字符串packageName=resolveInfo.activityInfo.packageName;
grantUriPermission(packageName、contentUri、Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
if(packageNameOfApp!=null){
if(appInstalledOrNot((活动)上下文,packageNameOfApp))
意图.setPackage(packageNameOfApp);
其他的
返回false;
}
context.startActivity(Intent.createChooser(Intent,intentMessage));
}捕获(例外e){
e、 printStackTrace();
}
返回true;
}
当我尝试直接发布到Instagram故事时,它会出现一个带有Toast消息的黑屏,无法刷新提要将Instagram应用程序包设置为intent package将完成您的工作
Uri uri = Uri.fromFile(new File(YOUR_FILE_PATH))
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setPackage("com.instagram.android"); //Instagram App package
startActivity(Intent.createChooser(shareIntent, "Share.."));
希望能对你有所帮助。经过长时间的研究,我终于找到了答案
private void shareStory(){
Uri backgroundAssetUri = FileProvider.getUriForFile(this, "your_package_name.provider", imgFile);
Intent storiesIntent = new Intent("com.instagram.share.ADD_TO_STORY");
storiesIntent.setDataAndType(backgroundAssetUri, "image/*");
storiesIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
storiesIntent.setPackage("com.instagram.android");
this.grantUriPermission(
"com.instagram.android", backgroundAssetUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
this.startActivity(storiesIntent);
}
@Vivek Faldu请看一下谢谢你的帮助。。。我刚刚解决了这个问题。。这是一张照片。。我正在发送png文件广告,数据标签是jpeg格式的。你有问题,如果你尝试上面的代码,那么在你的选择器中,只有Instagram应用程序会显示,没有其他应用程序会显示。感谢Shamsul,我需要在可用的应用程序中共享…除了Instagram story之外,其他所有应用程序都工作正常。它对我不起作用,它会打开相机而不是使用图像