如何在Android上显示带有应用程序的锁屏消息?

时间:2016-11-02 13:00:20

标签: java android

Android提供了设置锁屏消息like this one的功能,我想知道如何通过应用程序执行此操作。

我找到并读了 this主题,我尝试了方法

Settings.System.putString(context.getContentResolver(), Settings.System.NEXT_ALARM_FORMATTED, "Test");

但它不起作用:“context”对象上的编译失败。

有人能帮帮我吗?

编辑:我在{gttp存储库中找到了owner info settings的java文件。不幸的是,我无法利用这些数据。如果有人可以帮助我,那将是件好事。感谢

2 个答案:

答案 0 :(得分:0)

//Generate Notification
public void sendNotifaction(String messagebody){

    Intent intent = new Intent(this,HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    //to generate more notification
    Random random = new Random();

    notifactionCode = random.nextInt(9999 - 1000) + 1000;

    PendingIntent pendingIntent = PendingIntent.getActivity(this,notifactionCode,intent,PendingIntent.FLAG_UPDATE_CURRENT);

    Uri defaultRingtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(this)
            .setWhen(System.currentTimeMillis())
            .setAutoCancel(true)
            .setSmallIcon(R.mipmap.logo)
            .setContentTitle("VIS")
            .setSound(defaultRingtone)
            .setContentIntent(pendingIntent)
            .setVibrate(new long[] {1000,1000})
            .setContentText(messagebody);


    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notificationManager.notify(notifactionCode,notificationCompat.build());


}

可能你想要这个,它也可以帮助你或者看看WAKE_CLOCK主题。

答案 1 :(得分:0)

生成通知是在锁屏上显示消息的最简单方法,但我知道这不是您想要做的。

不幸的是,我不认为您可以直接在应用程序的锁屏上显示消息,因为滥用的可能性太大。

想象一下,使用狡猾的应用程序显示促销信息!这就是通知被解雇的原因

相关问题