android通知将不会运行。通知
我正在尝试发送一个android通知,但在mbuilder.build部分一直失败。我有一个警报对话框后,在相同的方法。我在下面张贴我的代码android通知将不会运行。通知,android,android-notifications,Android,Android Notifications,我正在尝试发送一个android通知,但在mbuilder.build部分一直失败。我有一个警报对话框后,在相同的方法。我在下面张贴我的代码 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.noteiconcon) .setContentTitle("Finished search") .setContentT
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.noteiconcon)
.setContentTitle("Finished search")
.setContentText("We found your account");
System.out.println("failed after setText");
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainActivity.class);
System.out.println("failed after result intent");
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
System.out.println("taskstackbuilder passed");
stackBuilder.addParentStack(MainActivity.class);
System.out.println("stackbuilder.appParentstack passed");
stackbuilder.addNextIntent(resultIntent);
System.out.println("stackbuilder.addnextintent passed");
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
System.out.println("pending intent passed");
mBuilder.setContentIntent(resultPendingIntent);
System.out.println("mbuilder.setcontentintent passed");
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
System.out.println("notification manager passed");
// mId allows you to update the notification later on.
mNotificationManager.notify(mId,mBuilder.build());
System.out.println("notificationManager.notify passed"+ mId);
我已经添加了元数据任务,但是日志猫说
Bogus static initialization, type 4 in field type Landroid/support/v4/app/NotificationCompat$NotificationCompatImpl; for Landroid/support/v4/app/NotificationCompat; at index 1
就像我说的,我添加了元数据标签,在一个警报对话框之后,它在一个asychtask中被调用。我已经注释掉了警报对话框,但它仍然有效
如果我删除最后一行。notify它不会崩溃,但显然不会发送通知。我必须使用另一种通知方法,然后它接受了通知
// Set the icon, scrolling text and timestamp
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String MyText = "Finished searching";
Notification mNotification = new Notification(R.drawable.passicon, MyText, System.currentTimeMillis() );
//The three parameters are: 1. an icon, 2. a title, 3. time when the notification appears
String MyNotificationTitle = "Finished Searching";
String MyNotificationText = "We can't find your password.";
Intent MyIntent = new Intent(this, MainActivity.class);
PendingIntent StartIntent = PendingIntent.getActivity(getApplicationContext(),0,MyIntent, PendingIntent.FLAG_CANCEL_CURRENT);
//A PendingIntent will be fired when the notification is clicked. The FLAG_CANCEL_CURRENT flag cancels the pendingintent
mNotification.setLatestEventInfo(getApplicationContext(), MyNotificationTitle, MyNotificationText, StartIntent);
int NOTIFICATION_ID = 1;
notificationManager.notify(NOTIFICATION_ID , mNotification);
//We are passing the notification to the NotificationManager with a unique id.
您的设备是否在自定义ROM上?如果是,哪一个?不,不是。很有趣。安卓的哪个版本?哪种设备?索尼xperia z1和4.4您还有其他设备可以在上面试用此代码吗?对我来说,这个错误听起来像是试图用其他类型(如int)初始化NotificationCompatImpl字段,这是不应该发生的。如果你手头有存货,可能值得向索尼/谷歌提交一份bug报告。不过,最好在KitKat的最新版本上试用,我认为它是4.4.4。我的SGS3上至少有4.4.2。请显示新代码。至少是新的通知方式。