如何在BroadcastReceiver类中创建挂起的intent?

the*_*r22 4 android broadcastreceiver

我正在尝试在广播接收器内创建我的广播实习生,但我认为我没有为它输入正确的代码.待定实习生应该如何寻找广播接收器?我想发短信.并且需要等待发送它的意图.

Com*_*are 7

我正在尝试在广播接收器内创建我的广播实习生,但我认为我没有为它输入正确的代码.

它与其他任何东西都没有什么不同PendingIntent,除了你必须使用传入的Context对象,因为BroadcastReceiver它不是Context:

public void onReceive(Context ctxt, Intent incoming) {
    Intent i=new Intent(ctxt, OnAlarmReceiver.class);
    PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0));

    // do stuff with PendingIntent here
}
Run Code Online (Sandbox Code Playgroud)