Android的奇巧4.4环聊无法处理发送短信的意图 [英] Android KitKat 4.4 Hangouts cannot handle Sending SMS intent

查看:130
本文介绍了Android的奇巧4.4环聊无法处理发送短信的意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code发送的完美工作,直到Android的4.3(果冻豆)短信停止工作,因为4.4(奇巧)

Code for sending sms that worked perfectly till Android 4.3 (Jelly Bean) stopped working since 4.4 (KitKat)

我只是preparing用户的文本消息,但他需要来选择号码发送到

I'm just preparing the text message for the user, but he needs to choose the number to send to

在code我用的是:

Intent sendIntent = new Intent(Intent.ACTION_VIEW);         
    sendIntent.setData(Uri.parse("sms:"));
    sendIntent.putExtra("sms_body", smsText);

    activity.startActivity(sendIntent);

由于它停止工作,我也尝试了 ACTION_SEND ACTION_SENDTO 两人都没有工作,我也试过 sendIntent.setType(vnd.android-DI​​R / MMS,SMS); ,又没有什么工作

Since it stopped working I tried also the ACTION_SEND and ACTION_SENDTO Both didn't worked, I also tried the sendIntent.setType("vnd.android-dir/mms-sms");, again nothing worked.

我找了几个答案在计算器<一href="http://stackoverflow.com/questions/19560323/send-sms-message-using-non-default-sms-app-on-android-4-4">answer 1 和回答2 ,但两者的答案都是不处理的要求我。

I looked for several answers in stackoverflow answer 1 and answer 2, but both answers aren't dealing with the requirements I have.

我想这样做的:

  • 发送短信SMS应用程序,而不能服务于发送意图所有的应用程序
  • prepare的文本用户
  • 让用户选择的电话号码发送消息给

有关版主: 这不是一个重复的问题,因为这些问题,不问同样的事情,这里需要的是发送短信,没有电话号码,并且没有任何处理的问题和答案。

For moderators: It is not a duplicate questions, since the questions, doesn't ask the exact same thing, the need here is to send sms with no phone number, and none of the questions and answers dealt with that.

推荐答案

我附加了code,以解决通过执行以下问题:

I attached a code that solve the problem by doing the following:

  • 检查操作系统版本
  • 在该情况下,旧版本(之前奇巧),用老方法
  • 如果新的API,检查默认SMS程序包。如果有任何,将其设置为包,否则,让用户选择共享应用程序。

下面是code:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat
    {
        String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity); //Need to change the build to API 19

        Intent sendIntent = new Intent(Intent.ACTION_SEND);
        sendIntent.setType("text/plain");
        sendIntent.putExtra(Intent.EXTRA_TEXT, smsText);

        if (defaultSmsPackageName != null)//Can be null in case that there is no default, then the user would be able to choose any app that support this intent.
        {
            sendIntent.setPackage(defaultSmsPackageName);
        }
        activity.startActivity(sendIntent);

    }
    else //For early versions, do what worked for you before.
    {
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.setData(Uri.parse("sms:"));
        sendIntent.putExtra("sms_body", smsText);
        activity.startActivity(sendIntent);
    }

这篇关于Android的奇巧4.4环聊无法处理发送短信的意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆