android - 为 Android KitKat 准备 SMS 应用

标签 android sms android-version android-4.4-kitkat

与 Android 开发者最近发布的帖子一致 http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html ,我试图为新的 Android 版本准备我的应用程序,但遇到了他们建议创建一个对话框以让用户将应用程序设置为默认应用程序来处理短信的部分的问题:

Android 开发者帖子

public class ComposeSmsActivity extends Activity {

@Override
protected void onResume() {
    super.onResume();

    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 button = (Button) findViewById(R.id.change_default_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);
    }
}

}

代码本身非常简单,但我无法访问 Telephony.Sms.getDefaultSmsPackage,因为它表示无法解析 Telephony,并且我找不到任何可以解决此问题的导入或声明。

有人可以帮忙吗?

最佳答案

android.provider.Telephony 根本还不存在(从 API 18 - 4.3 开始)。

该类将在 4.4(大概是 API 19)中添加,该博客文章强调了新 API 发布后您应该进行的更改,这样到时候您就不会感到惊讶。

从帖子末尾开始:

To help you make the changes, we'll soon be providing the necessary SDK components for Android 4.4 that allow you to compile and test your changes on Android 4.4.

不要忘记您应该将此代码包装在 API 版本检查中,这样您就不会遇到没有此类的旧版本的问题。

关于android - 为 Android KitKat 准备 SMS 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19523968/

相关文章:

android - 我需要将广播与警报管理器一起使用吗?

android - 什么是 Android Play 服务 SDK 级别?

android - 如何判断Android源代码的版本?

android - 一个 Activity 在不同安卓版本上的奇怪行为 : map blinks

android - 更新 android simplecursoradapter 游标

android - gradle版本和gradle构建工具版本之间的关系

c# - Twilio 语音转录替换

android - 电话 TextBasedSmsColumns Date_Sent 基于时间

java - 使用 Intent 向多个联系人发送消息

android - Android应用程序在不同Android版本之间的兼容性