Intent.ACTION_VIEW无法调用短信页面

今天在开发的过程中,遇到一个奇怪的问题,在 Nexus 系列的手机上没有办法使用Intent.ACTION_VIEW调用短信页面时会出现这个

No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }

日志。 后来谷歌了半天 总算找到一个可以解决的答案。  
上代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); //Need to change the build to API 19
    Intent sendIntent = new Intent(Intent.ACTION_SEND , smsToUri);
    sendIntent.putExtra("sms_body", shareParams.getText());
    sendIntent.setType("text/plain");
    if (defaultSmsPackageName != null){
        sendIntent.setPackage(defaultSmsPackageName);
    }
    context.startActivity(sendIntent);
} else {
    Intent sendIntent = new Intent(Intent.ACTION_VIEW, smsToUri);
    sendIntent.putExtra("sms_body", shareParams.getText());
    sendIntent.setType("vnd.android-dir/mms-sms");
    context.startActivity(sendIntent);
}

关键是
Intent.ACTION_SEND 
    sendIntent.setType("text/plain");


写下来作为记录
private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (Intent.ACTION_TIME_TICK.equals(action) || Intent.ACTION_TIME_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action) || Intent.ACTION_LOCALE_CHANGED.equals(action)) { if (Intent.ACTION_LOCALE_CHANGED.equals(action) || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) { // need to get a fresh date format mDateFormat = null; } updateClock(); } } }; public DateView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_TIME_TICK); filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_LOCALE_CHANGED); mContext.registerReceiver(mIntentReceiver, filter, null, null); updateClock(); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); mDateFormat = null; // reload the locale next time mContext.unregisterReceiver(mIntentReceiver); } protected void updateClock() { if (mDateFormat == null) { final String dateFormat = getContext().getString(R.string.system_ui_date_pattern); final Locale l = Locale.getDefault(); final String fmt = ICU.getBestDateTimePattern(dateFormat, l.toString()); mDateFormat = new SimpleDateFormat(fmt, l); } mCurrentTime.setTime(System.currentTimeMillis()); final String text = mDateFormat.format(mCurrentTime); if (!text.equals(mLastText)) { setText(text); mLastText = text; } } }
最新发布
06-08
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值