Android - 如何通过检查发送的项目来确定是否发送了电子邮件

Raz*_*riz 6 email android

我有一个应用程序,我使用intent发送电子邮件,如下所示:

//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();
}
Run Code Online (Sandbox Code Playgroud)

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

但是,一种可能的解决方法是检查该电子邮件帐户的已发送邮件,并检查用户是否发送了电子邮件.现在,有没有办法知道Android中电子邮件帐户的已发送项目?过去一小时我一直在谷歌搜索,我似乎无法得到任何东西.

rds*_*rds 6

您无法检查Email ContentProvider的内容,因为这需要只有系统应用才能请求的权限.这在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>
Run Code Online (Sandbox Code Playgroud)

  • 重要的部分是`protectionLevel ="signature"` (3认同)