关于Android中Notification问题

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  Button bt1=(Button) findViewById(R.id.button1);
  bt1.setOnClickListener(new View.OnClickListener() {


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        //通知消息与Intent关联 
        Intent i=new Intent(MainActivity.this, NotifiedActivity.class);
        PendingIntent pi=PendingIntent.getActivity(MainActivity.this, 0, i, 0);

        Notification mynNotification=new Notification();  //定义notification  
        mynNotification.icon=R.drawable.gender;
        mynNotification.tickerText=getResources().getString(R.string.notification);
        mynNotification.defaults=Notification.DEFAULT_SOUND;

         //具体的通知内容  
        mynNotification.setLatestEventInfo(MainActivity.this, "示例", "点击查看",pi);

        //从系统服务中获得通知管理器
        NotificationManager nm=(NotificationManager)MainActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);

        //执行通知 
        nm.notify(0, mynNotification);



    }
});
}

}

//就是我想点击按钮之后在状态栏出现通知,然后点击通知会跳转另一个页面,但就是跳不过去。 求大神支招。
//mynNotification.setLatestEventInfo(MainActivity.this, "示例", "点击查看",pi);
//上面这句代码出现警告The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type Notification is deprecated

查看全部
a460670026
a460670026
2016/03/23 07:05
  • android
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复