android 通知灯 测试,Android灯光系统通知灯【转】
标签:
一、通知灯应用程序的编写
1、首先实现一个按钮功能
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flashing Light at 20S"
android:id="@+id/button"
/>
2、实现按钮的点击监听
mLightButton = (Button)findViewById(R.id.button);
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
3、实现延时
private Handler mLightHander = new Handler();
private LightRunnable mLightRunnable = new LightRunnable();
class LightRunnable implements Runnable {
@Override
public void run() {
if (flashing) {
FlashingLight();
} else {
ClearLED();
}
}
}
mLightHander.postDelayed(mLightRunnable, 20000);
4、实现通知
private void FlashingLight()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledARGB = 0xFF0000ff;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
}
5、取消通知
private void ClearLED()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
nm.cancel(LED_NOTIFICATION_ID);
}
6、实现点击延时
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
二、测试
用法:
1. 先在单板上"Setting"->"Display"->"Sleep"设为"15S"
2. 运行程序
3. 点击按钮后不再操作
4. 等屏幕再次变黑即可看到通知灯闪烁
注意:黑屏期间可以通过menu键或K1键返回程序界面
三、程序
package com.thisway.app_0002_lightdemo;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.app.NotificationManager;
import android.app.Notification;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private Button mLightButton = null;
boolean flashing = false;
final private int LED_NOTIFICATION_ID = 123;
private Handler mLightHander = new Handler();
private LightRunnable mLightRunnable = new LightRunnable();
class LightRunnable implements Runnable {
@Override
public void run() {
if (flashing) {
FlashingLight();
} else {
ClearLED();
}
}
}
private void FlashingLight()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledARGB = 0xFF0000ff;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
}
private void ClearLED()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
nm.cancel(LED_NOTIFICATION_ID);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLightButton = (Button)findViewById(R.id.button);
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
flashing = !flashing;
if (flashing){
mLightButton.setText("Stop Flashing the Light");
}else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHander.postDelayed(mLightRunnable, 20000);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Flashing Light at 20S"
android:id="@+id/button" />
标签:
来源: https://www.cnblogs.com/zzb-Dream-90Time/p/10199094.html
android 通知灯 测试,Android灯光系统通知灯【转】相关推荐
- android服务器压力测试,Android压力测试Monkey工具
最近在Android程序测试过程中接触到了自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括android测试框架.CTS.Monkey.Monkeyrunner其它test t ...
- xamarin android 通知,在 Xamarin.Android 中使用 Notification.Builder 构建通知
0 背景 在 Android 4.0 以后,系统支持一种更先进的 Notification.Builder 类来发送通知.但 Xamarin 文档含糊其辞,多方搜索无果,遂决定自己摸索. 之前的代码: ...
- android app 渗透测试,android app渗透测试方法大全.pdf
Android APP 渗透测试方法大全 by backlion 一.Android APP 渗透测试方法 1.测试环境 SDK : J a JDK , Android SDK. 工具: 7zip, ...
- android 渠道包测试,Android快速批量多渠道包的“蛋生”
对于安卓程序猿朋友来说,每当发布新版本的APP,均会分发到各大应用市场,比如腾讯应用宝,豌豆荚和360手机助手等.为了让程序猿同志们更好的区分不同的应用市场,掌握各市场APP发展状况,为了更多体现世界 ...
- android 通知显示时间,android:在特定时间显示通知?
我有一个名为的函数show_notification(),当用户点击按钮时我会调用它.关键是,一旦他点击[如下面的函数],我不想显示通知,我想在特定的time= hours:mins 地方显示此通知. ...
- Android浏览器速度测试,Android平台浏览器网页加载速度对比评测
参与测试的浏览器 手机上网已经渐渐成为人们的一种习惯,无论在等公交时.乘地铁时.吃饭等餐时,很多朋友都习惯掏出手机简单浏览一下微博.人人.新闻网站等页面.移动网络的确为我们带来了莫大的便利,但网速和稳 ...
- android应用 暴力测试,Android 关于Monkey暴力测试
现在的好多应用市场上架之前都有经过Monkey的暴力测试,我们作为android的开发人员最后上线前再给测试人员测试的时候最好也要进行一下Monkey压力测试.废话不多说,今天就讲一下如何进行测试: ...
- android 通知id,java – Android:获取唯一的通知ID
我相信你不应该一次就给用户那么多的通知.您应该显示一个整合关于Gmail客户端事件组的信息的单个通知.为此目的使用Notification.Builder. NotificationCompat.Bu ...
- android系统稳定性测试,Android的稳定性
概述 Android的稳定性包含以下几个方面: 1.ANR 2.Crash 3.Tombstone 4.Freeze 5.黑屏 6.冻屏 #稳定性问题分析以及需要的相关log /data/anr/tr ...
最新文章
- C++中extern “C”含义深层探索(zz)
- 文档生成工具Sandcastle Help File Builder
- springboot分页展示功能_springboot+vue实现分页功能
- 数据库知识:SQLServer变量相关知识介绍
- 安装2000数据库的时候挂起
- MySQL生产库主从重新同步操作注意事项
- 基于基于jsp+mysql+Spring+mybatis的SSM汽车保险理赔管理系统设计和实现
- 成都双流计算机大专学校,成都双流有哪些好的职业学校?
- 质心公式_卢瑟福散射公式
- 软件测试ios打包,苹果测试iOS打包成 ipa包
- 做XH2.54杜邦线材料-导线
- HTML5 Canvas组件绘制太极图案
- C1认证学习笔记2--计算机通识
- 将Raspberry Pi用作台式PC的17个最佳Raspbian应用
- 论文格式之编辑页眉页码
- 如何利用python将NWPU VHR-10目标检测遥感数据集的格式转换成VOC目标检测数据集的格式
- 学生信息管理系统——查询学生信息(Java+web综合)
- Holoview--Introduction
- 如何保证企业服务器安全-MCK主机加固解决方案
- SWF 编辑工具 闪客之锤