Android 在多次成功收到通知后,它不再收到任何通知
我正在使用FCM服务将通知推送到我的应用程序。但是,当我为我的应用程序进行一些功能测试以确保所有功能都与通知一起正常工作时,设备(真实设备或模拟器)停止接收任何更多的通知,尽管我收到了“成功”发送通知。这意味着,在我发送了5个通知并与他们交互后,如果我再发送,我将无法再收到任何新的通知。 所以我的问题是:GetNotification函数(下面)中是否存在任何可能导致此问题的错误?还是来自安卓系统 [我甚至注意到,有时如果我关闭wifi并再次打开,我会收到本应发送到设备的丢失的通知(我100%确定在收到任何通知时我已连接到互联网)] 发送通知代码:Android 在多次成功收到通知后,它不再收到任何通知,android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,我正在使用FCM服务将通知推送到我的应用程序。但是,当我为我的应用程序进行一些功能测试以确保所有功能都与通知一起正常工作时,设备(真实设备或模拟器)停止接收任何更多的通知,尽管我收到了“成功”发送通知。这意味着,在我发送了5个通知并与他们交互后,如果我再发送,我将无法再收到任何新的通知。 所以我的问题是:GetNotification函数(下面)中是否存在任何可能导致此问题的错误?还是来自安卓系统 [我甚至注意到,有时如果我关闭wifi并再次打开,我会收到本应发送到设备的丢失的通知(我100%确
public void SendNotification(final Context context, String requestToken, final String serverKey, String fcmUrl, final Requests request)
{
String msg = "msg";
String title = "title";
JSONObject obj = null;
JSONObject objData = null;
try {
obj = new JSONObject();
objData = new JSONObject();
objData.put("body", msg);
objData.put("title", title);
obj.put("to", requestToken);
obj.put("notification", objData);
} catch (JSONException e)
{
e.printStackTrace();
}
JsonObjectRequest jsObjRequest =
new JsonObjectRequest(Request.Method.POST,fcmUrl, obj,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
Util.makeToast(context,"Success");
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Util.makeToast(context,"Fail");
}
})
{
@Override
public Map<String, String> getHeaders() throws AuthFailureError
{
Map<String, String> params = new HashMap<>();
params.put("Authorization", "key=" + serverKey);
params.put("Content-Type", "application/json");
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
int socketTimeout = 1000 * 60;// 60 seconds
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
jsObjRequest.setRetryPolicy(policy);
requestQueue.add(jsObjRequest);
}
GetNotification
方法看起来不错。在第一个调用的方法(断点)中检查调试是否接收到任何信息。请注意,当您向他们的服务器发出大量和频繁的请求时,谷歌服务可能会暂时禁止您-side@snachmsm是的,我之前检查过,我收到了信息。@snachmsm“注意,当你向他们的服务器端发出大量和频繁的请求时,谷歌服务可能会暂时禁止你”——你能告诉我这种行为的来源吗?我对GPS限制很好奇。没有来源,我是根据我自己的经验,在我第一次实现GCM(不久前)用于商业用途的过程中。发布的代码是好的,所以问题必须在中间某个地方(你说你是舒尔,你每次收到推送广播和<代码> GETNebug < /代码>也应该显示通知时间)
private void GetNotification(String messageTitle, String messageBody)
{
Intent intent = new Intent(this, MainController.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("serve","PLEASE");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 , intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(messageTitle)
.setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}