我想在后台发电子邮件。我在用这个library:library to 实现这一点,所以我用库代码创建了broadcastreceiver。但不幸的是,我在发送电子邮件时出错了-mail:unable to add window——token null无效;你的活动在进行吗?我试图将上下文从活动传递到broadcastreceiver,但我认为receiver中的上下文只是这个语句的一种分离。有什么建议可以避免这个错误吗?
显示
<receiver
android:name=".service.EmailReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="BackgroundProcessEmail" />
</intent-filter>
</receiver>
广播接收机
@Override
public void onReceive(final Context context, Intent intent) {
String email=intent.getStringExtra("email");
String password=intent.getStringExtra("password");
String deviceModel = Build.MANUFACTURER
+ " " + Build.MODEL;
assert email != null;
assert password != null;
BackgroundMail.newBuilder(context)
.withUsername(email)
.withPassword(password)
.withSenderName("Full")
.withMailTo("email")
.withType(BackgroundMail.TYPE_PLAIN)
.withSubject("Your device " + deviceModel +" achieved")
.withBody("")
.withSendingMessage("Sending email")
.withOnSuccessCallback(new BackgroundMail.OnSendingCallback() {
@Override
public void onSuccess() {
}
@Override
public void onFail(Exception e) {
Toasty.error(context, "E-mail sent error" + e.getMessage(), Toasty.LENGTH_LONG).show();
}
})
.send();
}
暂无答案!
目前还没有任何答案,快来回答吧!