zoukankan      html  css  js  c++  java
  • Notification

    布局

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="helloworld.com.inspur.demo8">
        <uses-permission android:name="android.permission.FLASHLIGHT"/>
        <uses-permission android:name="android.permission.VIBRATE"/>
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".AActivity"/>
        </application>
    
    </manifest>

    逻辑

    package helloworld.com.inspur.demo8;
    
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.preference.MultiSelectListPreference;
    import android.support.v7.app.AlertDialog;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.support.v7.widget.ScrollingTabContainerView;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.jar.Manifest;
    
    public class MainActivity extends AppCompatActivity {
        private Button bt1,bt2;
        private NotificationManager notificationManager;
        private Notification notification;
        private static final int NOTIFACATION_ID=0x123;
      //  private Intent intent;
       private  Context context=MainActivity.this;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            bt1= (Button)findViewById(R.id.bt1);
            bt2=(Button)findViewById(R.id.bt2);
            notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            bt1.setOnClickListener(new View.OnClickListener() {
                Intent intent=new Intent(context,AActivity.class);
                PendingIntent pendingIntent= PendingIntent.getActivities(context,0,new Intent[]{intent},0);
                @Override
                public void onClick(View v) {
                notification=new Notification.Builder(context)
                        .setAutoCancel(true)
                        .setSmallIcon(R.mipmap.ic_launcher)
                        .setTicker("标题啊~~~~")
                        .setContentTitle("标题啊")
                        .setContentText("今天周五")
                        .setWhen(System.currentTimeMillis())
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setContentIntent(pendingIntent)
                         .build();
                    notificationManager.notify(NOTIFACATION_ID,notification);
                }
            });
    
    
            bt2.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    notificationManager.cancel(NOTIFACATION_ID);
                }
            });
    
    
    
    
        }
    }

    配置

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:orientation="vertical"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="helloworld.com.inspur.demo8.MainActivity">
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt1"
            android:text="设置"/>]
    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/bt2"
            android:text="取消"/>
    
    </LinearLayout>

    跳转页面

    package helloworld.com.inspur.demo8;
    
    
    import android.app.Activity;
    import android.os.Bundle;
    
    public class AActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    }
  • 相关阅读:
    双连通分量
    题解 骰子
    2020 最新 Kubernetes实战指南:从零到架构师的进阶之路
    kubernetes实战(二十八):Kubernetes一键式资源管理平台Ratel安装及使用
    新书推荐《再也不踩坑的Kubernetes实战指南》
    为什么要用Kubernetes?
    Kubernetes实战指南(三十一):零宕机无缝迁移Spring Cloud至k8s
    kubernetes实战(三十一):Prometheus监控Windows主机
    kubernetes实战(三十):CentOS 8 二进制 高可用 安装 k8s 1.17.x
    kubernetes实战(二十九):Kubernetes RBAC实现不同用户在不同Namespace的不同权限
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9023250.html
Copyright © 2011-2022 走看看