注意就是Notification的构造函数的when参数的作用不是定时的作用,所以要运用TimerTask和Timer~
package com.et.TestUi;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.app.AlertDialog.Builder;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TimePicker;
public class TestUi extends Activity {
public NotificationManager mNotificationManager;
private Button button;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mNotificationManager =(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Timer timer = new Timer();
timer.schedule(new setNotification("tickrText", "Notititle", "Noticontent"), new Date());
}
});
}
public void Notification(String tickrText,String Notititle,String Noticontent){
Notification notification = new Notification(R.drawable.stat_notify_more,tickrText,
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,null, 0);
notification.setLatestEventInfo(this, Notititle, Noticontent, contentIntent);
notification.defaults = Notification.DEFAULT_ALL;
mNotificationManager.notify(0, notification);
}
public class setNotification extends TimerTask{
String tickrText;
String Notititle;
String Noticontent;
public setNotification(String tickrText,String Notititle,String Noticontent){
this.tickrText = tickrText;
this.Notititle = Notititle;
this.Noticontent = Noticontent;
}
@Override
public void run() {
// TODO Auto-generated method stub
Notification(tickrText,Notititle,Noticontent);
}
}
}
点击button5秒后显示
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Button" /></LinearLayout>
分享到:
相关推荐
android service Notification ...安装的服务开机自启动,service定时的打印消息,消息同时显示在通知栏,窗体界面的跳转,自定义控件的开发。系统广播,定时广播,轮询广播等。BroadcastReceiver轮询广播
设置 npm install --save @kyvg/vue3-notification 将依赖项添加到您的main.js : import { createApp } from 'vue' import Notifications from '@kyvg/vue3-notification' const app = createApp ( { ... } ) app...
前提:考虑到自己每次在敲代码或者打游戏的时候总是会不注意时间,一不留神就对着电脑连续3个小时以上,对眼睛的伤害还是挺大的,重度近视了可是会遗传给...notification:此知识点就是用作通知的显示了,具体的可以参考
定时通知 - 此通知将在允许的时间后出现并自动消失。 执行 如果您愿意,通知功能中的幻灯片很容易合并到您自己的项目中。 只需在你自己的活动布局中的“notification_layout.xml”布局就像我的“main_activity_...
7.23 设置录音取样频率与显示录音时间 7.24 EXIF照片信息编辑及读取 7.25 声音音效均衡器、重低音与音场控制 7.26 在自定义的SurfaceView上绘制动画 第8章 当Android与Internet接轨 8.1 ...
7.23 设置录音取样频率与显示录音时间 490 7.24 exif照片信息编辑及读取 495 7.25 声音音效均衡器、重低音与音场控制 498 7.26 在自定义的surfaceview上绘制动画 504 第8章 当android与internet接轨 ...
Version 1.3.2 - 修正: 定时模式的错误 + 修正在重启后电话设置关闭的问题 + 修正其他一些错误 Version 1.3.1 - 添加并修正: 修正无法启动关于画面的问题 + 修正等级 3 断开手机信号没有重新连接的问题 + 添加S2U2的...
7.23 设置录音取样频率与显示录音时间 7.24 EXIF照片信息编辑及读取 7.25 声音音效均衡器、重低音与音场控制 7.26 在自定义的SurfaceView上绘制动画 第8章 当Android与Internet接轨 8.1 HTTP GET/POST传递参数 8.2 ...
7.23 设置录音取样频率与显示录音时间 7.24 EXIF照片信息编辑及读取 7.25 声音音效均衡器、重低音与音场控制 7.26 在自定义的SurfaceView上绘制动画 第8章 当Android与Internet接轨 8.1 HTTP GET/POST传递参数 8.2 ...
7.23 设置录音取样频率与显示录音时间 7.24 EXIF照片信息编辑及读取 7.25 声音音效均衡器、重低音与音场控制 7.26 在自定义的SurfaceView上绘制动画 第8章 当Android与Internet接轨 8.1 HTTP GET/POST传递参数 8.2 ...
7.23 设置录音取样频率与显示录音时间 7.24 EXIF照片信息编辑及读取 7.25 声音音效均衡器、重低音与音场控制 7.26 在自定义的SurfaceView上绘制动画 第8章 当Android与Internet接轨 8.1 HTTP GET/POST传递参数 8.2 ...
6.5.5 定时提醒服务 6.5.6 音频服务 6.5.7 传感器服务 6.5.8 位置服务 6.6 本章小结 第三篇 Android开发基础详解 第7章 常用控件 7.1 Button(按钮) 7.2 ImageButton(图片按钮) 7.3 ToggleButton(开关按钮) 7.4...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
◆ BLE的Notification机制能得知指令是否下达成功且Scatternet的每节点还会定时巡视与下游之间的连接状态,一旦发现失去讯号,讯息就会往上游推送。host因此能确保Scatternet通讯的成功与否。 方案来源于大大通
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.7 图文可视化提醒——Toast与LinearLayoutView 5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——...