My application requirement is User can set multiple type reminder for same time, so at that time notification is pop up along with it's sound
My code is:
public class ReminderService extends Service {
int id;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(final Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
if (intent != null) {
new Thread() {
public void run() {
id = intent.getIntExtra("ID");
showNotification(id);
}
}.start();
}
}
Handler mHandler = new Handler();
public void showNotification(final int id) {
mHandler.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
Notification notification = new Notification(
R.drawable.icon, getString(R.string.app_name),
System.currentTimeMillis());
notification.sound = Uri.parse("android.resource://"
+ getPackageName() + "/" + R.raw.pluck_b);
Intent i = new Intent();
i.setClass(ReminderService.this, MyClass.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
notification.setLatestEventInfo(ReminderService.this,
getString(R.string.app_name), message,
PendingIntent.getActivity(ReminderService.this, 0,
i, 0));
NotificationManager nm = (NotificationManager) ReminderService.this
.getSystemService(Context.NOTIFICATION_SERVICE);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify((int) id, notification);
} catch (Exception e) {
}
}
});
}
}
Suppose user set 3 reminder for 10:30, so it will call 3 times this service, and 3 time different notification will call, so notification sound is also not proper as it create 3 different notification.
So now what have to do, I want to call single notification for these 3 different reminder using remote view, so sound will single.
But to create remote view how can I identify number of alarm at same time.
Please any one help me to identify best approaches, what I have to do in this case so notification sound would be single for different notification.
You could implement the Observer Pattern .
This sets up a one-to-many relationship between classes, which allows you to notify multiple classes from one event.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.