How to do this in my project? I have Broadcast Receiver like this one
public class AlarmManagerBroadcastReceiver extends BroadcastReceiver {
public AlarmManagerBroadcastReceiver(){
}
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Receiveds", Toast.LENGTH_LONG).show();
ActivityReminderBaru.sendingpush();
}
}
and I set the sendingpush() in my activity like this one
public class ActivityReminderBaru extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reminder_baru);
}
public void sendingpush() {
Intent intentnotif = new Intent(this, UserActivity.class);
intentnotif.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intentnotif,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Staf Operasi 13")
.setContentText(KeteranganHolder + TanggalHolder + WaktuHolder)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
the question is, how to call sendingpush(); from my activity to broadcast receiver? if I run this code it work perfect, but when the broadcast receiver come up it gives me an error like this one
Error:(16, 29) error: non-static method sendingpush() cannot be referenced from a static context
please help me to fix my code, thanks