Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android手机睡眠时的通知_Android_Notifications - Fatal编程技术网

Android手机睡眠时的通知

Android手机睡眠时的通知,android,notifications,Android,Notifications,我一直在我正在构建的应用程序中使用通知。自较旧的版本以来,构建通知的方式似乎发生了很大的变化,但最终我还是成功地显示了一个通知。(*) 但我有两个问题: 1) 通知没有发出声音。这不是增加平板电脑中的通知量的问题,因为来自gmail的通知确实会发出声音。如何发出产生声音和振动的通知?(我正在Android 6中尝试此功能) 2) 更重要的是,我如何在手机处于睡眠状态时发出“通知”我的通知?到目前为止,我的通知确实发生在手机睡觉时,但我必须打开手机才能看到它们。理想情况下,即使屏幕为黑色,也应显示

我一直在我正在构建的应用程序中使用通知。自较旧的版本以来,构建通知的方式似乎发生了很大的变化,但最终我还是成功地显示了一个通知。(*)

但我有两个问题: 1) 通知没有发出声音。这不是增加平板电脑中的通知量的问题,因为来自gmail的通知确实会发出声音。如何发出产生声音和振动的通知?(我正在Android 6中尝试此功能)

2) 更重要的是,我如何在手机处于睡眠状态时发出“通知”我的通知?到目前为止,我的通知确实发生在手机睡觉时,但我必须打开手机才能看到它们。理想情况下,即使屏幕为黑色,也应显示这些选项

编辑:为了清楚起见,这些通知是在手机处于睡眠状态时发出的。只是,除非我打开屏幕,否则我看不到它们,然后它们就出现了。我希望通知“打开屏幕”

(*)我当前的代码是

         NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(), 0);


        Notification notification= new Notification.Builder(context)
                .setContentTitle(message)
                .setContentText("Proximity Alert!")
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true)
                .setContentIntent(pi).build(); //getNotification();


        //notification.flags= Notification.FLAG_AUTO_CANCEL;

        //notification.setLatestEventInfo(context, "GAST", "Proximity Alert", pi); //this is deprecated

        notificationManager.notify(NOTIFICATION_ID, notification);

是的,您可以通过这种方式在发送通知时添加声音

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);  

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICAT‌​ION); 
builder.setSound(defaultSoundUri);
要在睡觉时使用手机,您必须使用该服务


文档:

对于声音:Uri defaultSoundUri=RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知);在通知生成器中:.setSound(defaultSoundUri)感谢您的回复。关于第二项,我可能没有解释清楚,对不起。通知确实发生在睡觉时。如果我按下on按钮,我可以清楚地看到,即使不使用服务,他们也在那里。我的问题是我想让他们叫醒电话。我该怎么做?请参考此唤醒屏幕,希望有帮助