あなたがタイプIntent.ACTION_VIEW
の意図を使用してstartActivity
する必要があります。
私はあなたのリソースからdrawableを共有したいと思っています。だから最初にdrawableをビットマップに変換する必要があります。そして、ビットマップをファイルとして外部メモリに保存し、Uri.fromFile(new File(pathToTheSavedPicture))を使用してそのファイルのURIを取得し、そのURIをこのような意図に渡す必要があります。
shareDrawable(this, R.drawable.dish, "myfilename");
public void shareDrawable(Context context,int resourceId,String fileName) {
try {
//convert drawable resource to bitmap
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId);
//save bitmap to app cache folder
File outputFile = new File(context.getCacheDir(), fileName + ".png");
FileOutputStream outPutStream = new FileOutputStream(outputFile);
bitmap.compress(CompressFormat.PNG, 100, outPutStream);
outPutStream.flush();
outPutStream.close();
outputFile.setReadable(true, false);
//share file
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(outputFile));
shareIntent.setType("image/png");
context.startActivity(shareIntent);
}
catch (Exception e) { Toast.makeText(context, "error", Toast.LENGTH_LONG).show();
}
}