2012-11-09 7 views
2

나는 안드로이드 초보자입니다. 내 앱에서 알림을 표시하고 싶습니다. 다음 코드인 텐트를 사용하지 않고 Android에서 알림 표시

 String ns = Context.NOTIFICATION_SERVICE; 
     NotificationManager notificationManager = (NotificationManager) getSystemService(ns); 
     int icon = R.drawable.icon; 
     CharSequence tickerText = ""; 
     long when = System.currentTimeMillis(); 
     Notification notification = new Notification(icon, tickerText, when); 
     Context context = getApplicationContext(); 
     CharSequence contentTitle = "Hello"; 
     CharSequence contentText = "Welcome "; 
     Intent notificationIntent = new Intent(); 
     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, null, 0); 
     notification.defaults |= Notification.DEFAULT_SOUND; 
     notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);  
     notificationManager.notify(HELLO_ID, notification); 

를 사용하지만 내 문제는 아이콘이 상태 표시 줄에 표시가 그 때는 아이콘 의도가로드 내 응용 프로그램을 실행 할 때마다입니다. 인 텐트를 사용하지 않고 알림을 표시하는 방법? 이 당신이 원하는 경우 잘 모르겠어요

답변

0

도와주세요,하지만 당신은 몇 가지 빠른 알림을 표시 할 경우, 토스트은 마음에 와서 :

Context context = getApplicationContext(); 
    CharSequence text = "Notification!"; 
    int duration = Toast.LENGTH_SHORT; 
    Toast toast = Toast.makeText(context, text, duration); 
    toast.show(); 

당신은 토스트가 함께 표시되는 시간을 변경할 수 있습니다 지속.

관련 문제