【问题标题】:Open an specific link with push notification android打开带有推送通知android的特定链接
【发布时间】:2020-10-11 17:37:46
【问题描述】:

以下代码是每次应用程序有新更新时显示的推送通知代码。

如何配置点击通知打开 PlayStore 窗口?也就是一个链接。

是否应该修改意图?

public static class NotificationServiceNuevaActualizacion extends IntentService {

        private NotificationManager notificationManager;
        private PendingIntent pendingIntent;
        private int NOTIFICATION_ID = 4;
        Notification notification;

        public NotificationServiceNuevaActualizacion(String name) {
            super(name);
        }

        public NotificationServiceNuevaActualizacion() {
            super("SERVICE");
        }

        @TargetApi(Build.VERSION_CODES.O)
        @Override
        protected void onHandleIntent(Intent intent2) {
            String NOTIFICATION_CHANNEL_ID = getApplicationContext().getString(R.string.app_name);
            Context context = this.getApplicationContext();
            notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            Intent mIntent = new Intent(this, Principal.class);
            Resources res = this.getResources();
            Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);

            String message = "New update";

            if (SDK_INT >= Build.VERSION_CODES.O) {
                final int NOTIFY_ID = 0; // ID of notification
                String id = NOTIFICATION_CHANNEL_ID; // default_channel_id
                String title = NOTIFICATION_CHANNEL_ID; // Default Channel
                PendingIntent pendingIntent;
                NotificationCompat.Builder builder;
                NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                if (notifManager == null) {
                    notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                }
                int importance = NotificationManager.IMPORTANCE_HIGH;
                NotificationChannel mChannel = notifManager.getNotificationChannel(id);
                if (mChannel == null) {
                    mChannel = new NotificationChannel(id, title, importance);
                    mChannel.enableVibration(true);
                    mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                    notifManager.createNotificationChannel(mChannel);
                }
                builder = new NotificationCompat.Builder(context, id);
                mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                pendingIntent = PendingIntent.getActivity(context, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                builder.setContentTitle(getString(R.string.app_name)).setCategory(Notification.CATEGORY_SERVICE)
                        .setSmallIcon(R.drawable.logo_utn)   // required
                        .setContentText(message)
                        .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.icono))
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setAutoCancel(true)
                        .setSound(soundUri)

                        .setContentIntent(pendingIntent)
                        .setVibrate(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                Notification notification = builder.build();
                notifManager.notify(NOTIFY_ID, notification);

                startForeground(3, notification);
            }
        }
    }

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    您必须更改这行代码:

    Intent mIntent = new Intent(this, Principal.class);
    

    为此并将%APP_ID% 替换为特定的应用程序ID:

    Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=%APP_ID%"));
    

    您可以在此处找到更多详细信息:https://developer.android.com/distribute/marketing-tools/linking-to-google-play

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2021-11-27
      • 2015-12-29
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多