我在 android studio 中使用此代码 java 有问题 [关闭]

问题描述 投票:0回答:0

我在 android studio 中遇到此代码 java 的问题它有错误并且不起作用

 private static final int uniqueID = 555;

  public void createNotification() {
        // 1. Initialize the NotificationCompat.Builder object and set the channel ID
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "channel_id");

        // Make this notification automatically dismissed when the user touches it.
        builder.setAutoCancel(true);

        // 2. Set Notification properties, at least: small icon, title, text
        builder.setSmallIcon(R.drawable.img_1);
        builder.setContentTitle("Login Notification");
        builder.setContentText("You have been successfully authenticated by the game App");

        // Optional: Add a timestamp for the notification (usually the time the event occurred).
        builder.setWhen(System.currentTimeMillis());

        // Optional: Add an action to the notification
        Intent intent = new Intent(this, ps_store.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(pendingIntent); //intent for action to run when clicked

        // 3. Build notification and issue it
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        // 4. Post a notification to be shown in the status bar
        nm.notify(uniqueID, builder.build());
    }

我试过,我做不到,遇到了很多问题

java android xml android-layout app-store
© www.soinside.com 2019 - 2024. All rights reserved.