Android-如何通过检查已发送邮件来确定是否已发送电子邮件 [英] Android - How to figure out if EMail was sent by checking sent items

查看:78
本文介绍了Android-如何通过检查已发送邮件来确定是否已发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,可以使用如下所示的意图发送电子邮件:

I have an application where I send EMails using an intent as shown below:

//TODO attach and send here
try {           

    Log.i(getClass().getSimpleName(), "send  task - start");

    String address = "emailHere@yahoo.com";
    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();
}

现在,用户选择他或她想要使用哪个应用程序来发送该电子邮件.但是,一旦选定的电子邮件应用程序接管了我,我便知道无法确定电子邮件是否正确发送.这里已经讨论了几个问题,因为 RESULT_OK 从未通过电子邮件或GMail Ap发送,所以使用 startActivityForIntent()没有帮助.发送,丢弃或保存为草稿的电子邮件.

Now, the user chooses which application he or she wants to use in order to send that EMail. However, once the selected Email application takes over, I know there's no way to figure out if the email was sent properly or not. It has been discussed in several questions here that using startActivityForIntent() does not help since RESULT_OK is never sent by the EMail or GMail Ap so I wouldn't know if the user sent, discarded, or saved the email as a draft.

但是,一种可能的解决方法是检查该电子邮件帐户的已发送邮件",然后从那里检查用户是否发送了电子邮件.现在,有没有办法知道Android中电子邮件帐户的已发送项目?在过去的一个小时里,我一直在做Google搜索,但似乎什么也没得到.

However, one possible work around is to check the Sent Items of that email account and check from there if the user sent an email or not. Now, is there a way to know the sent items of an email account in Android? I've been doing a google search for the past hour and I can't seem to get anything.

推荐答案

您无法检查Email ContentProvider的内容,因为这需要只有系统应用程序才能请求的权限.在 AndroidManifest for Email 中定义:

You cannot check the content of the Email ContentProvider, because this requires a permission that only system apps can request. This is defined in AndroidManifest for Email:

<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>

这篇关于Android-如何通过检查已发送邮件来确定是否已发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆