当Email未设置账户时,通过ACTION_SENDTO启动会报ActivityNotFoundException

当Email未设置账户时,通过ACTION_SENDTO启动会报ActivityNotFoundException

手机里已经安装了email的apk,检查manitfest中也有对应的action,并且activity也没有被disable掉,为何就是找不到呢?

<activity
android:name="com.android.email.activity.ComposeActivityEmail"
android:label="@string/app_name"
android:documentLaunchMode="intoExisting"
android:autoRemoveFromRecents="true"
android:theme="@style/ComposeTheme">
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
<action
android:name="android.intent.action.SENDTO" />
<data
android:scheme="mailto" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.BROWSABLE" />
</intent-filter>

1.我下载了一个QQ邮箱安装到手机,发现ACTION_SENDTO启动QQ邮箱的设置界面
2.我把QQ邮箱卸载了,在原生Email里面登录一个账号,再ACTION_SENDTO可以启动对应的ComposeActivityEmail
3.那就是没有账号不能启动ComposeActivityEmail
4.ActivityStarter中startActivityMayWait的ResolveInfo rInfo = mSupervisor.resolveIntent(intent, resolvedType, userId);
和 ActivityInfo aInfo = mSupervisor.resolveActivity(intent, rInfo, startFlags, profilerInfo);当有账号rInfo 和aInfo 都不为null,当没有账号返回的是null.

5.通过分析得知ComposeActivityEmail是动态被enable和disable的,所以搜索setComponentEnabledSetting,找到了关键代码
http://androidxref.com/7.1.1_r6/xref/packages/apps/Email/provider_src/com/android/email/provider/AccountReconciler.java
 if (!TextUtils.isEmpty(composeActivityName)) {
// If there are no accounts remaining after reconciliation, disable the compose activity
final boolean enableCompose = emailProviderAccounts.size() - accountsDeleted > 0;
final ComponentName componentName = new ComponentName(context, composeActivityName);
context.getPackageManager().setComponentEnabledSetting(componentName,
enableCompose ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
LogUtils.d(LogUtils.TAG, "Setting compose activity to "
+ (enableCompose ? "enabled" : "disabled"));
}


将这部分代码拿掉没有账号也可以启动email来处理sendto

具体为何google要这样做,目前还没有找到其理由。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值