我有一个应用程序,我使用意图发送电子邮件,如下所示:
//TODO attach and send here
try {
Log.i(getClass().getSimpleName(), "send task - start");
String address = "[email protected] /cdn-cgi/l/email-protection";
String subject = "Order of " + customer + " for " + date;
String emailtext = "Please check the attached file. Attached file contains order of " + customer;
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext);
ArrayList<Uri> uris = new ArrayList<Uri>();
Uri uriList = Uri.fromFile(orderListFile);
uris.add(uriList);
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
catch (Throwable t) {
Toast.makeText(this, "Request failed: " + t.toString(),
Toast.LENGTH_LONG).show();
}
现在,用户选择他或她想要使用哪个应用程序来发送该电子邮件。但是,一旦选定的电子邮件应用程序接管,我知道就无法确定电子邮件是否已正确发送。这里的几个问题已经讨论过使用startActivityForIntent()
没有帮助,因为RESULT_OK
从未由电子邮件或 GMail Ap 发送,因此我不知道用户是否发送、丢弃或将电子邮件保存为草稿。
但是,一种可能的解决方法是检查该电子邮件帐户的已发送邮件,并从那里检查用户是否发送了电子邮件。现在,有没有办法知道 Android 中电子邮件帐户的已发送项目?过去一个小时我一直在谷歌搜索,但似乎什么也没得到。
您无法检查 Email ContentProvider 的内容,因为这需要只有系统应用程序可以请求的权限。这是定义在用于电子邮件的 AndroidManifest https://github.com/android/platform_packages_apps_email/blob/master/AndroidManifest.xml:
<permission
android:name="com.android.email.permission.ACCESS_PROVIDER"
android:protectionLevel="signature"
android:label="@string/permission_access_provider_label"
android:description="@string/permission_access_provider_desc"/>
…
<application>
…
<!-- This provider MUST be protected by strict permissions, as granting access to
it exposes user passwords and other confidential information. -->
<provider
android:name=".provider.EmailProvider"
android:authorities="com.android.email.provider;com.android.email.notifier"
android:exported="true"
android:permission="com.android.email.permission.ACCESS_PROVIDER"
android:label="@string/app_name"
/>
…
</application>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)