如何通过电子邮件发送Android SDK中的.apk文件通过电子邮件itent?

问题描述:

我想通过电子邮件意向从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://*.com/a/18552517/1289716) – MAC 2014-08-28 06:53:47

试图改变自己的附件的类型如下:

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

这也适用于我谢谢.. – Roadies 2014-08-28 07:00:33

不要使用硬编码/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"); 

感谢帮助我得到了使用这种一个邮件。

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..."));