与 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 无法解析,而且我找不到任何可以解决此问题的导入或声明。
有人可以帮忙吗?