2014-08-30 4 views
0

Я пытаюсь отправить уведомление об андроиде, но он продолжает терпеть неудачу в части mbuilder.build(). У меня есть диалоговое окно с предупреждением сразу после того же метода. Я размещаю свой код нижеандроидные уведомления не будут выполняться .notify

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 после встревоженного диалога. Ive прокомментировал диалоговое окно предупреждения, но он все еще работает.

Если я опускаю последнюю строку .notify, она не падает, но, очевидно, не отправляет уведомление.

+0

Это устройство на заказном диске? Если да, то какой? –

+0

Нет, это не так. Его запас –

+0

Интересно. Какая версия Android? И какое устройство? –

ответ

0

Мне пришлось использовать другой метод уведомления, который затем принял уведомление.

 // 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. 
+0

Показать новый код, пожалуйста. По крайней мере новое уведомление mehtod. –

Смежные вопросы