3

我希望有人可以帮助阐明这一点。我有这段代码可以在 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");
}
4

0 回答 0