Android Instagram共享问题:有时我会收到消息;无法加载图像";
我正在使用Android Instagram共享问题:有时我会收到消息;无法加载图像";,android,android-intent,instagram,Android,Android Intent,Instagram,我正在使用Intent将共享功能用于社交应用程序 我在Instagram中共享图像时遇到问题 有时我会得到这个信息 无法加载图像 这是我的密码: String path="content://media/external/images/media/32872"; Intent shareIntent = new Intent(); shareIntent.setType("image/jpeg"); shareIntent.setAction(Intent.ACTION_SEND); shar
Intent
将共享功能用于社交应用程序
我在Instagram中共享图像时遇到问题
有时我会得到这个信息
无法加载图像
这是我的密码:
String path="content://media/external/images/media/32872";
Intent shareIntent = new Intent();
shareIntent.setType("image/jpeg");
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
shareIntent.setPackage("com.instagram.android");
startActivity(shareIntent);
如何解决此问题?如果您有文件,请使用以下代码共享图像
private void shareIntagramIntent(String path) {
Intent intent = getActivity().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("file://" + path));
} catch (Exception e) {
// TODO Auto-generated catch block
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);
}
}
试试这个:
File filepath = Environment.getExternalStorageDirectory();
cacheDir = new File(filepath.getAbsolutePath() + "/LikeIT/");
cacheDir.mkdirs();
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filepath.getAbsolutePath()));
activity.startActivity(intent);
首先,确保在清单中添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
别忘了加上
Intent.FLAG\u GRANT\u READ\u URI\u权限
如果没有上述权限,则出现“无法共享”错误。谢谢您的回复。我也使用过这段代码,但它不起作用。今天我在instagram上遇到了同样的问题,但上面的代码对我有效。这是重要的Uri.parse(“文件:/”+path)。这很好。但在Uri中传递的是哪条路径?你能分享你的道路吗@NullByteUse File.getPath()或File.getAbsolutePath()我也使用过此路径,但有一段时间它不起作用。。在instagram中,图像共享的高度、宽度或大小有何限制@空字节
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="path_name"
path="." />
</paths>
<provider
android:name=".utils.FileAccessProvider"
android:authorities="${applicationId}.path_name.file.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
Intent intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
if (intent != null) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.instagram.android");
File logFile = new File(path);
if (logFile.exists()) {
Uri logFileUri = FileAccessProvider.getUriForFile(context,
getApplicationContext().getPackageName() +
".path_name.file.provider", logFile);
// shareIntent.setDataAndType(logFileUri, "image/*");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.putExtra(Intent.EXTRA_STREAM, logFileUri);
}
shareIntent.setType("image/*");
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);
}