如何处理多个通知?

时间:2017-02-07 12:11:02

标签: java android push-notification notifications

根据通知编写应用程序,通知将数据写入SQLite。例如,将名称和日期作为字符串并使用AlarmManager DatePicker。但是,当我设置06.03和09.03的通知时,它只会在06.03收到通知。如何做到支持多个通知,如06和09?

public class Rachunki extends AppCompatActivity {
EditText name, surname;
Button btnAdd;
ListView lst;
DbCon dbcon;
DbCon.DbHelper dbHelper;
AlarmManager alarmManager;
DatePicker datePicker;

Button alarmON,okbtn;
EditText editprice,editname;
String minute_string;
String hour_string;

//public  EditText editName,editPrice ;



private PendingIntent pending_intent;

private TimePicker alarmTimePicker;
private static Rachunki inst;
private TextView alarmTextView;
int richard_quote = 0;
private AlarmReceiver alarm;
private Context context;


String year_string, month_string,day_string,date;
@TargetApi(Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rachunki);
    name = (EditText) findViewById(R.id.etNameR);
    surname = (EditText) findViewById(R.id.etSurnameR);
    btnAdd = (Button) findViewById(R.id.btnAddR);
    datePicker = (DatePicker)findViewById(R.id.datePickerR);
    alarmON = (Button) findViewById(R.id.alarm_onR);
    this.context = this;
    alarmTextView = (TextView) findViewById(R.id.update_textR);
     final Intent myIntent = new Intent(this.context, AlarmReceiver.class);
     alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    final java.util.Calendar calendar = java.util.Calendar.getInstance();

    dbcon=new DbCon(this);
  loadR();
    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                dbcon.insertS(name.getText().toString(), surname.getText().toString(),date.toString());
               loadR();
            } catch (Exception e) {

            }
        }
    });

         alarmON.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                calendar.set(Calendar.YEAR,datePicker.getYear());

                calendar.set(Calendar.MONTH,datePicker.getMonth());
                calendar.set(Calendar.DAY_OF_MONTH,datePicker.getDayOfMonth());

                final int year = datePicker.getYear();
                final int month = datePicker.getMonth();
                final int day = datePicker.getDayOfMonth();

                year_string= String.valueOf(year);
                month_string= String.valueOf(month);
                day_string = String.valueOf(day);

                if (month < 10) {
                   month_string= "0" + String.valueOf(month);
               }
                if ( day<10){
                 day_string="0"+String.valueOf(day);
               }
                date = day_strin

g+"-"+month_string+"-"+year;

                   myIntent.putExtra("extra", "yes");
                    myIntent.putExtra("quote id", String.valueOf(richard_quote));
                    pending_intent = PendingIntent.getBroadcast(Rachunki.this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending_intent);

                    setAlarmText(date );}
                }
            });




    }

    public void setAlarmText(String alarmText) {
        alarmTextView.setText(alarmText);
    }
    public void loadR() {
        Cursor cursor = null;
        try {
            dbcon.open();
            cursor = dbcon.readAllR();
        } catch (Exception e) {

        }
    }
}

public class AlarmReceiver extends BroadcastReceiver {
    DbCon dbcon;
    DbCon.DbHelper dbHelper;
    @Override
    public void onReceive(Context context, Intent intent) {
        String state = intent.getExtras().getString("extra"); Log.e("MyActivity", "In the receiver with " + state);
        String get_your_string=intent.getExtras().getString("extra");
        Log.e("What is the key",get_your_string);
        Intent service_intent = new Intent(context, RingtonePlayingServiceR.class);
        service_intent.putExtra("extra", get_your_string); context.startService(service_intent);
    }
}

0 个答案:

没有答案