2017-07-26 7 views
0

Androidスタジオにメインアクティビティにボタンがある簡単な通知デモを書いています。クリックすると、クリックすると別のアクティビティにつながる通知が表示されます。私は通知objを設定しているが、振動はありません。パターンがオフかどうかはわかりません。通知は振動しません

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

} 

答えて

0

マニフェストに振動の許可があることを確認してください。

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

サイドノート:Android Mでは、これを実行時にリクエストする必要はありませんが、通常の許可です。

通常のアクセス許可の詳細については、hereをご覧ください。

+0

せずに、私は通知がなされたとき – reallenliu

+0

@reallenliuはあなたでし無振動ではなく、まだその許可を入れ、原因モバイルがケーブルに接続され、振動が無視されるという事実であることができますそれをマニフェストの間違った場所に置いたのですか?私はこれまでに多くの問題を抱えていました。 – JediBurrell

0

これは、ケーブルテスト

関連する問題