3

我用

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 用于设备。我选择在 facebook 上分享。//但是内容是空的,不是我要共享的图像,我无法共享图像。

这是意图操作发送不使用 facebook sdk。你能帮我吗?

4

2 回答 2

10

您将使用这种方式访问​​ 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"));
于 2013-01-12T07:28:39.303 回答
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);
            }
        }
    }

这对我来说可以 。我相信它也对你有用。

于 2013-01-12T07:33:06.730 回答