2012-02-28 3 views
0

앱에서 피드를 수집하는 서비스가 실행 중입니다. 피드를 찾으면 표기법을 생성합니다 (실패한 경우).Android 앱에서 알림 정보가 작동하지 않음

doNotification(date,"New Article",title,link,content,description,false); 
기사

이 : 동영상의

doNotification(date,"New Video",title,link,"","",true); 

이 같은 메소드 호출을 사용합니다. 방법은 이것이다 :

public void doNotification(Date date,String title,String subtext,String url,String body,String dateString,boolean video){ 
     long time = date.getTime(); 
     if(time > feedGetter.lastFeed){ 
      //New feed, do notification 
      NotificationManager mNotificationManager = (NotificationManager) feedGetter.service.getSystemService(Context.NOTIFICATION_SERVICE); 
      int icon = R.drawable.notification_icon; 
      Notification notification = new Notification(icon, title + ": " + subtext, time); 
      Intent notificationIntent = new Intent(feedGetter.service, NotificationActivity.class); 
      notificationIntent.putExtra("url",url); 
      notificationIntent.putExtra("video",video); 
      if(!video){ 
       notificationIntent.putExtra("body",body); 
       notificationIntent.putExtra("date",dateString); 
       notificationIntent.putExtra("title",subtext); 
      } 
      notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
      PendingIntent contentIntent = PendingIntent.getActivity(feedGetter.service, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT); 
      notification.setLatestEventInfo(feedGetter.service.getApplicationContext(), title, subtext, contentIntent); 
      mNotificationManager.cancel(video? 1 : 0); 
      mNotificationManager.notify(video? 1 : 0, notification); 
      //Update new time if necessary. 
      if(time > feedGetter.newTime){ 
       feedGetter.newTime = time; //New time will be the time for this feed as it is the latest so far 
      } 
     } 
    } 

당신은 내가 올바르게 알림을 처리 할 수 ​​있도록 내가 의도로 일부 데이터를 추가시피. 알림은 동영상 용 ID 또는 기사 용 ID에 할당되며 이전 알림을 대체해야합니다. 그래서이 비디오의 URL을 활성화하고 문서는 사용자에게 표시되도록 문서를 처리하기위한 몇 가지 데이터 기사에 대한 응용 프로그램을 다시 시작하기로했다

public class NotificationActivity extends Activity{ 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Debug.out("Notification Activity"); 
     NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     if(getIntent().getBooleanExtra("video", true)){ 
      //Handle video notification 
      Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getIntent().getStringExtra("url"))); 
      startActivity(browserIntent); 
      mNotificationManager.cancel(1); 
     }else{ 
      //Start application UI and move to article 
      Intent intent = new Intent(this,TheLibertyPortalActivity.class); 
      intent.setAction(Intent.ACTION_MAIN); 
      intent.addCategory(Intent.CATEGORY_LAUNCHER); 
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      intent.putExtra("url", getIntent().getStringExtra("url")); 
      intent.putExtra("body", getIntent().getStringExtra("body")); 
      intent.putExtra("date", getIntent().getStringExtra("date")); 
      intent.putExtra("title", getIntent().getStringExtra("title")); 
      startActivity(intent); 
      mNotificationManager.cancel(0); 
     } 
     finish(); 
    } 
} 

다음은 알림을 처리하는 NotificationActivity입니다.

충분히 간단 해 보이지만 작동하지 않습니다. 알림이 표시되고 알림 메뉴에서 서로 바꿔 비디오 및 기사에 대한 최신 알림을 표시하지만 클릭하면 잘못 표시됩니다. 나는 기사 통보를 클릭하는 것을 시도하고 그것이 비디오이고 비디오 중 하나를로드한다고 생각한다. 알림 메뉴로 돌아가서 기사 알림을 클릭해도 동영상 알림이 사라졌습니다. 기사 알림을 클릭하면 아무 일도 일어나지 않습니다. 그것은 문자 그대로 메뉴를 닫고 아무것도하지 않으며 통지는 아무것도하지 않는 메뉴에 남아 있습니다.

감사합니다. 나는 레벨 8의 최소 SDK 버전과 2.2.1 Android 태블릿을 사용하여 Google API 레벨 14 API를 타겟팅하고 있습니다.

답변

2

문제는 대기중인 의도와 관련이 있습니다. 워드 프로세서가 requestCode를 사용하지 않는다고 말하는 경우에도 그렇습니다. 각 PendingIntent에 고유 한 정수를 전달해야합니다. 그게 효과가 있었어!

관련 문제