1

enter image description here이미지에서 더 이상 사용되지 않는 알림 클래스의 대안은 무엇입니까?

강력한 텍스트 안녕하세요, 안드로이드 장치에서 내 상태 표시 줄 알림 내 알림을 표시하려는 . 1 년 전의이 자습서를 따르고 있습니다. http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/#comment-28784 . 실제로 작동하지만 Java 코드는 좋지 않습니다. 그것도 잘 작동 수정해야합니다.

이 경우 Notification 클래스의 대체 클래스는 무엇이고 코드를 수정하려면 어떻게해야합니까?

답변

1

당신은 당신의 훌륭한 대답이

NotificationManager mNotificationManager = (NotificationManager) context 
    .getSystemService(Context.NOTIFICATION_SERVICE); 
NotificationCompat.Builder builder = new NotificationCompat.Builder(context); 
Notification notification = null; 

Intent intent = new Intent(context, PdfDialogAlert.class); 
intent.putExtra("dialog", 1); 
PendingIntent piDismiss = 
    PendingIntent.getActivity(context, 0, intent, 0); 

builder.setContentIntent(piDismiss) 
    .setSmallIcon(R.drawable.ic_notif) 
    .setWhen(System.currentTimeMillis()) 
    .setContentTitle("fileName") 
    .setTicker(message) 
    .setContentText("message"); 

notification = builder.build(); 
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; 
+0

감사처럼 많은 일을 할 수 있습니다. 이제 클릭 한 상태 표시 줄에서 알림을 제거하는 방법이 하나뿐입니다. 사실이 코드를 추가했습니다 "mBuilder.setAutoCancel (true);" 그러나 작동하지 않습니다. – Gilana

+0

위의 코드에서 FLAG_AUTO_CANCEL은 다음을 참조 할 것입니다. http://developer.android.com/reference/android/app/Notification.html#FLAG_AUTO_CANCEL – keshav

+0

안녕하세요, 코드에 버그가 있습니다. 새로운 사용자 계정을 만들 때마다 우리는 항상 이클립스에서 두 번 응용 프로그램을 실행하여 알림을 표시 할 수 있습니다. 이 문제에 대해 알고 있습니까? – Gilana