首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android通知栏

Android通知栏
EN

Stack Overflow用户
提问于 2012-05-21 18:55:44
回答 1查看 909关注 0票数 2

我有一个包含Junit测试用例的测试项目。

我有一个测试用例,我需要访问通知栏并单击通过互联网到达我的应用程序的消息。

我该怎么做呢。如何单击通知栏中的通知消息?

EN

回答 1

Stack Overflow用户

发布于 2012-05-21 18:57:55

这是一个示例,请参考此示例

代码语言:javascript
复制
    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);
        }
    });
}

}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10683917

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档