2014-08-28 47 views
1

我想通過電子郵件意向從sdcard發送.apk文件,但沒有獲得附件。如何通過電子郵件發送Android SDK中的.apk文件通過電子郵件itent?

見下文codei試試這個代碼,但不是爲我工作..

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("text/plain"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, 
      new String[] { "email id" }); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, 
      "Test Subject"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, 
      "go on read the emails"); 
    Log.v(getClass().getSimpleName(), 
      "sPhotoUri=" + Uri.parse("file:/" + "/sdcard/obb/rr.apk")); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, 
      Uri.parse("file:/" + "/sdcard/obb/rr.apk")); 
    startActivity(Intent.createChooser(emailIntent, "Send mail...")); 

這個代碼表示無法連接,而不是獲取郵件。

+0

請嘗試[this1](http://stackoverflow.com/a/18552517/1289716) – MAC 2014-08-28 06:53:47

回答

3

試圖改變自己的附件的類型如下:

  emailIntent.setType("application/zip"); 
+0

這也適用於我謝謝.. – Roadies 2014-08-28 07:00:33

0

不要使用硬編碼/sdcard/也不能保證SD卡將有路徑

而是改變

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/" + "/sdcard/obb/rr.apk")); 

Uri fileUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separatorChar + "obb" + File.separatorChar + "rr.apk")); 
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri); 

而且改變

emailIntent.setType("text/plain"); 

emailIntent.setType("application/zip"); 
1

感謝幫助我得到了使用這種一個郵件。

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
    emailIntent.setType("*/*"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"email id"}); 
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App new 1"); 
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///mnt/sdcard/rr.apk")); 
    startActivity(Intent.createChooser(emailIntent, "Send mail..."));