且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在其他应用程序***享图像

更新时间:2023-02-01 16:20:07

尝试此代码

  Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);

  shareIntent.setType("image/*");

  shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, (String)                       
  v.getTag(R.string.app_name));

  shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri); // put your image URI

  PackageManager pm = v.getContext().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);

      v.getContext().startActivity(shareIntent);

      break;
    }
  }

编辑1

Intent shareIntent = new Intent();
         shareIntent.setAction(Intent.ACTION_SEND);

         shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(filePath)));  //optional//use this when you want to send an image
         shareIntent.setType("image/jpeg");
         shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
         startActivity(Intent.createChooser(shareIntent, "send"));

使用此代码我尝试过,它可以在我这边工作

use this code i tried it and it works here at my side