码迷,mamicode.com
首页 > 其他好文 > 详细

Notification

时间:2018-05-11 13:01:15      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:sele   near   tis   UNC   cte   map   intent   tab   horizon   

布局

<?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);
    }
}

 

Notification

标签:sele   near   tis   UNC   cte   map   intent   tab   horizon   

原文地址:https://www.cnblogs.com/excellencesy/p/9023250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!