Android: How to share image with text on facebook via intent?

后端 未结 7 2472
眼角桃花
眼角桃花 2020-11-27 03:18

I\'d like to share a photo with caption pre-filled from my app via a share intent, on facebook.

Example code

Intent intent = new Intent();
intent.set         


        
7条回答
  •  粉色の甜心
    2020-11-27 04: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 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;
            }
          }
    

提交回复
热议问题