簡單概述Android通知

簡單概述Android通知

舉例說明

  • ` Button start_notification;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main3);
    start_notification = (Button) findViewById(R.id.bt_fs);
    start_notification.setOnClickListener(this);
    }

    public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.bt_fs:

            NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    
            Notification notification = new Notification(
                    R.mipmap.ic_launcher, "有通知來了", System.currentTimeMillis());
    
    
            Intent intent = new Intent(this, NotificationActivity.class);
    
    
            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                    intent, PendingIntent.FLAG_CANCEL_CURRENT);
    
    
           notification.setLatestEventInfo(this, "股票大漲", "今日萬科的股票停牌,應對惡意收購",
                  pendingIntent);
            manager.notify(1, notification);
            break;
    
        default:
            break;
    }
    

    }`

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章