通知不会振动

时间:2017-07-26 02:56:07

标签: java android xml

我正在Android Studio中编写一个简单的通知演示,其中主要活动中有一个按钮,当您单击它时,会出现一个通知,导致另一个点击活动。我在通知obj上setVibrate但是没有振动。不确定图案是否关闭。

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());

}

2 个答案:

答案 0 :(得分:0)

确保您的清单中有振动许可。

<uses-permission android:name="android.permission.VIBRATE" />

附注:在Android M上,您不必在运行时请求此操作,这是正常的权限。

您可以阅读有关正常权限here的更多信息。

答案 1 :(得分:0)

这可能是因为移动设备连接到电缆,振动被忽略,没有电缆测试

相关问题