0

在我的应用程序中,我有一个启动接收器,所以当设备重新启动时,我想唤醒另一个接收器。所以请帮助我。下面是我的代码:

public class BootUpReciever extends BroadcastReceiver{

Context context;
SharedPreferences settings;
SmsManager smsMgr = SmsManager.getDefault();
public static final String PREFS_NAME = "MyPrefsFile";

@Override
public void onReceive(Context context, Intent intent) {

    Intent sms = new Intent(context, SMSReceiver.class);
    sms.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(sms);

    Intent netAvailability = new Intent(context, CheckingNetworkAvailability.class);
    netAvailability.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(netAvailability); 
}    }

这里 SMSReceiver.class 和 heckingNetworkAvailability.class 是我的接收者。我做错了什么吗。

4

1 回答 1

0

现在我正在使用包管理器并且它工作正常:)

@Override
public void onReceive(final Context context, Intent intent) {

    ComponentName sms = new ComponentName(context, SMSReceiver.class);
    context.getPackageManager().setComponentEnabledSetting(sms, 
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);

    ComponentName net = new ComponentName(context, CheckingNetworkAvailability.class);
    context.getPackageManager().setComponentEnabledSetting(net, 
            PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}
于 2012-12-08T03:27:45.270 回答