我希望有人可以帮助阐明这一点。我有这个代码适用于API版本10.但是,当我切换到API 16时,第一个组件被加载,但第二个组件抛出一个异常,它在应用程序中不存在。
除了API的更改外,没有任何变化。有人可以对此有所了解吗? 我一直在搜索,还没有碰到过任何东西。
谢谢!
/***************************************************
* INITIATE THE BROADCAST RECEIVERS
**************************************************/
//create reference to the package manager and required receivers
PackageManager pm = getApplicationContext().getPackageManager();
ComponentName BroadcastReceiver_Text =
new ComponentName(this, TextMessageReceiver.class.getName());
ComponentName BroadcastReceiver_Phone =
new ComponentName(this, PhoneCallReceiver.class.getName());
//turn ON the broadcast receivers for the texting
try {
pm.setComponentEnabledSetting(BroadcastReceiver_Text,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Log.i("Broadcast Receiver for Text", "Is Now ENABLED");
//turn ON the broadcast receivers for the phone calls
pm.setComponentEnabledSetting(BroadcastReceiver_Phone,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
Log.i("Phone Receiver for Text", "Is Now ENABLED");
}catch(Exception e){
Log.i("NameNotFoundException", e.getMessage());
}
Log.i("AwayModeService", "OnCreate Ending");
}