我有以下代码来从扩展BroadcastReceiver
类的类发送电子邮件:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
S2Mconfig s2m = new S2Mconfig();
Log.d(TAG, "Create Intent for mail to " + address);
emailIntent.setType("plain/text");
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, s2m.read(thisContext));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, address);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
Log.d(TAG, String.format("Sending mail %s", emailIntent.toString()));
thisContext.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
BroadcastReciever
是在manifest
中注册的,我设置了INTERNET
权限:
<uses-permission android:name="android.permission.INTERNET" />...
<receiver android:name=".SmsReceiver" android:exported="true" >
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.MMS_RECEIVED" />
</intent-filter>
</receiver>
日志确认在调用
startActivity()
之前已设置了FLAG_ACTIVITY_NEW_TASK
。尽管如此,我仍然遇到了可怕的"Calling startActivity()... requires the FLAG_ACTIVITY_NEW_TASK flag...
错误提示。
非常感谢您提供任何线索。