我正在使用
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file//res/drawable/u.png");
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
//我使用sumsung real for device.and我选择在facebook上分享。 //但是内容是空的而不是我的共享图像我无法共享图像。
这是意图动作发送不使用facebook sdk。 你可以帮帮我吗?
答案 0 :(得分:10)
以这种方式使用Access Drawable文件夹会出错。
Uri imageUri = Uri.parse("android.resource://your.package/drawable/fileName");
您应该尝试这种方式:
Uri imageUri = Uri.parse("android.resource://your.package/drawable/fileName");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent , "Share"));
答案 1 :(得分:2)
尝试这种方式:
Uri pngUri = Uri.parse("file//res/drawable/u.png"); Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("image/png"); shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"YOUR TEXT HERE"); shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,"YOUR TEXT HERE"); shareIntent.putExtra(android.content.Intent.EXTRA_STREAM,pngUri); PackageManager pm = getApplicationContext().getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ((app.activityInfo.name).contains("facebook")) { final ActivityInfo activity = app.activityInfo; final ComponentName name = new ComponentName( activity.applicationInfo.packageName, activity.name); shareIntent.addCategory(Intent.CATEGORY_LAUNCHER); shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); shareIntent.setComponent(name); startActivity(shareIntent); } } }
对我来说很好。我相信它也适合你。