1

Прежде всего, я бы прочитал много ответов об этой проблеме, Я хочу установить 5 будильников, но с разным временем проблема является последней, которая переопределяет остальных, поэтому я вижу последний только, Я попытался изменить код запроса PendingIntent, чтобы сделать его уникальным, но проблемы все еще такие: Я переписал код много раз, но тот же результат, Я попытался сделать один метод для всех аварийные сигналы и изменение кода запроса, но не используются, также я попытался сделать разные методы для каждого сигнала тревоги с уникальными кодами запросов, но все же последний аварийный сигнал отменяет остальные, вот мой код для двух методов в качестве примера:
Примечание: переменные, которые я есть fajrMillis, dhuhrMillis:
являются миллисекунды, которые превращаются в календарь, чтобы установить время в
fajrMessage, dhuhrMessage: струнные сообщения, которые будут отправлены в класс приемника к уведомлению в нем
Вызов два метода:
android Установка нескольких сигналов тревоги

setFajrAlarm(fajrMillis, 1, fajrMessage); 
 
setDhuhrAlarm(dhuhrMillis, 2, dhuhrMessage);

public void setFajrAlarm(long millis, int id, String message) { 
 
\t \t Calendar c = Calendar.getInstance(); 
 
\t \t c.setTimeInMillis(millis); 
 
\t \t PrayersReceiver.notificationId = id;// 1 
 
\t \t PrayersReceiver.notificationMessage = message;// "حان الآن موعد صلاة الفجر" 
 
\t \t Intent intent = new Intent(getBaseContext(), PrayersReceiver.class); 
 
\t \t PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 1, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); 
 
\t \t AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
 
\t \t alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
 
\t \t \t \t c.getTimeInMillis(),30000, pendingIntent); 
 

 
\t } 
 

 
\t public void setDhuhrAlarm(long millis, int id, String message) { 
 
\t \t Calendar c = Calendar.getInstance(); 
 
\t \t c.setTimeInMillis(millis); 
 
\t \t PrayersReceiver.notificationId = id;// 1 
 
\t \t PrayersReceiver.notificationMessage = message;// "حان الآن موعد صلاة الظهر 
 
\t \t Intent intent = new Intent(getBaseContext(), PrayersReceiver.class); 
 
\t \t PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 2, intent, PendingIntent.FLAG_UPDATE_CURRENT | Intent.FILL_IN_DATA); 
 
\t \t AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
 
\t \t alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, 
 
\t \t \t \t c.getTimeInMillis(), 5000, pendingIntent); 
 
    
 
\t } 
 

 
//---------------------------------------------------------------------------------


Приемник класса

package com.prayers; 
 

 
import android.app.NotificationManager; 
 
import android.content.BroadcastReceiver; 
 
import android.content.Context; 
 
import android.content.Intent; 
 
import android.support.v4.app.NotificationCompat; 
 
import android.widget.Toast; 
 

 
public class PrayersReceiver extends BroadcastReceiver { 
 

 
\t public static String notificationMessage = ""; 
 
\t public static int notificationId ; 
 

 
\t @Override 
 
\t public void onReceive(Context context, Intent intent) { 
 
\t \t // TODO Auto-generated method stub 
 
\t \t Toast.makeText(context, "Time For Prayer", 3000).show(); 
 

 
\t \t // ----------------- 
 
\t \t // --------------Notification Part--------------------------- 
 
\t \t NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
 
\t \t \t \t context).setSmallIcon(R.drawable.ic_launcher) 
 
\t \t \t \t .setContentTitle("حان الآن موعد الصلاة") 
 
\t \t \t \t .setContentText(notificationMessage); 
 

 
\t \t NotificationManager mNotificationManager = (NotificationManager) context 
 
\t \t \t \t .getSystemService(Context.NOTIFICATION_SERVICE); 
 
\t \t mNotificationManager.notify(notificationId, mBuilder.build()); 
 
\t } 
 

 
}


Заранее спасибо, надеюсь получить ответы в ближайшее время

ответ

0

я знал ответ, так что если кто сталкивается с этой проблемой для получения решения: Я устанавливал значения переменных в rec eiver класс, так что последний вызов метода отменяет предыдущие вызовы:

PrayersReceiver.notificationId = id; 
 
PrayersReceiver.notificationMessage = message;

проблема была в этих двух линий в теле метода: поэтому удалось решить путем:

Intent intent = new Intent(getBaseContext(), PrayersReceiver.class); 
 
intent.putExtra("notificationId", id); 
 
intent.putExtra("notificationMessage", message);

и в приемной класс Iver получить два значения:

Bundle bundle = intent.getExtras(); 
 
if (bundle == null) { 
 
    Log.i("PrayersReceiver", "bundle is null"); 
 
\t return; 
 
\t \t } 
 

 
notificationId = bundle.getInt("notificationId"); 
 
notificationMessage = bundle.getString("notificationMessage");