如何为KitKat设置默认SMS提示 [英] How to set Default SMS prompt for KitKat

查看:97
本文介绍了如何为KitKat设置默认SMS提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个SMS应用程序,可以正确显示所有消息,还创建了一个BroadcastReceiver,可以帮助我在到达时知道新消息.

I have created an SMS application that shows all the messages properly and also a BroadcastReceiver that helps in letting me know new messages on arrival.

使用URI的帮助content://mms-sms/conversations?simple=true我能够检索消息.

Using the URI's help content://mms-sms/conversations?simple=true I am able to retrieve the messages.

即使在KitKat上也可以正常工作.我可以发送短信,阅读短信,但由于我的应用程序不是默认的短信应用程序,因此无法删除该短信.

This is working fine even on KitKat. I can send SMS, read SMS but I am not able to delete the SMS because my App is not the default SMS app.

如何提示用户将应用设置为默认设置?我看了此博客:

How do I prompt user to make the App default? I looked at this blog:

我尝试了上面给出的代码,但没有发现任何区别?我在这里想念什么吗?

I tried the code given on it but I don't see any difference? Am I missing anything here?

这是代码:

 int currentapiVersion = android.os.Build.VERSION.SDK_INT;

    if (currentapiVersion >= 19)
    {
        final String myPackageName = getPackageName();
        if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) 
        {
            // App is not default.
            // Show the "not currently set as the default SMS app" interface
            View viewGroup = findViewById(R.id.not_default_app);
            viewGroup.setVisibility(View.VISIBLE);

            // Set up a button that allows the user to change the default SMS app
            button.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Intent intent =
                            new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
                    intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, 
                            myPackageName);
                    startActivity(intent);
                }
            });
        }
        else 
        {
            // App is the default.
            // Hide the "not currently set as the default SMS app" interface
            View viewGroup = findViewById(R.id.not_default_app);
            viewGroup.setVisibility(View.GONE);

        }
    }

等待您的回应! 谢谢!

Awaiting your response! Thanks!

推荐答案

我通过在清单中输入以下内容来解决.

I solved by entering the following in the manifest.

最重要的部分是我们应该使用的所有内容,包括MMS部分,否则将无法正常工作.

The most important part we should use everything, including MMS part if not it will not work.

<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity android:name=".ComposeSmsActivity" >
    <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <action android:name="android.intent.action.SENDTO" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="sms" />
        <data android:scheme="smsto" />
        <data android:scheme="mms" />
        <data android:scheme="mmsto" />
    </intent-filter>
</activity>

<!-- Service that delivers messages from the phone "quick response" -->
<service android:name=".HeadlessSmsSendService"
         android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE"
         android:exported="true" >
    <intent-filter>
        <action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="sms" />
        <data android:scheme="smsto" />
        <data android:scheme="mms" />
        <data android:scheme="mmsto" />
    </intent-filter>
</service>

这篇关于如何为KitKat设置默认SMS提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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