そのアプリケーションでアプリケーションを作成して、画像のようなレイアウトを共有しています。共有している間、レイアウトを画像に変換してSNSで共有していますが、問題は画像が内部ストレージに保存されることと、画像を共有した後に削除する方法です。
bitmap = Bitmap.createBitmap(itemView.getWidth(), itemView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
itemView.draw(canvas);
try {
// output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/path/to/file.png");
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "share_image_" + System.currentTimeMillis() + ".png");
image_path = file.getAbsolutePath();
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 50, out);
out.close();
bmpUri = Uri.fromFile(file);
sharePost();
public void sharePost() {
try {
Resources resources = context1.getResources();
final String photoUri = MediaStore.Images.Media.insertImage(
context1.getContentResolver(), image_path, null, null);
Intent emailIntent = new Intent();
emailIntent.setAction(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
emailIntent.setType("image/*");
PackageManager pm = context1.getPackageManager();
Intent openInChooser = Intent.createChooser(emailIntent, "Share via Oddcast");
List<ResolveInfo> resInfo = pm.queryIntentActivities(emailIntent, 0);
List<LabeledIntent> intentList = new ArrayList<LabeledIntent>();
for (int i = 0; i < resInfo.size(); i++) {
// Extract the label, append it, and repackage it in a LabeledIntent
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
if (packageName.contains("android.email")) {
emailIntent.setPackage(packageName);
} else {
emailIntent.setComponent(new ComponentName(packageName, ri.activityInfo.name));
if (packageName.contains("twitter")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
} else if (packageName.contains("facebook")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
} else if (packageName.contains("mms")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
} else if (packageName.contains("android.gm")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
} else if (packageName.contains("whatsapp")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
}else if (packageName.contains("com.google.android.apps.plus")) {
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(photoUri));
}
else{
emailIntent.putExtra(Intent.EXTRA_STREAM, MyCustomAdapter.bmpUri);
}
intentList.add(new LabeledIntent(emailIntent, packageName, ri.loadLabel(pm), ri.icon));
}
}
// convert intentList to array
LabeledIntent[] extraIntents = intentList.toArray(new LabeledIntent[intentList.size()]);
openInChooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
context1.startActivity(openInChooser);
Log.e("start", "start");
}catch (SecurityException e) {
Toast.makeText(context1, "Please check your permissions settings.Permission issue.", Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (Exception e) {
Toast.makeText(context1, "Please check your permissions settings.Permission issue.", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
file.delete();
Log.e("emd","end");
//context1.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(String.valueOf(bmpUri)))));
}