與Android Developers http://android-developers.blogspot.pt/2013/10/getting-your-sms-apps-ready-for-kitkat.html最近的帖子一致,我試圖準備我的應用程序到新的android版本,但遇到了一個問題,他們建議創建一個對話框讓用戶設置應用程序爲默認的應用程序來處理SMS的:準備安卓手機短信應用程序KitKat
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);
}
}
}
代碼本身非常簡單,b ut我無法訪問Telephony.Sms.getDefaultSmsPackage,因爲它表示Telephony無法解析,而且找不到可以解決該問題的任何導入或聲明。
任何人都可以請幫忙嗎?
是的,你是正確的!我只是錯過閱讀後的最後幾行.. = \!我還是謝謝你! – Pmsc