Android开发学习笔记-关于Android的消息推送以及前后台切换
下面是最简单的Android的消息推送的实现方法
package com.example.shownotic; import java.util.Random; import android.support.v7.app.ActionBarActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore.Audio.Media;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast; public class MainActivity extends ActionBarActivity { private static final int STATUS_BAR_ID = 0;
Button btnShowNotic = null;
private Random random = new Random(20);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnShowNotic = (Button) findViewById(R.id.btnShowNotic);
btnShowNotic.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
new Thread(new Runnable() {
public void run() {
while(true)
{
SystemClock.sleep(30000);
showNotic();
}
}
}).start();
showNotic();
} });
}
private void showNotic() {
NotificationManager notificationManger = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Gigade";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon , tickerText , when );
notification.flags = Notification.FLAG_AUTO_CANCEL; CharSequence contentText = "show:"+random.nextInt(30);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_WEB_SEARCH);
intent.setData(Uri.parse("http://www.baidu.com"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent , 0);
notification.setLatestEventInfo(this, getTitle(), contentText , contentIntent ); notificationManger.notify(0, notification ); } }
Android开发学习笔记-关于Android的消息推送以及前后台切换的更多相关文章
- android开发学习笔记000
使用书籍:<疯狂android讲义>——李刚著,2011年7月出版 虽然现在已2014,可我挑来跳去,还是以这本书开始我的android之旅吧. “疯狂源自梦想,技术成就辉煌.” 让我这个 ...
- Android开发学习之路--Android Studio cmake编译ffmpeg
最新的android studio2.2引入了cmake可以很好地实现ndk的编写.这里使用最新的方式,对于以前的android下的ndk编译什么的可以参考之前的文章:Android开发学习之路– ...
- Android开发学习之路--Android系统架构初探
环境搭建好了,最简单的app也运行过了,那么app到底是怎么运行在手机上的,手机又到底怎么能运行这些应用,一堆的电子元器件最后可以运行这么美妙的界面,在此还是需要好好研究研究.这里从芯片及硬件模块-& ...
- 【Android开发学习笔记】【第四课】基础控件的学习
通过一个简单的例子来学习下面几种控件: 1.TextView:简单的文本显示控件 2.EditText:可以编辑的文本框 3.Button:按钮 4.Menu:这里指的是系统的Menu 5.Toast ...
- android开发学习笔记系列(1)-android起航
前言 在学习安卓的过程中,我觉得非常有必要将自己所学的东西进行整理,因为每每当我知道我应该是如何去实现功能的时候,有许多细节问题我总是会遗漏,因此我也萌生了写一系列博客来描述自己学习的路线,让我的an ...
- 【转】Android开发学习笔记(一)——初识Android
对于一名程序员来说,“自顶向下”虽然是一种最普通不过的分析问题和解决问题的方式,但其却是简单且较为有效的一种.所以,将其应用到Android的学习中来,不至于将自己的冲动演变为一种盲目和不知所措. 根 ...
- Android开发学习笔记DDMS的使用
打开DDMS DDMS 的全称是Dalvik Debug Monitor Service,是 Android 开发环境中的Dalvik虚拟机调试监控服务. DDMS里面包含了:Device(设备) F ...
- 【Android开发学习笔记】【高级】【随笔】插件化——Activity生命周期
前言 如同第一章我们说的,宿主程序通过 dexclassloader 将插件的类加载进来,然后通过反射去调用它的方法,这样Activity就被当成了一个普通的类来执行了,因此系统不再接管它的生命周期, ...
- 【Android开发学习笔记】【第八课】五大布局-下
概念 五大布局上一篇文章已经介绍了 LinearLayout RelativeLayout 这一篇我们介绍剩下的三种布局 FrameLayout 五种布局中最佳单的一种布局.在这个布局在整个界面被当成 ...
随机推荐
- Creating a Physical Standby Database 11g
1.Environment Item Primary database standby database Platform Redhat 5.4 Redhat 5.4 Hostname gc1 gc2 ...
- strace命令学习
跟踪一个php程序的运行: strace -s 1000 -f -o test.log php test.php 对于守护进程(后台一直跑的进程) php test.php & 得到它的P ...
- Linux系统中的以太网连接
1.在Linux中,以太网连接接口被命令为:eth0,eth1等,其中0,1表示网卡编号. 2.lspci来查看网卡硬件信息(USB则是lsusb) 3.ifconfig来查看接口信息 ifconfi ...
- 【oneday_onepage】—— 日常用语
what do you do for living? 一般用在问对方的工作.如果直接说“what is your job?”会显得有点生硬了. i was wondering if you can t ...
- 【javascript】js 检验密码强度
最近一直在做通行证项目,里面的注册模块中输入密码需要显示密码强度(低中高).今天就把做的效果给大家分享下,代码没有网上搜索的那么复杂,能够满足一般的需求. html 代码如下: <!DOCTYP ...
- 逐行分析jQuery源码
注意:本次源码分析选择2.0.3(因为不支持IE6.7.8,就少了很多兼容的hack的写法,对了解jQuery的实现原理有很大的帮助) 1.jQuery有不同的版本,从2.x版本便不再支持IE6.7. ...
- CATALINA_BASE与CATALINA_HOME的区别
http://blog.csdn.net/keda8997110/article/details/21400455 —————————————————————————————————————————— ...
- JQ 点击指定文本框显示div。点击其他区域隐藏DIV
<input id="username" type="text" style="width:90%;margin-top: 40px;" ...
- Linux共享库 base64库
base64网上实现很多,但是如果是对中文进行编码,有的无法编码,有的编码结果不一致 经过研究,发现base64算法都没有问题,问题出现在汉字的编码上,下面的base64编码稍微做了一些改进,增加了编 ...
- Kafka设计解析(二):Kafka High Availability (上)
转自:http://www.infoq.com/cn/articles/kafka-analysis-part-2/ Kafka在0.8以前的版本中,并不提供High Availablity机制,一旦 ...