2017-01-25 10 views
0

ロック画面での通知の表示方法がわかりません。これが私の通知です:ロック画面でのJava Androidの通知通知

public static void getSynchronizeNotification(Context context, DataResponse dataResponse) { 
    Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); 
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID); 

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); 
Notification notification = new Notification.Builder(context) 
     .setContentTitle(context.getString(R.string.app_name)) 
     .setSmallIcon(R.drawable.ic_launcher) 
     .setContentIntent(pendingIntent) 
     .setContentText("Zmiany po synchronizacji...") 
     .setStyle(new Notification.BigTextStyle().bigText(buildNotificationAfterSynchronizeText(dataResponse))) 
     .setLargeIcon(Largeicon) 
     .setAutoCancel(true) 
     .setVibrate(vibratePattern) 
     .setSound(alarmSound) 
     .setPriority(Notification.PRIORITY_MAX) 
     .build(); 
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; 
notificationManager.notify(NOTIFICATION_SYNCHRONIZE_ID, notification); 
} 
+0

を参照してください。http://stackoverflow.com/questions/7442670/android-how-表示通知を表示する –

+0

'.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) ' –

+0

@TimCastelijnsは役に立ちません –

答えて

0

私はこれを行うと、それは動作します: マニフェストにこれを追加します。

<uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> 

public static void getSynchronizeNotification(Context context, DataResponse dataResponse) { 

     Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); 
     NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID); 

     PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); 
     KeyguardManager km = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE); 
     final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("IN"); 
     kl.disableKeyguard(); 

     PowerManager pm = (PowerManager) context.getSystemService(POWER_SERVICE); 
     PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "SMOK Komunal"); 
     wl.acquire(); 
     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context) 
       .setCategory(Notification.CATEGORY_PROMO) 
       .setSmallIcon(R.drawable.ic_launcher) 
       .setContentTitle("Zmiany po synchronizacji...") 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(buildNotificationAfterSynchronizeText(dataResponse))) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setLargeIcon(Largeicon) 
       .setContentIntent(pendingIntent) 
       .setVibrate(vibratePattern) 
       .setLights(Color.GREEN, 2000, 2000) 
       .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); 

     wl.release(); 

     notificationManager.notify(0, notificationBuilder.build()); 
    } 
関連する問題