Уведомление только о звуке звонка (без отображения фактического уведомления)

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

@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;
}

person chirag patel    schedule 15.12.2015    source источник


Ответы (1)


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

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);
person Nikos Mitropoulos    schedule 15.12.2015
comment
Я получаю уведомление, когда я устанавливаю smallicon для уведомления, но мне не нужен маленький значок. Что я могу сделать в этом? - person chirag patel; 15.12.2015
comment
@chiragpatel См. эту ссылку, я думаю, решить ваш вопрос. построитель уведомлений показывает уведомление без значка"> stackoverflow.com/questions/16170648/ - person Nikos Mitropoulos; 15.12.2015