android Notification 入门
来源:互联网 发布:淘宝外围女孙佑怡 编辑:程序博客网 时间:2024/06/01 22:11
package com.example.xh.notification;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.content.Intent;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;public class MainActivity extends AppCompatActivity { private NotificationManager mNotificationManager; private static final int NOTIFICATION_FLAG=1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mNotificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE); } public void notificationMethod(View view) { Intent intent = new Intent(this,DemoActivity.class);//意图 PendingIntent pi = PendingIntent.getActivity(this,0,intent,0);//将intent传给pi Notification notification = new Notification.Builder(this) .setSmallIcon(R.mipmap.ic_launcher) .setContentTitle("有种你再点!") .setContentText("就知道你不敢点!") .setTicker("新消息") .setContentIntent(pi) //设置触摸通知后的行为 .getNotification(); notification.flags|=Notification.FLAG_AUTO_CANCEL; /* 旧版本支持 Notification notification = new Notification(); notification.icon=R.mipmap.ic_launcher; notification.tickerText="有新消息"; notification.flags|=Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this,"标题"."内容",pi);*/ mNotificationManager.notify(NOTIFICATION_FLAG,notification);//调用notification }}
DemoActivity.java
package com.example.xh.notification;import android.app.Activity;import android.os.Bundle;/** * Created by XH on 2016/8/18. */public class DemoActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.demo); }}
<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.xh.notification.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="千万不要点!" android:id="@+id/button" android:layout_marginTop="107dp" android:onClick="notificationMethod"/></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="能进到到这里说明你是一个充满好奇心的逗比!" android:textSize="50dp" android:textColor="@color/colorAccent" android:id="@+id/textView2" android:layout_marginTop="150dp"/></LinearLayout>
0 0
- Android Notification入门
- android Notification 入门
- Android入门之Notification(纯java)
- Android入门笔记 - 界面开发 - Notification, NotificationManager
- Android通知Notification入门小例子(一)
- Android入门开发之Toast、Notification、Menu
- android 入门学习笔记 NotificationManager与Notification对象的应用
- android入门(八) 状态栏通知(消息推送) Notification
- ANdroid Notification
- android notification
- android notification
- android notification
- Android Notification
- android notification
- android notification
- android Notification
- Android Notification
- android Notification
- mkdir - make directories
- html表单的几种提交方式总结(C#数组传库比较)
- 迭代器模式
- 关系数据库是如何工作的
- JavaScript window、location对象基础知识整理
- android Notification 入门
- JSON.NET 简单的使用
- Glide-Target
- Java压缩和解压文件工具类ZipUtil
- CheckIO 中位数
- 在VS2013中运行程序时如何传递实参
- Git版本控制学习与使用一
- Hellow
- json(http://www.asp.net/whitepapers/request-validation)