Получать уведомления, когда товар добавлен в переработку - PullRequest
1 голос
/ 06 ноября 2019

Как получить уведомление, когда предмет добавлен в переработчик?

@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {

    final OrdersData order = mUsers.get(position);
    final String client_Id = order.getClient_id();
    title = order.getItems();
    text = order.getF_name();
    holder.title.setText(order.getItems());
    holder.subtitle.setText(order.getF_name());
    holder.timeStamp.setText(order.getDateStamp());
    holder.address.setText(order.getAddress());
    String no = String.valueOf(position);
    holder.orderNo.setText(no);

}

1 Ответ

0 голосов
/ 06 ноября 2019

Существуют различные способы создания локального уведомления. В вашем случае я рекомендую самый простой способ. Просто вызвав функцию buildLocalNotification () прямо перед тем, как добавить данные в RecyclerView , а затем уведомить данные, измененные в RecyclerView .

  private void buildLocalNotification(String title, String message) {

        Intent intent = new Intent(getApplicationContext(), BaseActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0 /* Request code */, intent,
                PendingIntent.FLAG_ONE_SHOT);

        String channelId = getString(R.string.default_notification_channel_id);
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        NotificationCompat.Builder notificationBuilder =
                new NotificationCompat.Builder(this, channelId)
                        .setSmallIcon(R.drawable.ic_push_notification)
                        .setSound(defaultSoundUri)
                        .setContentTitle(title)
                        .setContentText(message)
                        .setAutoCancel(true)
                        .setContentIntent(pendingIntent);

        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);


        /**
         * Since Android Oreo
         */

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            createNotificationChannel(channelId, notificationManager);

        }

        assert notificationManager != null;
        notificationManager.notify((int) System.currentTimeMillis(), notificationBuilder.build());
    }

    @SuppressLint("NewApi")
    public void createNotificationChannel(String channelId, NotificationManager notificationManager) {


        @SuppressLint("WrongConstant")
        NotificationChannel channel = new NotificationChannel(channelId, getString(R.string.app_name),
                NotificationManager.IMPORTANCE_MAX);
        AudioAttributes att = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build();
        assert notificationManager != null;
        if (AppConstants.DEFAULT_NOTIFICATION_SOUND_URI != null) {
            channel.setSound(AppConstants.DEFAULT_NOTIFICATION_SOUND_URI, att);
        }
        channel.setLightColor(Color.parseColor("#F1E605"));
        channel.setVibrationPattern(VIBRATE_PATTERN);
        channel.canShowBadge();
        channel.enableVibration(true);
        notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(channel);

    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...