2013-07-03 5 views
0

알림 생성이 멈췄습니다. 상태 표시 줄 (알림 표시 줄)에 배터리 수준을 표시하고 싶습니다. 알림은 영구되었습니다. 다음은 코드의 일부입니다.배터리 잔량을 표시하는 영구 알림을 만드는 방법

private BroadcastReceiver batteryInfoReceiver = new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context context, Intent intent) { 

      int level= intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 

       String[] status = { 
       "Level: "+level 
       . . . 
       }; 

      NotificationManager notifi = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 

      Notification notification = new Notification(R.drawable.ic_launcher,"Level",System.currentTimeMillis()); 

      notification.flags = Notification.FLAG_ONGOING_EVENT; 

      Intent i = new Intent(context, MainActivity.class); 

      PendingIntent penInt = PendingIntent.getActivity(getApplicationContext(), 0 , i , 0); 

      notification.setLatestEventInfo(getApplicationContext(), +level+"%", penInt); 

      notifi.notify(215,notification); 


      } 
}; 

맞습니까? 매니페스트에 예를 들어 추가 할 항목이 있습니까? 나는 이런 식으로이 줄을 썼습니다 : Intent i = new Intent(context, MainActivity.class);하지만 정확한지 알 수 없습니다.

답변

0

예, 당신은 추가해야합니다 : 여기

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

더 많은 정보 :

Get battery level only once using Android SDK

+0

확인이 덕분에 작동합니다. 한 가지, 지금 여기'알림 알림 = 새 알림 (R.drawable.ic_launcher, + 레벨 + "%", System.currentTimeMillis())'나는 레벨이 아니라 아이콘 만 표시하고 싶습니다. 사실 그것은 상태 표시 줄에 아이콘 배터리 만 표시합니다. 그것을 삭제할 수있는 방법이 있습니까? –

관련 문제