2012-07-11 2 views
0

저는 여기에 새 초보자입니다. 내 Android 앱에 약간의 문제가 있습니다. 특히 이미지를 클릭하면 이벤트가 발생합니다. 이 이벤트는 미리 작성된 텍스트가 포함 된 이메일 클라이언트를 열고 이미지의 이미지를 첨부해야합니다. 이미지를 비트 맵으로 변환 한 다음 압축하여 전자 메일 클라이언트로 보내야한다는 것을 이미 알고 있지만 안타깝게도 Android/Java 전문가가 아니므로이를 수행하는 방법을 찾을 수 없습니다. 이 이메일 메소드의 코드입니다 : 내가 교체해야Android : ImageView에서 이미지가 포함 된 이메일을 보내주세요.

새로운 코드

다음 "문자열 imageURI = NULL을;" 이메일이 이미지로 필요한 것. 다들 감사 해요!

편집 :

나는이 내 코드를 편집 관리

, 제공 오류 :

public void sendMail(ImageView image){ 
    Intent i = new Intent(Intent.ACTION_SEND); 
    int imageURI = R.drawable.img1; 

    i.setType("text/plain"); 
    i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
    i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto"); 
    i.putExtra(Intent.EXTRA_TEXT , "Globelife"); 
    i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    i.setType("image/jpeg"); 
    i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI)); 


    try { 
     startActivity(Intent.createChooser(i, "Send mail...")); 
    } catch (android.content.ActivityNotFoundException ex) { 
     Toast.makeText(Test01Activity.this, "Non sono presenti app per l'invio di e-mails.", Toast.LENGTH_SHORT).show(); 
    } 

} 

는하지만 변경할 필요가 없다 "INT imageURI = R.drawable.img1;" ~ "int imageURI = ImageView.src;" 또는

+0

보내려는 이미지는 로컬 SDCard에 저장되었거나 인터넷에서 전송됩니까? –

+0

이미지가 앱의 드로어 블 폴더에 있음 – Stefano

답변

4

시도 이동이

ImageView iv = (ImageView) findViewById(R.id.splashImageView); 
Drawable d =iv.getBackground(); 
BitmapDrawable bitDw = ((BitmapDrawable) d); 
Bitmap bitmap = bitDw.getBitmap(); 
File mFile = savebitmap(bitmap); 

다음

Uri u = null; 
    u = Uri.fromFile(mFile); 

    Intent emailIntent = new Intent(Intent.ACTION_SEND); 
    emailIntent.setType("image/*"); 
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hello..."); 
    // + "\n\r" + "\n\r" + 
    // feed.get(Selectedposition).DETAIL_OBJECT.IMG_URL 
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Your tsxt here"); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, u); 
    startActivity(Intent.createChooser(emailIntent, "Send email...")); 

savebitmap 방법

private File savebitmap(Bitmap bmp) { 
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 
    OutputStream outStream = null; 
    File file = new File(extStorageDirectory, temp + ".png"); 
    if (file.exists()) { 
    file.delete(); 
    file = new File(extStorageDirectory, temp + ".png"); 
    } 

    try { 
    outStream = new FileOutputStream(file); 
    bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); 
    outStream.flush(); 
    outStream.close(); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    return null; 
    } 
    return file; 
} 
+0

마지막 줄의 코드 ("i.putExtra (Intent.EXTRA_STREAM, bis);")에서 "메소드 putExtra (String, boolean) in 형식 인 텐트는 인수 (String, ByteArrayInputStream)에 적용 할 수 없습니다. " – Stefano

+0

@Stefano 내 잘못 .. 내 대답을 편집했습니다. 시도해보세요. –

+0

코드는 컴파일 오류를주지 않지만 이미지를 탭하면 SendMail (ImageView 이미지) (우리가 작업중인 이미지)에서 NullPointerException을 보내는 전자 메일을 보내십시오. 나는 지금 무엇이 잘못되었는지를 찾으려고 노력하고있다. – Stefano

-1

// 다시 같은이 String imageURI=null;

public void sendMail(ImageView image){ 
    Intent i = new Intent(Intent.ACTION_SEND); 

Uri pngImageUri = Uri.parse(image); 


i.setType("image/png");//change here with image/png 
    i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"}); 
    i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto"); 
    i.putExtra(Intent.EXTRA_TEXT , "Testo"); 
    i.putExtra(Intent.EXTRA_STREAM, pngImageUri); 
+0

안녕하세요, 다시 "Uri.parse (image);"를 사용하려고합니다. 하지만 그것은 "Uri 형식의 메서드 parse (String)은 인수 (ImageView)에 적용 할 수 없습니다" – Stefano

+0

다음 'Uri.fromFile (image);'을 사용하십시오. –

+0

같은 오류가 발생했습니다. File ("Uri 유형의 메서드 fromFile (File) (파일 (ImageView) 인수에 해당되지 않습니다.") – Stefano

0
Intent intent=new Intent(Intent.ACTION_SEND); 
String[] recipients={"[email protected]"}; 
intent.putExtra(Intent.EXTRA_EMAIL, recipients); 
intent.putExtra(Intent.EXTRA_SUBJECT, "Oggetto"); 
intent.putExtra(Intent.EXTRA_TEXT , "Testo"); 
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
intent.setType("image/png"); 
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse(“file///sdcard/Images/your_image.jpg”));//or you can pass the path of your image 
startActivity(Intent.createChooser(intent, "Send mail")); 
0
Intent i = new Intent(Intent.ACTION_SEND); 
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
i.setType("image/jpg"); 
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/ 
image.jpg")); 
startActivity(i); 
관련 문제