4

アプリから .gif を facebook や twitter などに共有したい.png のような単純な画像を facebook や twitter に共有することはできますが、.gif 画像を共有することはできません。実は、URL から .gif 画像を共有したいのです。それで、最初はsdcardから.gif画像を共有しようとして成功しましたが、drawableとURLからは成功しません。これらの 2 つの方法で .gif 画像を共有するにはどうすればよいですか? 以下のコードは、sdcard から .gif を正常に共有します。

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "g1.gif");
Uri pngUri = Uri.fromFile(yourFile);

//Not working from URL
//Uri pngUri = Uri.parse("http://www.gamecastor.com/iphoneapps/emoji/gangnamemoji/Group1/g1.gif");

//Not working from drawable
//Uri pngUri = Uri.parse("android.resource://com.example.asd/drawable/g1.gif");

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);

//code to share to facebook only
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);
    }
 }
4

0 に答える 0