2017-09-24 16 views
0

レイアウトから画像を取得していて、保存したくありません。私は意図を介して直接それを共有したいACTION_SENDサービス。私はそれがここで例外Transaction Too many Large: data parcel size 2315980 bytes保存しないときにビットマップを圧縮する方法

を与えて送信するときに私のコードスニペットは、

View myview = (View) findViewById(R.id.mylayout); 

Bitmap mypicture = getBitmapFromView(myview); 

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra("", mypicture); 

intent.setType("image/jpeg"); 
startActivity(intent); 
+0

イメージの設定に使用するuri/pathを保持できます。代わりにあなたの意図でそのURIを送信してください。 –

+0

私はそれをする方法を知らない – Mudassir

答えて

0

である私は意図ACTION_SENDサービスを通じて直接

を、それを共有したいオプションされていないこと。 EXTRA_TEXT holds textEXTRA_STREAM holds a Uri。どちらもBitmapです。ここで

私のコードスニペットにはACTION_SEND活動が空のキーと余分を探しませんようご余分は、無意味である

です。

0

ビットマップをファイルに保存してから、そのファイルにuri /リンクを共有できます。それを共有する

public static File saveBitmapInternal(Context context, Bitmap bitmap) { 
    File imagePath = new File(context.getFilesDir(), "images"); 
    if (!imagePath.exists() && !imagePath.mkdirs()) { 
     print("Make dir failed"); 
    } 

    return saveBitmap(bitmap, "preview.png", imagePath); 
} 


private static File saveBitmap(Bitmap bitmap, String filename, File root) { 
    print(String.format("Saving %dx%d bitmap to %s.", bitmap.getWidth(), bitmap.getHeight(), filename)); 

    final File file = new File(root, filename); 
    if (file.exists()) { 
     file.delete(); 
    } 
    try { 
     final FileOutputStream out = new FileOutputStream(file); 
     bitmap.compress(Bitmap.CompressFormat.PNG, 99, out); 

     out.flush(); 
     out.close(); 

     return file; 
    } catch (final Exception e) { 
     print("Exception!" + e); 
    } 
    return null; 
} 

 // Uri uri = Uri.fromFile(file); 
     Uri uri = FileProvider.getUriForFile(context, 
       context.getString(R.string.file_provider_authority), 
       file); 

     final Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setType("image/*"); 
     intent.putExtra(Intent.EXTRA_STREAM, uri); 

     intent.putExtra(Intent.EXTRA_TEXT, shareText); 
     context.startActivity(Intent.createChooser(intent, "Share media")); 

はあなたのマニフェスト(https://developer.android.com/reference/android/support/v4/content/FileProvider.html参照)でファイルプロバイダを設定する必要があります。 fileproviderに関するクエリがある場合は、別の質問を作成することができます。

+0

私はファイルプロバイダを作る際にも助けてください私は最後にUriの最後のパラメータに問題がありますUriの最後のパラメータに実際に渡すもの – Mudassir

関連する問題