我使用以下代碼添加通知,並在通知中添加了兩個功能,一個是聲音,另一個是閃爍的燈光。通知聲音停止點擊
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.cutomnotification);
contentView.setTextViewText(R.id.textView1,"Custom");
notification.contentView = contentView;
Intent notificationIntent = new Intent(v.getContext(), MyClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(v.getContext(), 0, notificationIntent, 0);
notification.contentIntent = contentIntent;
notification.sound=android.provider.Settings.System.DEFAULT_RINGTONE_URI;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags=Notification.FLAG_INSISTENT|Notification.FLAG_SHOW_LIGHTS|Notification.FLAG_NO_CLEAR;
mNotificationManager.notify(HELLO_ID, notification);
在此我也使用了自定義佈局,
現在我有兩個問題,
1)的聲音響起,當用戶點擊通知選項卡上它停了,但我想繼續聲音直到用戶按下自定義佈局上的任何按鈕。
2)我在自定義佈局中添加一個按鈕,現在我可以在其上實現onClickListener()。
嘿有人在android中使用通知,請給我一些建議。 –
可以請任何人給我答案 –