如何设置我的默认应用程序接收SMS [英] How to set my application as default to receive SMS

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

问题描述

我开发一个应用程序发送和接收短信。我想补充的选项来设置我的默认应用程序像谷歌的Hangouts了:

i'm developing an application to send and receive SMS. I want to add the option to set my application as default like Hangout of Google:

你有一个想法?非常感谢。

Do you have an ideas? Thanks a lot.

推荐答案

如何设置你的应用程序为默认消息应用?

How to set your app as default messaging app?

Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, YOUR_PACKAGE_NAME);

如何检查,如果你的应用程序是默认消息应用?

How to check if your app is default messaging app?

@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isDefaultSmsApp(Context context) {
    return context.getPackageName().equals(Telephony.Sms.getDefaultSmsPackage(context));
}

从preference活动添加在preferenceClickListener并添加以下code里面它首先检查它是否已经是默认消息应用程序,然后打开一个屏幕,用户可以改变它,否则设置当前应用程序的默认信息应用。

From the preference activity add OnPreferenceClickListener and add the following code inside it which first check if it is already a default messaging app, then opens a screen where the user can change it else set the current app as the default messaging app.

 if (isDefaultSmsApp(getActivity())) {
                        startActivityForResult(new Intent(Settings.ACTION_WIRELESS_SETTINGS), 0);
                    } else {
                    final String packageName = getActivity().getPackageName();
                        Intent intent = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
                        intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, packageName);
                        startActivityForResult(intent, 0);
                    }

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

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