Skip to content

Instantly share code, notes, and snippets.

@qpark99
Last active December 31, 2015 12:59
Show Gist options
  • Save qpark99/7989583 to your computer and use it in GitHub Desktop.
Save qpark99/7989583 to your computer and use it in GitHub Desktop.
Android 이미지 공유하기
// 참고 http://stackoverflow.com/questions/15702891/how-to-share-text-image-in-google-plus-g-from-android-without-using-intent
public void shareImage(String appName, File file) {
List<Intent> targetedShareIntents = new ArrayList<Intent>();
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/jpeg");
List<ResolveInfo> resInfo = mContext.getPackageManager().queryIntentActivities(share, 0);
if ( !resInfo.isEmpty() ) {
for ( ResolveInfo info : resInfo ) {
Intent targetedShare = null;
Log.i(">>>>>>>>", "PackageName : " + info.activityInfo.packageName + " / " + info.activityInfo.name);
if ( info.activityInfo.packageName.toLowerCase().contains(appName) ||
info.activityInfo.name.toLowerCase().contains(appName) ) {
targetedShare = ShareCompat.IntentBuilder.from((Activity)mContext)
.setType("image/jpeg")
.setStream(Uri.fromFile(file))
.getIntent()
.setPackage(info.activityInfo.packageName);
targetedShareIntents.add(targetedShare);
}
}
if ( targetedShareIntents.size() == 0 ) {
// FIXME : Event Dispatch!!
Toast.makeText(mContext, "없음 : " + appName, Toast.LENGTH_LONG);
return;
}
Intent chooserIntent = Intent.createChooser(targetedShareIntents.remove(0), "Select app to share");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedShareIntents.toArray(new Parcelable[]{}));
mContext.startActivity(chooserIntent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment