- 浏览: 57699 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
cyhcheng:
http://android-sdk-addons.motod ...
android 更新列表 -
cyhcheng:
递归删除.svn文件夹find -name '.svn' |x ...
在ubuntu下安装subversion -
cyhcheng:
http://cssdeck.com/labs/html5-d ...
varnish -
cyhcheng:
http://demo.geo-solutions.it/sh ...
install,create and usetemplate database -
cyhcheng:
入门学习站点:http://ian01.geog.psu.ed ...
install,create and usetemplate database
题外话:在Android中服务必须在Actvity创建后,方可获得,否则会出现错误:java.lang.IllegalStateException: System services not available to Activities before onCreate()。
主要功能:实现在Activity中发出通知、删除通知、在通知中启动Activity
主Activity代码:
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.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class SimpleNotificationActivity extends Activity { private final String notifictionService = Context.NOTIFICATION_SERVICE; private final int icon = R.drawable.icon; private static int createdNums = 0; private final String tickerText = "通知内容:该起床了!"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button startNotificationButton = (Button) findViewById(R.id.startNotificationButton); startNotificationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NotificationManager notificationManager = (NotificationManager) getSystemService(notifictionService); long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); String contentTitle = "学校通知"; String contentText = "6:30分必须起床,否则罚跑操场10圈!!!!!!!!"; //Intent notificationIntent = new Intent(SimpleNotificationActivity.this, SimpleNotificationActivity.class); Intent notificationIntent= new Intent(SimpleNotificationActivity.this,AnotherActivity.class); // PendingIntent contentIntent = // PendingIntent.getActivity(getApplicationContext(), 0, null, // Intent.FLAG_ACTIVITY_NEW_TASK);//不在通知栏启动Activity PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK);// 在通知栏启动Activity,并打开新的Task栈 notification.setLatestEventInfo(SimpleNotificationActivity.this, contentTitle, contentText, contentIntent); notification.defaults |= Notification.DEFAULT_LIGHTS; notificationManager.notify(3, notification); } }); Button removeNotificationButton = (Button) findViewById(R.id.removeNotificationButton); removeNotificationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { NotificationManager notificationManager = (NotificationManager) getSystemService(notifictionService); notificationManager.cancel(3); } }); setTitle("我是第" + createdNums++ + "个对象!!!!!");// 验证由自身跳转回自身的情况:创建新对象 } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { System.out.println("恢复活动状态——如果没有我,用户数据无法恢复,而用户也会出离愤怒"); super.onRestoreInstanceState(savedInstanceState); } @Override protected void onSaveInstanceState(Bundle outState) { System.out.println("保存活动状态——如果我不保存用户数据,你想恢复也恢复不了"); super.onSaveInstanceState(outState); } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { //在模拟器下,大写字母按键的录入捕获的是两个键值(字母键+功能键) System.out.println("用户按下的键是————————————————————————————————————————————————"+keyCode + "、" + event.getDisplayLabel() + "、" + event.getCharacters()); return super.onKeyUp(keyCode, event); } }
辅助Activity代码
import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class AnotherActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); TextView textView=new TextView(this); textView.setText("我是由Notification跳转过来的"); setContentView(textView); } }
布局代码
<?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"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:text="添加通知" android:id="@+id/startNotificationButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> <Button android:text="删除通知" android:id="@+id/removeNotificationButton" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> </LinearLayout> </HorizontalScrollView> </LinearLayout>
- studyNotification.rar (48.3 KB)
- 下载次数: 10
发表评论
-
实现不选择选项则不可以关闭的对话框之方法三
2013-12-25 00:05 585本方法基于Dialog,使用自定义布局,更能满足发杂的需求。 ... -
实现不选择选项则不可以关闭的对话框之方法二
2013-12-24 23:28 719本方法在打开对话框后,如果没有选中项则禁用Positive ... -
实现不选择选项则不可以关闭的对话框之方法一
2013-12-24 23:23 549本方法中,当点击Positive Button时,如果没有选 ... -
Android开发环境搭建
2013-12-17 22:57 624由于本人现在使用mac了,所以特别记录下mac下的几条命令: ... -
关于空指针异常的处理
2013-10-14 10:27 629在Android中使用Log时的处理: I ... -
NDK入门
2013-07-15 16:51 426下载Android SDK、NDK,配置环境变量 新建 ... -
Android 中DatePickerDialog和TimePickerDialog使用旧版的样式
2013-07-11 15:27 2319想在Android3.*+项目中使用Android2.*版 ... -
调用google cloud print
2013-07-04 16:15 1365判断本地是否安装某个应用,如果没有安装,则打开google ... -
调用google translate
2013-07-04 15:21 945Intent i = new Intent(); i.set ... -
读取Tag数据
2013-04-28 15:33 1070import java.io.UnsupportedEnco ... -
向Tag写入数据
2013-04-28 15:24 1509授权: <uses-permission ... -
ubuntu下安装android开发环境
2012-04-11 10:54 818sudo umount /media/cdrom sudo ... -
android 更新列表
2012-04-11 09:18 951https://dl-ssl.google.com/andro ... -
Android常见问题及其解决办法
2012-02-15 13:44 3560今天在向模拟器部署运行项目时碰到下面的异常: [201 ... -
Layout动画入门
2012-02-09 12:02 1333针对Layout或者ViewGroup对象,可以方便的通过xm ... -
逐帧动画入门
2012-02-09 10:58 1075简单来讲,逐帧动画就 ... -
Menu及其自定义皮肤的处理
2011-09-23 09:52 1262SimpleMenuActivity.java代码: ... -
Sqlite入门
2011-09-23 09:35 904在Android下,对Sqlite3进行了封装,使用相对更简单 ... -
CheckBox与ListView的结合方法一
2011-06-03 14:19 1936最近这段时间比较闲,每天都无所事事。不再想重复这样的生 ...
相关推荐
主要介绍了Android中Notification用法,以实例形式较为详细的分析并总结了Notification的功能与使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
目录 安装您需要安装软件包: npm install react-cookie-consent-notification 您可以使用毛线: yarn add react-cookie-consent-notification 入门您应该导入组件: import CookieConsent from 'react-cookie-...
Android入门开发实例--Toast、Notification、Intent应用
本文实例讲述了Android中Notification用法。分享给大家供大家参考,具体如下: Notification可以理解为通知的意思一般用来显示广播信息 用Notification就必须要用到NotificationManager 想用Notification一般有三个...
Google Google.Android开发入门与实战第7章.良好的学习开端——Android基本组件介绍之温馨的提醒——Toast和Notification应用.rar
有关联系跟踪的更多信息,请参见: 内容入门要与您的本机应用程序集成: # with npmnpm install --save react-native-exposure-notification-service# with yarnyarn add react-native-exposure-notification-...
@ react-native-community / push-notification-ios 对iOS的React Native Push Notification API 通知有行动使用TextInput动作入门安装yarn add @react-native-community/push-notification-ios链接React Native v...
专为开发人员设计的库 通过@DanielOX与 :red_heart:入门使用简单。通知面板的[查看][自动检测]用户是否读取了通知?特征您可以传递一个对象您可以传递一个数组自动检测用户是否已阅读通知,然后重置通知计数&&显示...
7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...
19、Notification 状态栏通知 20、GridView、ImageSwitcher 21、SmsManager 消息管理器,发短信(这里是模拟器只能给其它模拟器发短信) 22、Intent Action、Category属性 测试 23、系统 Action、Category属性 24...
《Android从入门到精通》 第1章 初识Android 1.1 什么是Android 1.1.1 移动信息设备分类 1.1.2 Open Handset Alliance和 Android 1.2 Android简介 1.2.1 Andriod的历史 1.2.2 Andriod的未来 1.2.3 Andriod平台的技术...
Windows Azure使用入门 第九课:开发移动应用和通知发送.pdf
flutter_app_notification 一个新的Flutter应用程序。 入门 该项目是Flutter应用程序的起点。 如果这是您的第一个Flutter项目,那么有一些资源可以帮助您入门: 要获得Flutter入门方面的帮助,请查看我们的,其中...
安装与入门 可以使用指定的Xcode版本来构建项目。依赖关系由,无需进一步设置。 调配 为特定的配置文件配置了项目。要将应用安装在自己的设备上,您将必须使用自己的配置文件更新设置。 Apples Exposure ...
7.8 温馨的提醒——Toast和Notification应用 7.8.1 实例操作演示 7.8.2 实例编程实现 7.9 本章小结 第8章 移动信息仓库——Android的数据存储操作 8.1 Android数据存储概述 8.2 轻轻地我保护——SharedPreferences...
通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向 用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现。发出一 条通知后,手机最上方的状态栏中会显示一...
第十九讲:Android Notification的使用入门 第二十讲:Content Provider 使用入门 第二十一讲:Broadcast Receiver 使用入门 第二十二讲:AIDL和远程Service调用 第二十三讲:Drawable使用入门 第二十四讲...
Create React App入门 该项目是通过引导的。 可用脚本 在项目目录中,可以运行: npm start 在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何...