2012-05-21 7 views
2

나는 Junit 테스트 케이스를 가지고있는 테스트 프로젝트를 가지고있다.안드로이드 알림 바

알림 표시 줄에 액세스하여 인터넷에 도착한 메시지를 응용 프로그램에 클릭해야하는 테스트 사례가 있습니다.

어떻게하면됩니까? 알림 표시 줄의 알림 메시지를 어떻게 클릭 할 수 있습니까?

답변

1

이 예는 이것

public class SimpleNotification extends Activity { 

private NotificationManager mNotificationManager; 
private int SIMPLE_NOTFICATION_ID; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
    final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis()); 


    Button start = (Button)findViewById(R.id.notifyButton); 
    Button cancel = (Button)findViewById(R.id.cancelButton); 

    start.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 


      Context context = getApplicationContext(); 
      CharSequence contentTitle = "Notification Details..."; 
      CharSequence contentText = "Browse Android Official Site by clicking me"; 
      Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com")); 
      PendingIntent intent = 
       PendingIntent.getActivity(SimpleNotification.this, 0, 
       notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 

      notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); 
      mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 
     } 
    }); 

    cancel.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 

      mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); 
     } 
    }); 
} 

}

참조되고