接收到通知時,我沒有聽到聲音,振動或光線。有人能告訴我我錯過了什麼嗎?Android:推送通知沒有聲音/振動/光線
我也有一些其他問題:
1)我只得到指定的圖標時,應用程序打開。當應用程序關閉時,我得到了android徽標圖標(我想這是因爲我還沒有定義應用程序圖標)。
2.)股票代碼文本僅在應用程序打開時顯示。
3.)當應用程序打開時,我沒有得到內容文本,只有內容標題。
SOLUTION:發生這種情況是因爲我在以前的版本中使用了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();
}
}
非常感謝! – Markus
當我殺了一個應用程序,然後收到推送通知沒有振動。在其他情況下,通知有振動。任何人都知道原因? – nAkhmedov