2016-07-19 28 views
0

私はカメラで撮影した画像を送信する必要があるAndroidアプリケーションを作成していますが、セキュリティ上の理由からこの画像をユーザーデバイスに保存することはできません。デバイスに保存せずに電子メールでビットマップを送信する - Android

電子メールでビットマップを送信したことで見つかったすべての解決策は、そのアプリケーションのディレクトリに保存してから、そのパスを使用して送信するようです。

私のアプリケーションでは、イメージはこの非常にアクティビティ(および電子メールで送信された場合)でのみ使用されます。

Soo ...ビットマップを保存せずに送信してもどうですか?

編集: ここで私はこれを今のところ行っています(btwは動作していません)。

public void sendEmail(){ 
     Intent i = new Intent(Intent.ACTION_SEND); 
     if(foto) { //if user attached a pic 
      i.setType("image/png"); 
      i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
      i.putExtra(Intent.EXTRA_SUBJECT, "Assistencia Tecnica"); 
      i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(problemPicture)); 
      i.putExtra(Intent.EXTRA_TEXT, commentText.getText()); 
      problemPicture.delete(); 
      try { 
       startActivity(Intent.createChooser(i, "Enviando Email...")); 
      } catch (android.content.ActivityNotFoundException ex) { 
       Toast.makeText(StatusActivity.this, "Comunicaçaõ Falhou", 
         Toast.LENGTH_SHORT).show(); 
      } 
      try { 
       // We try to delete the picture 
       boolean success = problemPicture.delete(); 
       if(success) { 
        Log.i(TAG, "File deleted successfully"); 
       } else { 
        if(problemPicture.isDirectory()) { 
         success = deleteDirectory(problemPicture); 
         if(success) { 
          Log.i(TAG, "Directory deleted successfully!"); 
         } else { 
          Log.i(TAG, "Could not delete directory"); 
         } 
        } 
        Log.i(TAG, "File could not be deleted"); 
       } 
      } catch (NullPointerException e) { 
       // In case we don't find it 
       Log.i(TAG, "File not found"); 
      } 

      try { 
       deleteFile("problemPicture.png"); 
      } catch(NullPointerException e) { 
       Log.i(TAG, "Context file not found"); 
      } 
     } 
     else { 
      i.setType("plane/text"); 
      i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
      i.putExtra(Intent.EXTRA_SUBJECT, "Assistencia Tecnica"); 
      i.putExtra(Intent.EXTRA_TEXT, commentText.getText()); 
      try { 
       startActivity(Intent.createChooser(i, "Enviando Email...")); 
      } catch (android.content.ActivityNotFoundException ex) { 
       Toast.makeText(StatusActivity.this, "Comunicaçaõ Falhou", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    } 

が活動

エンディング:結果

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    //Converts picture to PNG 
    if ((requestCode == CAMERA_PIC_REQUEST) && (resultCode == RESULT_OK)) { 
     thumbnail  = (Bitmap) data.getExtras().get("data"); 
     ImageView image = (ImageView) findViewById(R.id.image_comment); 
     image.setImageBitmap(thumbnail); 

     try { 
      File root = Environment.getExternalStorageDirectory(); 
      if (root.canWrite()){ 
       // We + "/MapTest" to make it storage on a deeper directory for our application 
       problemPicture  = new File(getCacheDir(), "problemPicture.png"); 
       FileOutputStream out = new FileOutputStream(problemPicture); 
       thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out); 
       out.flush(); 
       out.close(); 
      } 
     } catch (IOException e) { 
      Log.e("BROKEN", "Could not write file " + e.getMessage()); 
     } 
    } 
} 

(写真はその前に真の右側に設定されている)電子メールの送信を取得

imageButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 
     //Opens camera app 
     foto   = true; 
     Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     startActivityForResult(intent, 1); 
    } 
}); 

:カメラの呼び出し

private void endActivity() { 
    //Back to Maps Activity 
    boolean success = false; 
    try { 
     success = problemPicture.delete(); 
    } catch(NullPointerException e) { 
     Log.d(TAG, "No picture found"); 
    } 
    if(success) { 
     Log.i(TAG, "Picture deleted"); 
    } else { 
     Log.i(TAG, "Picture could not be deleted"); 
    } 

    success = deleteFile("problemPicture.png"); 
    if(success) { 
     Log.d(TAG, "File deleted"); 
    } else { 
     Log.d(TAG, "File could not be deleted"); 
    } 

    Toast.makeText(getApplicationContext(), "OS Finalizada",Toast.LENGTH_SHORT).show(); 
    Intent it = new Intent(StatusActivity.this, MapsActivity.class) 
      .putExtra("index", index); 
    startActivity(it); 
} 

悪いコードの壁には申し訳ありません、ありがとうございます!

+0

私たちはあなたを助けることができるコードを示してください! –

+0

これを行うには、私はあなたのアプリに直接電子メール送信を構築しなければならないと思います。添付ファイルを「メモリ内」に渡しても(または送信後に「ディスク」のファイルを削除しても)、電子メールの意図を使用すると、ユーザーの電話にある電子メールプログラムが起動します。そのほとんどは送信された電子メールのコピーを保持します。 – TripeHound

+0

@SohailZahid Done –

答えて

0

イメージの共有は、イメージのURIを目的のアプリケーションに送信します。 URIを使用せずに送信する方法はありません。 URIでは、画像を保存する必要があります。したがって、可能性はありません。共有後に削除することに問題がある場合は.... DiskCacheに保存しておくと、自動的にLRUに基づいて削除されます。

+0

知識を共有してくれてありがとう! –

+0

@ PedroCunial:ようこそ –

0
private static final int TAKE_PICTURE = 1; 

    public void takePhoto(View view) { 

     Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
     startActivityForResult(intent, TAKE_PICTURE); 
    } 

    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     if (resultCode == RESULT_OK) { 
      switch (requestCode) { 
       case TAKE_PICTURE: 
        if (resultCode == Activity.RESULT_OK) { 
         Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); 
         Uri uri = data.getData(); 
//      ImageView image = (ImageView) findViewById(R.id.image_comment); 
//      image.setImageBitmap(thumbnail); 
         // set image if you want to 

         Intent shareIntent = new Intent(); 
         shareIntent.setAction(Intent.ACTION_SEND); 
         shareIntent.putExtra(Intent.EXTRA_STREAM, 
           uri); 
         shareIntent.setType("image/jpeg"); 
         startActivity(Intent.createChooser(shareIntent, 
           "choose one")); 
         // your desired intent with your own parames subject and others 
         // no need to del and others. 
         // this is test in API 19 hope it will work for you too! 

        } 
        break; 
      } 
     } 
関連する問題