gpt4 book ai didi

android - 为 Android KitKat 准备短信应用

转载 作者:行者123 更新时间:2023-11-29 00:25:52 25 4
gpt4 key购买 nike

同意 Android 开发人员最近的帖子 http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html ,我正在尝试为新的 Android 版本准备我的应用程序,但在他们建议创建对话框以让用户将应用程序设置为默认应用程序来处理 SMS 的部分遇到问题:

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 准备短信应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19523968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com