package com.example.notification;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
create();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void create(){
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
//2-实例化Notification:
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
}
}
简单不??
分享到:
相关推荐
android通知入门小例子.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Android一个带有进度条的通知栏的DEMO,对初学Android的初学者是一个不错的参考例子,代码实现了点击显示按钮就会在通知栏上出现一个有图片和进度条的提示,点击取消按钮就会取消通知栏的提示通知。
自己写的关于消息通知栏的demo,这个很简单了啊。新手看看还可以
Android自定义通知显示在通知栏上,小例子
通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向 用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现。发出一 条通知后,手机最上方的状态栏中会显示一...
Android通知栏消息、点亮屏幕、震动、声音、显示样式的小例子。
通知栏(Notification)使用介绍及案例,写了三个小例子供大家参考
Android 任务状态栏的学习,例子很好值得参考
Android notifications 框架例子。好用 方便 快速 可自定义 可适配Android手表
Android DownLoadManager使用的小例子,主要使用DownloadManager.Request方法来下载文件,下载可在通知栏中显示
Android实现可定制可滑动的标签栏的代码例子.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
使用android做的小例子 可以在通知栏显示消息和小图标 点击进去可以进入一个页面 主要用于notification的学习 基于android2.3开发
Android 简单实现了Notification和WebView结合的例子
我们在做Android开发的时候经常会遇到后台线程执行的比如说下载文件的时候,这个时候我们希望让客户能看到后台有操作进行,这时候我们就可以使用进度条,那么既然在后台运行,为的就是尽量不占用当前操作空间,用户可能...
就是手机的通知栏的颜色不再是白色、黑色简单的两种了,本人用的小米4手机,米4手机中的自带软件都支持沉浸式通知栏, 举个例子:大家可以看一下自己的qq,它的标题的背景颜色是蓝色的,那么通知栏也会变成蓝色。...
notification是一种出现在任务栏的提示,特别是在4.0以后notification改进了不少,本文内容都是基于4.0及4.1以后总结来的,详细介绍各种布局的Notification样式,实现音乐播放器、邮件通知等复杂的例子详细代码。
它要是实现和用户的交互的话需要通过通知栏或者是通过发送广播,UI去接收显示。 (3).它的应用十分广泛,尤其是在框架层,应用更多的是对系统服务的调用。 2.作用: (1).它用于处理一些不干扰用户使用的后台操作。...
主要内容包括Android的四大应用程序组件(Activity、Service、Content Provider和Broadcast Receiver)、布局、菜单、控件、资源和本地化、可视化UI设计、对话框、Toast和通知栏(Notification)、Fragment、ActionBar、...
这一联盟将会支持 Google 发布的 Android 手机操作系统或者应用软件,共同开发名为 Android 的 开 放源代码的移动系统。开放手机联盟包括手机制造商、手机芯片厂商和移动运营商几类。目前,联盟成员 数 量已经达到了...