0
我正在Android Studio中編寫一個簡單的通知演示,其中主活動中有一個按鈕,當您單擊它時,會出現一條通知,導致點擊另一個活動。我在通知對象上設置了振動,但沒有振動。不確定模式是否關閉。通知不會振動
NotificationCompat.Builder notification;
private static final int id = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notification = new NotificationCompat.Builder(this);
notification.setAutoCancel(true);
}
public void notificationMethod(View v){
notification.setSmallIcon(R.mipmap.ic_launcher);
notification.setTicker("this is ticker");
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle("This is the Title");
notification.setContentText("This is the Text");
notification.setVibrate(new long[]{1000,1000,1000,1000,1000});
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pintent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setContentIntent(pintent);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(id, notification.build());
}
我把該權限的,但仍然沒有振動通知時作出 – reallenliu
@reallenliu莫非你把它放在艙單的錯誤區域?我曾經有過很多問題。 – JediBurrell