Java 在GcmListenerService中获取错误
有时在每个设备中都没有收到任何推送通知时出现此错误-可能是设备问题?? Android 5.0中最新的get崩溃 请帮忙 致命异常:java.lang.NullPointerException:尝试调用 null上的虚拟方法“java.lang.String java.lang.String.intern” 对象引用 在android.os.Parcel.readExceptionParcel.java:1556 位于android.os.Parcel.readExceptionParcel.java:1499 在android.app.ActivityManagerProxy.getIntentSenderActivityManagerNative.java:3740 在android.app.pendingent.getActivityEndingContent.java:291 在android.app.pendingent.getActivityEndingContent.java:252 在com.mystuc.Service.MyGcmListenerService.sendNotificationMyGcmListenerService.java:122 在com.mystuc.Service.MyGcmListenerService.onMessageReceivedMyGcmListenerService.java:82 位于com.google.android.gms.gcm.GcmListenerService.zzqUnknown来源 位于com.google.android.gms.gcm.GcmListenerService.zzpun已知来源 位于com.google.android.gms.gcm.GcmListenerService.zzoun已知来源 位于com.google.android.gms.gcm.GcmListenerService.zza未知来源 位于com.google.android.gms.gcm.GcmListenerService$1.run未知来源 位于java.util.concurrent.ThreadPoolExecutor.runWorkerThreadPoolExecutor.java:1112 位于java.util.concurrent.ThreadPoolExecutor$Worker.runThreadPoolExecutor.java:587 java:818 我正在使用以下代码:Java 在GcmListenerService中获取错误,java,android,google-cloud-messaging,Java,Android,Google Cloud Messaging,有时在每个设备中都没有收到任何推送通知时出现此错误-可能是设备问题?? Android 5.0中最新的get崩溃 请帮忙 致命异常:java.lang.NullPointerException:尝试调用 null上的虚拟方法“java.lang.String java.lang.String.intern” 对象引用 在android.os.Parcel.readExceptionParcel.java:1556 位于android.os.Parcel.readExceptionParcel.j
public class MyGcmListenerService extends GcmListenerService {
private static final String TAG = "MyGcmListenerService";
private Intent intent;
@Override
public void onMessageReceived(String from, Bundle data) {
Log.e("onMessageReceived", "onMessageReceived:" + data.toString());
Utils pref = Utils.getInstance(getApplicationContext());
String uid = pref.getString(Constants.uid, "");
if (uid.length() > 0) {
if (pref.getBoolean(Constants.isEnableNotification, false)) {
try {
String response = data.getString("data");
if (response != null) {
JSONObject jsonObject = new JSONObject(response);
if (jsonObject.has("stype")) {
String stype = jsonObject.getString("stype");
if (stype.equalsIgnoreCase("timeline")) {
String msg = jsonObject.getString("msg");
String post_type = jsonObject.getString("post_type");
String post_id;
String postDetails = "";
if (post_type.equalsIgnoreCase(Constants.PostType.Question)) {
post_id = jsonObject.getString("question_id");
} else {
post_id = jsonObject.getString("post_id");
try {
postDetails = jsonObject.getJSONArray("postDetail").getJSONObject(0).toString();
} catch (JSONException e) {
e.printStackTrace();
}
}
String post_tab = jsonObject.getString("post_tab");
String message = msg.trim();
if (post_type.equalsIgnoreCase(Constants.PostType.Question)) {
intent = new Intent(getApplicationContext(), QuestionView.class);
} else {
intent = new Intent(getApplicationContext(), FeedDetail_home.class);
}
intent.putExtra(Constants.fromTimeLineNotification, true);
intent.putExtra(Constants.posttype, post_type);
intent.putExtra(Constants.postid, post_id);
intent.putExtra(Constants.posttab, post_tab);
intent.putExtra(Constants.postDetailsJson, postDetails);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
sendNotification(message, intent);
}
} else {
String msg = jsonObject.getString("msg");
String sender = jsonObject.getString("sent_by");
String templeteid = jsonObject.getString("template_id");
String message = msg.trim();
Intent intent = new Intent(this, Home.class);
intent.putExtra(Constants.fromNotification, true);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
sendNotification(message, intent);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
sendBroadcast();
}
public void sendBroadcast() {
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(Constants.OnNotification));
}
private void sendNotification(String message, Intent intent) {
Bitmap icon = BitmapFactory.decodeResource(
MyGcmListenerService.this.getResources(),
R.drawable.app_icon);
final Intent notificationIntent = new Intent(this, Home.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
int color = getResources().getColor(R.color.colorPrimary);
Uri sound = Uri.parse("android.resource://com.mystuc/raw/coindrop");
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_smallnotify)
.setContentTitle("MyStuC")
.setContentText(message)
.setAutoCancel(true)
.setColor(color)
.setSound(sound)
.setLargeIcon(icon)
.setContentIntent(pendingIntent).setPriority(NotificationCompat.PRIORITY_MAX);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 , notificationBuilder.build());
}}
而不是给出0
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
请解释您的问题@Gurvinderi已经添加了更多细节,请检查。谢谢
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);