2016-04-26 19 views
2

通知を受け取ったときに音、振動または光が聞こえません。誰かが私に行方不明を教えてもらえますか?アプリが開いているとき、私は唯一の指定されたアイコンを取得Android:プッシュ通知に音/バイブレーション/ライトがありません

1):

また、私はいくつかの他の質問があります。アプリが閉じられるとアンドロイドのロゴアイコンが表示されます(まだアプリアイコンが定義されていないので、それは私が推測します)。

2.)テロップのテキストは、アプリが開いているときにのみ表示されます。

3.)アプリが開いているときは、コンテンツのテキストのみが表示されますが、コンテンツのタイトルは表示されません。

解決策:これは、以前のバージョンよりcom.google.android.gms:play-services-gcm:8.4.0を使用しているために発生します。

サーバー上で、キー配列と値のペアe = 0のみを含む通知配列を送信している間は、データ配列にメッセージ情報を送信してください。

この問題は既にここに偉大な答えがあります。これは私のソースですAfter updating Google play services to 8.4.0 push notifications displayed by themselves

を:

public class MyGcmListenerService extends GcmListenerService { 

    private final static String TAG = "GCM_Listener"; 

    @Override 
    public void onMessageReceived(String from, Bundle data) { 
     String message = data.getString("message"); 
     Log.d(TAG, "From: " + from + " (" + message); 

     // Sets an ID for the notification 
     SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.sharedPreferenceStore_default), Context.MODE_PRIVATE); 

     int mNotificationId = sharedPreferences.getInt("id_notification", 0); 
     mNotificationId++; 

     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         .setSmallIcon(R.drawable.all_picks_made_indicator) 
         .setAutoCancel(true) 
         .setContentTitle("Product - " + mNotificationId) 
         .setContentText(message) 
         .setTicker("Product Notification received"); 



     // Because clicking the notification opens a new ("special") activity, there's no need to create an artificial back stack. 
     PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DetectLoginActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); 
     mBuilder.setContentIntent(resultPendingIntent); 

     // Gets an instance of the NotificationManager service 
     NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     // Builds the notification and issues it. 
     Notification notification = mBuilder.build(); 
     notification.defaults = Notification.DEFAULT_ALL; 
     mNotifyMgr.notify(mNotificationId, notification); 

     SharedPreferences.Editor editor = sharedPreferences.edit(); 
     editor.putInt("id_notification", mNotificationId); 
     editor.commit(); 
    } 
} 

答えて

2

カスタムサウンド。

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.pop); 
notification.defaults |= Notification.DEFAULT_VIBRATE; 
+1

ありがとうございました! – Markus

+0

私はアプリを殺したとき、振動のないプッシュ通知を受け取りました。他の状況では通知に振動があります。誰でもその理由を知っていますか? – nAkhmedov

0
mBuilder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}); 
mBuilder.setLights(getResources().getColor(R.color.mainColor), 1000, 1000); 

あなたは色を設定し、あなたがしている

+1

音のための同様の方法 – kimchibooty

+0

私はnotification.defaults = Notification.DEFAULT_ALL;すでに – Markus

0

ビルダーオブジェクト上で振動することができますこのようなものがありません:

long[] pattern = new long[]{0, 100, 200, 100}; //two short beeps 
mBuilder.setVibrate(pattern); 
Notification note = mBuilder.build(); 
note.vibrate = pattern; 

それはあなたに振動を与えるでしょう。ライトを見て、私はatmでそのコードを持っていません。あなたのコードの変更

Notification notification = mBuilder.build(); 
    notification.defaults = Notification.DEFAULT_ALL; 
    mNotifyMgr.notify(mNotificationId, notification); 

にプッシュ通知

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.pop); 

ため

+0

私はnotification.defaults = Notification.DEFAULT_ALLを持っています。既に。最初にビルダークラスで振動を指定してから、公共の変数 – Markus

+0

を使って再度設定することはできません。DEFAULT_ALLオプションには含まれていません。実際の解決策から私に話をする前に、ドキュメントをお読みください。その議論。 – Shark

+0

ドキュメント(http://developer.android.com/reference/android/app/Notification.html)では、DEFAULT_ALLはデフォルトの振動、光、および音を使用すると記載されています。 – Markus

関連する問題