2017-09-06 19 views
0

通知機能をアプリケーションに追加して、通知LEDを点滅させようとしています。何も動作すべての私の試みの後...Android - LED通知が点滅しない

はここに私のコードです:誰が助けることができれば

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this) 
      .setLights(Color.BLUE, 200, 200) 
      .setContentTitle(remoteMessage.getData().get("title")) 
      .setContentText(remoteMessage.getData().get("body")) 
      .setColor(getColor(R.color.buttonBlueInactive)) 
      .setSmallIcon(R.mipmap.ic_launcher); 
    NotificationManagerCompat manager = NotificationManagerCompat.from(this); 
    manager.notify(1, notification.build()); 
} 

、それは本当にいただければ幸いです。私は間違っていないよ場合は、

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this) 
      .setLights(Color.BLUE, 200, 200) 
      // Add the line bellow 
      .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS) 
      .setContentTitle(remoteMessage.getData().get("title")) 
      .setContentText(remoteMessage.getData().get("body")) 
      .setColor(getColor(R.color.buttonBlueInactive)) 
      .setSmallIcon(R.mipmap.ic_launcher); 
    NotificationManagerCompat manager = NotificationManagerCompat.from(this); 
    manager.notify(1, notification.build()); 
} 
+0

を200から2000だけを変更するかどうかをテストする。 – W0rmH0le

+0

ちょうどそれを試みたが、それは動作しなかった.. –

+0

Ok。あなたは少なくとも、通知を得ていますよね?ちょうど点滅していないLEDだけ? – W0rmH0le

答えて

0

オプション1

:私が持っていた同じ問題を持っている人のためのソリューション

は、解決策があります紛失していますsetDefaults()

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 
    NotificationCompat.Builder notification = new NotificationCompat.Builder(this) 
      .setLights(Color.BLUE, 200, 200) 
      .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS) // Add this line 
      .setContentTitle(remoteMessage.getData().get("title")) 
      .setContentText(remoteMessage.getData().get("body")) 
      .setColor(getColor(R.color.buttonBlueInactive)) 
      .setSmallIcon(R.mipmap.ic_launcher); 
    NotificationManagerCompat manager = NotificationManagerCompat.from(this); 
    manager.notify(1, notification.build()); 
} 
上記の例では3210

、私は次のオプションを追加しました:

Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS 

あなたはあなたの必要性に応じて変更することもできます。さらに詳しい情報:

Android DOC

オプション2

上記の例は動作しない場合は、下記のコード試してください:テストのためのタイマーを増やすようにしてください...からの変更を

@Override 
public void onMessageReceived(RemoteMessage remoteMessage) { 
    super.onMessageReceived(remoteMessage); 

    NotificationCompat.Builder notification = new NotificationCompat.Builder(this) 
      .setLights(Color.BLUE, 200, 200) 
      .setContentTitle(remoteMessage.getData().get("title")) 
      .setContentText(remoteMessage.getData().get("body")) 
      .setColor(getColor(R.color.buttonBlueInactive)) 
      .setSmallIcon(R.mipmap.ic_launcher); 

    Notification builtNotification = notification.build(); 
    builtNotification.flags |= Notification.FLAG_SHOW_LIGHTS; 

    NotificationManagerCompat manager = NotificationManagerCompat.from(this); 
    manager.notify(1, builtNotification); 
} 
+0

私と結婚しますか?私はちょうどそれを修正しようと一日を費やした!どうもありがとうございます ! –

+0

お役立ち情報...上記のコードのどれがあなたのために働いたのか教えてください。ちょうど今後の参考に... – W0rmH0le

+0

これは最初のものです –

関連する問題