【发布时间】:2013-10-22 16:58:18
【问题描述】:
与 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 sms android-version android-4.4-kitkat