在android

时间:2016-06-12 10:59:13

标签: android android-notifications

我是android的新手。有人给我看详细代码,让我在一天中的特定时间显示应用程序?

如果您详细显示代码会更好。

我只知道使用本地通知。

code is here.

long = = Calendar.getInstance()。getTimeInMillis();             当+ = 10000;

        Intent intent = new Intent(getApplicationContext(),MainActivity.class);

        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(),1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
        long[] pattern = {500,500};

        NotificationCompat.Builder notification =
                (NotificationCompat.Builder) new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.notification1)
                        .setContentTitle("My notification")
                        .setContentText("Hello World!")
                        .setContentIntent(pendingIntent)
                        .setLights(Color.BLUE, 500, 500)
                        .setAutoCancel(true)
                        .setVibrate(pattern)
                        .setDefaults(Notification.DEFAULT_SOUND);

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

// mId允许您稍后更新通知。             mNotificationManager.notify(1,notification.build());

1 个答案:

答案 0 :(得分:2)

看看AlarmManager https://developer.android.com/reference/android/app/AlarmManager.html

AlarmManager允许您安排应用程序在将来某个时间运行