zoukankan      html  css  js  c++  java
  • 使用一个Notification启动Activity

    public class MultiComponentActivity extends Activity {
    
        NotificationManager notificationManager;
        private  final  int NOTIFICATION_ID=0x123;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_multi_component);
    
            notificationManager =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        }
    
        public void senNotification(View view){
    
            Intent intent=new Intent(MultiComponentActivity.this,MainActivity.class);
            PendingIntent pendingIntent=PendingIntent.getActivity(
                    MultiComponentActivity.this,0,intent,0);
            Notification notification=new Notification.Builder(MultiComponentActivity.this)
                    .setAutoCancel(true)
                    .setTicker("new message")
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setContentTitle("this is a notification")
                    .setContentText("thank you for testing this app !")
                    .setDefaults(Notification.DEFAULT_LIGHTS)
                    .setWhen(System.currentTimeMillis())
                    .setContentIntent(pendingIntent)
                    .build();
            notificationManager.notify(NOTIFICATION_ID, notification);
        }
        public void cancelNotifiacation(View view){
            notificationManager.cancel(NOTIFICATION_ID);
        }
    
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    numpy的文件存储 .npy .npz 文件
    Google词向量word2vec的使用
    Python函数-logging.basicConfig
    现货黄金-20180918
    Pandas的loc方法
    Pandas的index属性
    python调用exe程序
    Pandas的concat方法
    转载:为什么选择Nginx(1.2)《深入理解Nginx》(陶辉)
    discuz3.4:在Centos6.5中安装过程
  • 原文地址:https://www.cnblogs.com/Thereisnospon/p/4768451.html
Copyright © 2011-2022 走看看