android8 通知呼吸灯_Android中通知Notification使用实例(振动、灯光、声音)
本文实例讲解了通知Notification使用方法,此知识点就是用作通知的显示,包括振动、灯光、声音等效果,分享给大家供大家参考,具体内容如下
效果图:
MainActivity:
import java.io.File;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
private Button sendNotice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendNotice = (Button) findViewById(R.id.send_notice);
sendNotice.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.send_notice:
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//创建notification对象来存储通知所需的各种信息
//第一个参数为图标
//第二个参数用于指定通知的ticker内容
//第三个参数用于指定通知被创建的时间,以毫秒为单位
Notification notification = new Notification(
R.drawable.ic_launcher, "This is ticker text",
System.currentTimeMillis());
//此处设置点击的activity的跳转
//第一个参数依旧是Context
//第二个参数一般用不到,所以用0表示取默认值
//第三个参数就是一个Intent对象
//FLAG_CANCEL_CURRENT:如果当前系统中已经存在一个相同的PendingIntent对象,
// 那么就将先将已有的PendingIntent取消,然后重新生成一个PendingIntent对象。
Intent intent = new Intent(this, NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
//设置通知的布局
//第一个参数为Context
//第二个参数用于指定通知的标题
//第三个参数用于指定通知的征文内容
//第四个参数用于传入PendingIntent对象,用于设置点击效果
notification.setLatestEventInfo(this, "This is content title",
"This is content text", pi);
// //设置在通知发出的时候的音频
// Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));
// notification.sound = soundUri;
//
// //设置手机震动
// //第一个,0表示手机静止的时长,第二个,1000表示手机震动的时长
// //第三个,1000表示手机震动的时长,第四个,1000表示手机震动的时长
// //此处表示手机先震动1秒,然后静止1秒,然后再震动1秒
// long[] vibrates = {0, 1000, 1000, 1000};
// notification.vibrate = vibrates;
//
// //设置LED指示灯的闪烁
// //ledARGB设置颜色
// //ledOnMS指定LED灯亮起的时间
// //ledOffMS指定LED灯暗去的时间
// //flags用于指定通知的行为
// notification.ledARGB = Color.GREEN;
// notification.ledOnMS = 1000;
// notification.ledOffMS = 1000;
// notification.flags = Notification.FLAG_SHOW_LIGHTS;
//如果不想进行那么多繁杂的这只,可以直接使用通知的默认效果
//默认设置了声音,震动和灯光
notification.defaults = Notification.DEFAULT_ALL;
//使用notify将通知显示出来
//第一个参数是id,要爆炸为每个通知所指定的id是不同的
//第二个参数就是Notification对象
manager.notify(1, notification);
break;
default:
break;
}
}
}
activity_main:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/send_notice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发出通知"
/>
NotificationActivity:
import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;
public class NotificationActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification_layout);
//打开NotificationActivity这个Activity后把通知给关掉
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.cancel(1);
}
}
notification_layout:
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="24sp"
android:text="这是通知点击后的界面"
/>
AndroidManifest:
package="com.example.notificationtest"
android:versionCode="1"
android:versionName="1.0" >
android:minSdkVersion="14"
android:targetSdkVersion="19" />
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:name="com.example.notificationtest.MainActivity"
android:label="@string/app_name" >
android8 通知呼吸灯_Android中通知Notification使用实例(振动、灯光、声音)相关推荐
- android8 通知呼吸灯_android学习笔记----解决兼容8.0以上和8.0之前版本通知栏显示、振动、LED呼吸灯闪烁问题(真机验证)...
Android 8.0系统的通知栏适配文章讲解(郭霖大神的): 然后开始试验了: 模拟器: 真机(华为荣耀V9,8.0系统),下拉横幅需要手动打开,除非是厂家白名单,比如QQ.微信 我在oppo手机6 ...
- android8 通知呼吸灯_Android8.0及以上的Notification
这篇文章上次修改于 702 天前,可能其部分内容已经发生变化,如有疑问可询问作者. 在新版本上(Android8.0及以上)开发时,会遇到一些问题,比如,不显示通知,Notification 声音不可 ...
- android8 通知呼吸灯_android8 通知呼吸灯_说说8.0下 Android 通知(Notification)
当运用程序不在前台运转,这时便借助关照( Notification )向用户发送少许提醒消息. 发出关照后,手机非常上方的状况栏中就会表现一个关照图标,下拉状况栏就会看到关照的细目. 1 根基用法 / ...
- android8 通知呼吸灯_说说8.0下 Android 通知(Notification)
当运用程序不在前台运转,这时便借助关照( Notification )向用户发送少许提醒消息. 发出关照后,手机非常上方的状况栏中就会表现一个关照图标,下拉状况栏就会看到关照的细目. 1 根基用法 / ...
- android8 通知呼吸灯_正在消失的功能,为什么越来越多的手机没有呼吸灯?你知道原因吗...
正在消失的功能,为什么越来越多的手机没有呼吸灯?你知道原因吗 其实说到手机呼吸灯,大家应该都不陌生,毕竟如果你有心心念念的人儿,每次呼吸灯闪烁,都会迫不及待的打开手机查看消息,想看看是不是TA给自己发 ...
- android8 通知呼吸灯_手机没有呼吸灯?这款APP帮你实现手机通知“可视化”
7月6日消息,现在越来越多的手机因为全面屏设计导致了LED通知灯被移除.对于这一问题,外媒Phone Arena称,一位安卓程序开发人员开发了一款名为"通知好友"(Notify B ...
- android8 通知呼吸灯_手机呼吸灯那么好用!为什么要取消它?没有呼吸灯真的好吗?...
说起手机的呼吸灯相信大家应该都是不会陌生吧,当我们手机内有消息的时候,呼吸灯就会亮起,甚至是有些手机的呼吸灯还可以因为不同的消息设置不同的提示颜色,随着智能手机的发展,相比过去单调的设计,有的厂商为其 ...
- xamarin android 通知,在 Xamarin.Android 中使用 Notification.Builder 构建通知
0 背景 在 Android 4.0 以后,系统支持一种更先进的 Notification.Builder 类来发送通知.但 Xamarin 文档含糊其辞,多方搜索无果,遂决定自己摸索. 之前的代码: ...
- android mvp模式例子_Android中mvp模式使用实例详解
MVP 是从经典的模式MVC演变而来,它们的基本思想有相通的地方:Controller/Presenter负责逻辑的处理,Model提供数据,View负 责显示.作为一种新的模式,MVP与MVC有着一 ...
最新文章
- 海康 安全码 修改密码_手机为什么要设置PIN码 手机设置PIN码的原因【介绍】
- Flutter快速入门 五步搞定Flutter环境配置
- CLOSE_WAIT状态的原因与解决方法 --转
- android SQLite查询并显示用户输入的选择信息
- 【转载】C#中List集合使用Exists方法判断是否存在符合条件的元素对象
- laravel-admin 使用 wangEditor 的一些小方法
- Go 的新关键字 any 是个啥
- js页面自适应屏幕大小_Web页面适配移动端方案研究
- 高大上!手把手教你在京东云擎上部署个人应用!
- 外联样式表添加到html中,CSS联样式表之内联式、外联式和嵌入式
- Java中,成员内部类的常见修饰符及应用 成员内部类不是静态的,访问的格式...
- 数据集下载地址(转)以下内容转自https://baijiahao.baidu.com/s?id=1615853849218131902wfr=spiderfor=pc
- java实现屏幕共享功能_屏幕共享功能的应用
- 数学分析教程 第十八章学习感受
- 强烈推荐一款好用的API接口
- ubuntu下使用vscode阅读内核源码或uboot源码使用技巧——search.excludefiles.exclude
- spring mysql 事务回滚失败_Spring事务回滚失败
- 永恒之蓝 ms17_010漏洞
- [转]关于 UTC , GMT 和 BST 夏令时
- 红米note3图片剪裁bug