如何通过API设置重复通知?

时间:2019-07-25 09:17:16

标签: android android-notifications

因此,有一个API可以加载最近的电影,根据当天的最新电影数量,显示多少通知需要采取什么步骤?

我了解您需要一个显示通知的渠道,但是如何使它们从API中显示呢?首先猜测是来自RecyclerView之类的

API应该加载电影的标题和内容,并且这些标题和内容应显示在通知中

public class NotificationHelper extends ContextWrapper {

public static String CHANNEL_ID = "channel_01";
public static CharSequence CHANNEL_NAME = "dicoding channel";
private NotificationManager notificationManager;
private NotificationChannel channel;

public NotificationHelper(Context base) {
    super(base);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createChannels();
    }
}

@TargetApi(Build.VERSION_CODES.O)
public void createChannels() {

    channel = new NotificationChannel(CHANNEL_ID,
            CHANNEL_NAME,
            NotificationManager.IMPORTANCE_DEFAULT);
    channel.enableVibration(true);
    channel.enableLights(true);
    channel.setLockscreenVisibility(MODE_PRIVATE);

    if (notificationManager != null) {
        getNotificationManager().createNotificationChannel(channel);
    }
}

public NotificationManager getNotificationManager() {
    if (notificationManager == null) {
        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    }
    return notificationManager;
}

public NotificationCompat.Builder getChannelNotification() {
    return new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID)
            .setContentTitle("Film Tv")
            .setContentText("Hey, cek katalog movie kamu sekarang!")
            .setSmallIcon(android.R.drawable.sym_def_app_icon);

    }
}

编辑添加了一些代码

您如何做到的?

0 个答案:

没有答案