【问题标题】:How can I display a lockscreen message with an application on Android?如何使用 Android 上的应用程序显示锁屏消息?
【发布时间】:2016-11-02 13:00:20
【问题描述】:

Android 提供了设置锁屏消息 的功能,我想知道如何通过应用程序来做到这一点。

我找到并阅读了 this话题,方法我试过了

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

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

有人可以帮帮我吗?

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

【问题讨论】:

  • 您是否尝试过像加载一样制作等待屏幕(进度条)???
  • 不,我没有,这怎么可能有用?

标签: java android


【解决方案1】:

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

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

想象一下,多变的应用程序会显示促销信息!这就是通知可以关闭的原因

【讨论】:

  • 感谢您的回答。我没有注意到这一点。因此,我认为我的项目无法实现:/。这真的无所谓。再次感谢。
【解决方案2】:
//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 主题。

【讨论】:

  • 这不是我想做的。我希望应用程序在锁屏消息布局中显示文本,而不是在通知框中。
  • 好吧,我不知道。如果我找到了,我会帮助你。
猜你喜欢
  • 2011-05-13
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多