2015-12-15 2 views
0

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

@Override 
protected void onHandleIntent(Intent intent) { 

    Bitmap remote_picture = null; 
    long when = System.currentTimeMillis(); 
    int icon = getNotificationIcon(); 
    Bundle gcmData = intent.getExtras(); 
    Random random = new Random(); 
    int count = random.nextInt(9999 - 1000) + 1000; 

    if (intent.getExtras().getString("price") != null && intent.getExtras().getString("img") != null) { 

     NotificationCompat.BigPictureStyle notiStyle = new NotificationCompat.BigPictureStyle(); 
     notiStyle.setSummaryText(intent.getExtras().getString("price")); 

     try { 
      remote_picture = BitmapFactory.decodeStream((InputStream) new URL(intent.getExtras().getString("img")).getContent()); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     notiStyle.bigPicture(remote_picture); 
     NotificationManager notificationManager = (NotificationManager) this 
       .getSystemService(Context.NOTIFICATION_SERVICE); 
     PendingIntent contentIntent = null; 

     Intent gotoIntent = new Intent(); 

     gotoIntent.setClassName(this, "com.vspf.LoginCheckActivity"); 

     contentIntent = PendingIntent.getActivity(this, 
       (int) (Math.random() * 100), gotoIntent, 
       PendingIntent.FLAG_UPDATE_CURRENT); 

     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); 

     Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo1); 

     Notification notification = mBuilder.setLargeIcon(bitmap) 
       .setTicker("VSPF") 
       .setWhen(0) 
       .setAutoCancel(true) 
       .setContentTitle("VSPF") 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(intent.getExtras().getString("price"))) 
       .setContentIntent(contentIntent) 
       .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
       .setContentText(intent.getExtras().getString("price")) 
       .setStyle(notiStyle) 
       .build(); 

     notification.flags = Notification.FLAG_AUTO_CANCEL; 
     count++; 
     notificationManager.notify(count, notification); 
    } 
} 

private int getNotificationIcon() { 
    boolean whiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
    return whiteIcon ? R.drawable.logo1 : R.drawable.logo1; 
} 

ответ

0

Попробуйте изменить код, как на примере ниже ...

Notification.Builder builder = new Notification.Builder(this.getApplicationContext()); 
      builder.setTicker("VSPF") 
      builder.setWhen(0) 
      builder.setAutoCancel(true) 
      builder.setContentTitle("VSPF") 
      builder.setContentIntent(contentIntent); 
      builder.setContentText(intent.getExtras().getString("price")) 
      builder.setStyle(notiStyle) 
      ...... 
      ...... 

Notification notification = builder.build(); 

notificationManager.notify(count, notification); 
+0

в этом случае я получил ошибку на builder.setStyle линии. –

+0

Я получаю уведомление, когда я устанавливаю smallicon для уведомления, но я не хочу маленькую иконку. Что я могу сделать в этом? –

+0

@chiragpatel Посмотрите эту ссылку, я думаю, решите ваш вопрос .. http://stackoverflow.com/questions/16170648/android-notification-builder-show-a-notification-without-icon –

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