java屏幕锁定_Java android FCM,当应用程序最小化或屏幕锁定时我听不到声音和颤音...

我使用FCM,当我的应用程序最小化或手机锁定时,我听不到声音和颤音。当某件事来自服务器时(当服务器向我的手机发送消息时),我会创建一个通知。当我的应用程序是在上面我听到一个声音和vibratteJava android FCM,当应用程序最小化或屏幕锁定时我听不到声音和颤音

private void createNotification(String messageBody) {

Bitmap Largeicon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher);

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

notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID);

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

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

//FLAG_UPDATE_CURRENT is important

PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);

PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK/* | PowerManager.FULL_WAKE_LOCK*/ | PowerManager.ACQUIRE_CAUSES_WAKEUP), "SMOK Komunal");

wakeLock.acquire();

wakeLock.release();

}

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

Notification notification = new Notification.Builder(getApplicationContext())

.setSmallIcon(R.drawable.ic_launcher)

.setContentTitle("Wiadomosc z serwera")

.setStyle(new Notification.BigTextStyle().bigText(messageBody))

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setLargeIcon(Largeicon)

.setContentIntent(pendingIntent)

.setVibrate(vibratePattern)

.setLights(Color.GREEN, 2000, 2000)

.build();

notificationManager.notify(0, notification);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);

PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK /*| PowerManager.FULL_WAKE_LOCK |*/ | PowerManager.ACQUIRE_CAUSES_WAKEUP), "SMOK Komunal");

if (wakeLock.isHeld())

wakeLock.release();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值