user2681199
user2681199

Reputation: 3

PendingIntent not sending broadcast

The sendBroadcast in onCreate is working but the pendingIntent is not sending the broadcast at the specific time.

I checked the time in the log and it is okay. Dont know why the PendingIntent is not working. Please help.

public class MainActivity extends Activity {

Intent intent;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    intent = new Intent();
    intent.setAction("Broadcast");
    sendBroadcast(intent);
}

public void onClick(View v){

    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(System.currentTimeMillis());
    c.add(Calendar.MINUTE, 1);      

    AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, 0);
    mgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, c.getTimeInMillis() , pi);

    Log.v("system current",""+System.currentTimeMillis());
    Log.v("calender",""+c.getTimeInMillis());
}

}

Upvotes: 0

Views: 860

Answers (1)

Shakeeb Ayaz
Shakeeb Ayaz

Reputation: 6096

you should try using try using mgr.set(AlarmManager.RTC, c.getTimeInMillis() , pi);

Upvotes: 1

Related Questions