您的位置:首页 > 其它

关于发送多条notifications所遇到的一些问题 2

2013-10-29 16:18 363 查看
NotificationManager mNotificationManager =(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent mIntent = new Intent(context, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				
mIntent.putExtra(TAG, GCM);
mIntent.putExtra(MESSAGE_ID, message_id);
mIntent.putExtra(TITLE, title);
mIntent.putExtra(TEXT, msg);
				
int requestID = (int) System.currentTimeMillis();
				
PendingIntent contentIntent = PendingIntent.getActivity(context, requestID, mIntent, PendingIntent.FLAG_ONE_SHOT);
				
				NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
				.setContentTitle(title)
				.setContentText(msg)
				.setSmallIcon(R.drawable.ic_launcher)
				.setAutoCancel(true)
				.setLights(Color.parseColor("#2E6AD7"), 5000, 5000)
				.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
				
				mBuilder.setContentIntent(contentIntent);
				
				SharedPreferences prefs = context.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
				int notifiId = prefs.getInt("notifiId_count", 0);
				notifiId = notifiId + 1;
				
				mNotificationManager.notify(notifiId,mBuilder.build());
				
				
				SharedPreferences.Editor editor = prefs.edit();
				editor.putInt("notifiId_count", notifiId);
				editor.commit();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: