O türü Intent.ACTION_VIEW
niyetini kullanarak startActivity
gerekiyor.
Gördüğüm kadarıyla, kaynaklarınızdan çekilebilir bir şekilde paylaşmak istiyorsunuz. Bu yüzden ilk önce çekilebilir bir bitmap dönüştürmek zorunda. Ve sonra bitmap'i bir dosya olarak harici belleğe kaydetmeniz ve daha sonra Uri.fromFile (yeni Dosya (pathToTheSavedPicture)) kullanarak bu dosya için bir uri almanız ve bu uri'yi bu gibi niyetle geçirmeniz gerekir.
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();
}
}