当前位置:  编程技术>移动开发
本页文章导读:
    ▪有个主意和大家交流下        有个想法和大家交流下 我超喜欢dota里面的声音,想将其设为铃声。  比如说超神。 五分钟内第一次收到短信就只放超神的声音          第二次就是先放超神后放双杀        第三次就.........
    ▪ java反照机制详解        java反射机制详解 在Java运行时刻,能否知道一个类的属性方法并调用改动之?对于任意一个对象,能否知道他的所属类,并调用他的方法?答案是肯定的。这种动态的获取信息及动态调用.........
    ▪ Notification应用詳解       Notification使用詳解 当用户有没有接到的电话的时候,Android顶部状态栏里就会出现一个小图标。提示用户有没有处理的快讯,当拖动状态栏时,可以查看这些快讯。Android给我们提供了Notific.........

[1]有个主意和大家交流下
    来源: 互联网  发布时间: 2014-02-18
有个想法和大家交流下


我超喜欢dota里面的声音,想将其设为铃声。 

比如说超神。

五分钟内第一次收到短信就只放超神的声音 
        第二次就是先放超神后放双杀
        第三次就是超神然后三杀
        第四次就是超神加疯狂杀戮 
        第五次就是超神加暴走 

这些声音在网上都能下载到。

我的手机是htc, android2.2的操作系统。

这种应用要是能开发出来,估计会吸引很多魔兽爱好者。
1 楼 zKF43510 2011-07-29  
创意不错,抽个时间写给个apk满足你。
2 楼 pangyi 2011-08-29  
zKF43510 写道
创意不错,抽个时间写给个apk满足你。



呵呵,期待啊。

    
[2] java反照机制详解
    来源: 互联网  发布时间: 2014-02-18
java反射机制详解
在Java运行时刻,能否知道一个类的属性方法并调用改动之?对于任意一个对象,能否知道他的所属类,并调用他的方法?答案是肯定的。这种动态的获取信息及动态调用方法的机制在Java中称为“反射”(reflection)。
Java反射机制主要提供以下功能:
在运行时判断任意一个对象所属的类;
在运行时构造任意一个类的对象;
在运行时判断任意一个类所具有的成员变量和方法;
在运行时调用任意一个对象的方法。
Reflection 是Java被视为动态(或准动态)语言的一个关键性质。这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如public, static 等等)、superclass(例如Object)、实现之interfaces(例如Serializable),也包括fields和methods 的所有信息,并可于运行时改变fields内容或调用methods。
一般而言,开发者社群说到动态语言,大致认同的一个定义是:“程序运行时,允许改变程序结构或变量类型,这种语言称为动态语言”。
在JDK中,主要由以下类来实现Java反射机制,这些类都位于java.lang.reflect包中:
Class类:代表一个类;
Field 类:代表类的成员变量(成员变量也称为类的属性);
Method类:代表类的方法;
Constructor 类:代表类的构造方法;
Array类:提供了动态创建数组,以及访问数组的元素的静态方法;

例程DateMethodsTest类演示了Reflection API的基本作用,它读取命令行参数指定的类名,然后打印这个类所具有的方法信息,代码如下:

Datemethodstest.java代码
public class DateMethodsTest     
{     
public static void main(String args[]) throws Exception     
{     
// 加载并初始化命令行参数指定的类     
Class<?> classType = Class.forName("java.util.Date");     
// 获得类的所有方法     
Method methods[] = classType.getDeclaredMethods();     
for (int i = 0; i < methods.length; i++)     
{     
System.out.println(methods[i].toString());     
}     
}     
}   
例程ReflectTester类进一步演示了Reflection API的基本使用方法。ReflectTester类有一个copy(Object object)方法,这个方法能够创建一个和参数object同样类型的对象,然后把object对象中的所有属性拷贝到新建的对象中,并将它返回这个例 子只能复制简单的JavaBean,假定JavaBean 的每个属性都有public 类型的getXXX()和setXXX()方法,代码如下:

Reflecttester.java代码
public class ReflectTester {     
public Object copy(Object object) throws Exception {     
// 获得对象的类型     
Class<?> classType = object.getClass();     
System.out.println("Class:" + classType.getName());     

// 通过默认构造方法创建一个新的对象     
Object objectCopy = classType.getConstructor(new Class[] {}).newInstance(new Object[] {});     

// 获得对象的所有属性     
Field fields[] = classType.getDeclaredFields();     

for (int i = 0; i < fields.length; i++) {     
Field field = fields[i];     

String fieldName = field.getName();     
String firstLetter = fieldName.substring(0, 1).toUpperCase();     
// 获得和属性对应的getXXX()方法的名字     
String getMethodName = "get" + firstLetter + fieldName.substring(1);     
// 获得和属性对应的setXXX()方法的名字     
String setMethodName = "set" + firstLetter + fieldName.substring(1);     

// 获得和属性对应的getXXX()方法     
Method getMethod = classType.getMethod(getMethodName, new Class[] {});     
// 获得和属性对应的setXXX()方法     
Method setMethod = classType.getMethod(setMethodName, new Class[] { field.getType() });     

// 调用原对象的getXXX()方法     
Object value = getMethod.invoke(object, new Object[] {});     
System.out.println(fieldName + ":" + value);     
// 调用拷贝对象的setXXX()方法     
setMethod.invoke(objectCopy, new Object[] { value });     
}     
return objectCopy;     
}     

public static void main(String[] args) throws Exception {     
Customer customer = new Customer("Tom", 21);     
customer.setId(new Long(1));     

Customer customerCopy = (Customer) new ReflectTester().copy(customer);     
System.out.println("Copy information:" + customerCopy.getId() + " "    
+ customerCopy.getName() + " " + customerCopy.getAge());     
}     
}     

class Customer {     
private Long id;     

private String name;     

private int age;     

public Customer() {     
}     

public Customer(String name, int age) {     
this.name = name;     
this.age = age;     
}     

public Long getId() {     
return id;     
}     

public void setId(Long id) {     
this.id = id;     
}     

public String getName() {     
return name;     
}     

public void setName(String name) {     
this.name = name;     
}     

public int getAge() {     
return age;     
}     

public void setAge(int age) {     
this.age = age;     
}     
}  
ReflectTester 类的copy(Object object)方法依次执行以下步骤:


(1)获得对象的类型:
Class classType=object.getClass();
System.out.println("Class:"+classType.getName());



在java.lang.Object 类中定义了getClass()方法,因此对于任意一个Java对象,都可以通过此方法获得对象的类型。Class类是Reflection API 中的核心类,它有以下方法:
getName():获得类的完整名字;
getFields():获得类的public类型的属性;
getDeclaredFields():获得类的所有属性;
getMethods():获得类的public类型的方法;
getDeclaredMethods():获得类的所有方法;



getMethod(String name, Class[] parameterTypes):获得类的特定方法,name参数指定方法的名字,parameterTypes 参数指定方法的参数类型;

getConstructors():获得类的public类型的构造方法;
getConstructor(Class[] parameterTypes):获得类的特定构造方法,parameterTypes 参数指定构造方法的参数类型;
newInstance():通过类的不带参数的构造方法创建这个类的一个对象;



(2)通过默认构造方法创建一个新对象:
Object objectCopy=classType.getConstructor(new Class[]{}).newInstance(new Object[]{});
以上代码先调用Class类的getConstructor()方法获得一个Constructor 对象,它代表默认的构造方法,然后调用Constructor对象的newInstance()方法构造一个实例。



(3)获得对象的所有属性:
Field fields[]=classType.getDeclaredFields();
Class 类的getDeclaredFields()方法返回类的所有属性,包括public、protected、默认和private访问级别的属性。



(4)获得每个属性相应的getXXX()和setXXX()方法,然后执行这些方法,把原来对象的属性拷贝到新的对象中。



以上是一个反射(reflection)的比较详细的解说,当然真正工程上是不会这样麻烦的,这里是底层的讲解。





以下这个类运用反射机制调用其add()和echo()方法,代码如下:

Invoketester.java代码
import java.lang.reflect.Method;     

public class InvokeTester {     
public int add(int param1, int param2) {     
return param1 + param2;     
}     

public String echo(String msg) {     
return "echo: " + msg;     
}     

public static void main(String[] args) throws Exception {     
Class<?> classType = InvokeTester.class;     
Object invokeTester = classType.newInstance();     

// 调用InvokeTester对象的add()方法     
Method addMethod = classType.getMethod("add", new Class[] { int.class,     
int.class });     
Object result = addMethod.invoke(invokeTester, new Object[] {     
new Integer(100), new Integer(200) });     
System.out.println((Integer) result);     

// 调用InvokeTester对象的echo()方法     
Method echoMethod = classType.getMethod("echo",     
new Class[] { String.class });     
result = echoMethod.invoke(invokeTester, new Object[] { "Hello" });     
System.out.println((String) result);     
}     
}   
add()方法的两个参数为int 类型,获得表示add()方法的Method对象的代码如下:
Method addMethod=classType.getMethod("add",new Class[]{int.class,int.class});
Method类的invoke(Object obj,Object args[])方法接收的参数必须为对象,如果参数为基本类型数据,必须转换为相应的包装类型的对象。invoke()方法的返回值总是对象,如果实际被 调用的方法的返回类型是基本类型数据,那么invoke()方法会把它转换为相应的包装类型的对象,再将其返回。

在本例中,尽管InvokeTester 类的add()方法的两个参数以及返回值都是int类型,调用add Method 对象的invoke()方法时,只能传递Integer 类型的参数,并且invoke()方法的返回类型也是Integer 类型,Integer 类是int 基本类型的包装类:

Object result=addMethod.invoke(invokeTester,
new Object[]{new Integer(100),new Integer(200)});
System.out.println((Integer)result); //result 为Integer类型。



java.lang.Array 类提供了动态创建和访问数组元素的各种静态方法。下面的例子ArrayTester1.java的main()方法创建了一个长度为10 的字符串数组,接着把索引位置为5 的元素设为“hello”,然后再读取索引位置为5 的元素的值,代码如下:

Arraytester1.java代码
import java.lang.reflect.Array;     

public class ArrayTester1     
{     
public static void main(String args[]) throws Exception     
{     
Class<?> classType = Class.forName("java.lang.String");     
// 创建一个长度为10的字符串数组     
Object array = Array.newInstance(classType, 10);     
// 把索引位置为5的元素设为"hello"     
Array.set(array, 5, "hello");     
// 获得索引位置为5的元素的值     
String s = (String) Array.get(array, 5);     
System.out.println(s);     
}     
}  
Java API是个很好的帮助资料,大家可以查阅观看。比如说以上的例子:classType就是String类型的一个对象。通过Array类的 newInstance(类型, 长度)创建了一个长度为10的,类型为String的Array数组。通过Array的get和set方法可以将字符串“hello”插进下标为5(实际 上是Array中第六个元素)的“数组方块”中。



下面例子是一个复杂的多维数组例子,不过只要了解了一维数组,应该不难了解多维数组的。所谓多维数组只是下级数组作为一个“元素”存在于上级数组中。



例程ArrayTester2 类的main()方法创建了一个 5 x 10 x 15 的整型数组,并把索引位置为[3][5][10] 的元素的值为设37,代码如下:

Arraytester2.java代码
import java.lang.reflect.Array;     

public class ArrayTester2     
{     
public static void main(String args[])     
{     
int[] dims = new int[] { 5, 10, 15 };     
Object array = Array.newInstance(Integer.TYPE, dims);     
Object arrayObj = Array.get(array, 3);     
Class<?> cls = arrayObj.getClass().getComponentType();     
System.out.println(cls);     
arrayObj = Array.get(arrayObj, 5);     
Array.setInt(arrayObj, 10, 37);     
int arrayCast[][][] = (int[][][]) array;     
System.out.println(arrayCast[3][5][10]);     
}     
}  

Class是Reflection起源。针对任何您想探勘的class,唯有先为它产生一个Class object,接下来才能经由后者唤起为数十多个的Reflection APIs。



Java允许我们从多种途径为一个class生成对应的Class object。



(一)运用getClass()方法:

String str = "abc";

Class class = str.getClass();



(二)运用Class.getSuperclass()方法:

Button b = new Button();

Class c1 = b.getSuperclass();

Class c2 = c1.getSuperclass();



(三)运用静态方法Class.forName(),这个最常用:

Class c1 = Class.forName("java.lang.String");

Class c2 = Class.forName("java.util.Date");



(四)运用.class语法:

Class c1 = String.class;

Class c2 = java.awt.Button.class;

Class c3 = int.class;

Class C4 = int[].class;



(五)运用原始包装类的TYPE方法:

Class c1 = Integer.TYPE;

Class c2 = Character.TYPE;

Class c3 = Boolean.TYPE;

Class c4 = Void.TYPE;



通过这五种方法,可以生成我们想要的类对象。
____________________________

    
[3] Notification应用詳解
    来源: 互联网  发布时间: 2014-02-18
Notification使用詳解
当用户有没有接到的电话的时候,Android顶部状态栏里就会出现一个小图标。提示用户有没有处理的快讯,当拖动状态栏时,可以查看这些快讯。Android给我们提供了NotificationManager来管理这个状态栏。可以很轻松的完成。
    如果要添加一个Notification,可以按照以下几个步骤
1:获取NotificationManager:
NotificationManager m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
2:定义一个Notification:
  
Notification  m_Notification=new Notification();
3:设置Notification的各种属性:
//设置通知在状态栏显示的图标
m_Notification.icon=R.drawable.icon;
                
//当我们点击通知时显示的内容
m_Notification.tickerText="Button1 
通知内容.....";
                                
通知时发出的默认声音
m_Notification.defaults=Notification.DEFAULT_SOUND;
//设置通知显示的参数
Intent   m_Intent=new Intent(NotificationDemo.this,DesActivity.class);       
PendingIntent m_PendingIntent=PendingIntent.getActivity(NotificationDemo.this, 0, m_Intent, 0);
m_Notification.setLatestEventInfo(NotificationDemo.this, "Button1", "Button1通知",m_PendingIntent );
//这个可以理解为开始执行这个通知
m_NotificationManager.notify(0,m_Notification);
4:既然可以增加同样我们也可以删除。当然是只是删除你自己增加的。
 
 m_NotificationManager.cancel(0);  
  
  这里的0是一个ID号码,和notify第一个参数0一样。
这也就完成了,添加删除工作。
这里我们还是一个Demo来掩饰我们的操作。
1:新建一个工程NotificationDemo。
2:添加一个Activity:DesActivity,注意需要在Manifest.xml中声明
3:NotificationDemo中的Laytout文件很简单就是定义一个Button.其代码文件如下:
1.
package com.rocky.studio.ch4221;
2.	import android.app.Activity;
3.	import android.app.Notification;
4.	import android.app.NotificationManager;
5.	import android.app.PendingIntent;
6.	import android.content.Intent;
7.	import android.os.Bundle;
8.	import android.view.View;
9.	import android.widget.Button;
10.	import android.widget.TextView;
11.	public class NotificationDemo extends Activity {
12.	
13.	Button m_Button1;
14.	TextView m_txtView;
15.	
16.	NotificationManager m_NotificationManager;
17.	Notification m_Notification;
18.	
19.	Intent m_Intent;
20.	PendingIntent m_PendingIntent;
21.	  
22.	    /** Called when the activity is first created. */
23.	    @Override
24.	    public void onCreate(Bundle savedInstanceState) {
25.	        super.onCreate(savedInstanceState);
26.	        setContentView(R.layout.main);
27.	        
28.	        m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
29.	        
30.	                
31.	        m_Button1=(Button)this.findViewById(R.id.Button01);
32.	       
33.	        
34.	        //点击通知时转移内容
35.	        m_Intent=new Intent(NotificationDemo.this,DesActivity.class);
36.	        
37.	        m_PendingIntent=PendingIntent.getActivity(NotificationDemo.this, 0, m_Intent, 0);
38.	        
39.	        m_Notification=new Notification();
40.	        
41.	        m_Button1.setOnClickListener(new Button.OnClickListener(){
42.	   public void onClick(View v) {
43.	    // TODO Auto-generated method stub
44.	    
45.	    //设置通知在状态栏显示的图标46.	
47.	    m_Notification.icon=R.drawable.icon;
48.	    
49.	    //当我们点击通知时显示的内容
50.	    m_Notification.tickerText="Button1 通知内容.....";
51.	        
52.	    //通知时发出的默认声音
53.	    m_Notification.defaults=Notification.DEFAULT_SOUND;
54.	    
55.	    //设置通知显示的参数
56.	    m_Notification.setLatestEventInfo(NotificationDemo.this, "Button1", "Button1通知",m_PendingIntent );
57.	    
58.	    //这个可以理解为开始执行这个通知
59.	    m_NotificationManager.notify(0,m_Notification);
60.	    
61.	   }});
62.	        
63.	    }
64.	    
65.	    
66.	}


4:修改DesActivity 的源文件,代码如下:它做的事情就是取消之前添加的Notification

1.
package com.rocky.studio.ch4221;
2.	import android.app.Activity;
3.	import android.app.NotificationManager;
4.	import android.os.Bundle;
5.	public class DesActivity extends Activity {
6.	
7.	NotificationManager m_NotificationManager;
8.	
9.	@Override
10.	protected void onCreate(Bundle savedInstanceState) {
11.	  // TODO Auto-generated method stub
12.	   super.onCreate(savedInstanceState);  
13.	   this.setContentView(R.layout.main2);
14.	   
15.	   //启动后删除之前我们定义的
16.	   m_NotificationManager=(NotificationManager)this.getSystemService(NOTIFICATION_SERVICE);
17.	   m_NotificationManager.cancel(0);   
18.	}
19.	
20.	}
复制代码
代码也很简单。可以查看Notification , NotificationMananger 这两个类来学习前后左右。
下面是一篇文章,对Notification ,NotificationManager这两个类有详细的说明介绍,特借鉴一下。
NoticificationManager很容易可以放在状态栏,也很容易实现从statusbar进入程序 中, 
NoticificationManager中通过intent执行此程序的activity就可以了 

NoticificationManager状态栏操作 

NotificationManager(通知管理器): 
NotificationManager负责通知用户事件的发生. 
NotificationManager有三个公共方法: 
1. cancel(int id) 取消以前显示的一个通知.假如是一个短暂的通知,试图将隐藏,假如是一个持久的通知,将从状态条中移走. 
2. cancelAll() 取消以前显示的所有通知. 
3. notify(int id,  Notification notification) 把通知持久的发送到状态条上. 


//初始化NotificationManager: 
NotificationManager nm = 
      (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
Notification代表着一个通知. 
Notification的属性: 
audioStreamType 当声音响起时,所用的音频流的类型 
contentIntent 当通知条目被点击,就执行这个被设置的Intent. 
contentView 当通知被显示在状态条上的时候,同时这个被设置的视图被显示. 
defaults 指定哪个值要被设置成默认的. 
deleteIntent 当用户点击"Clear All Notifications"按钮区删除所有的通知的时候,这个被设置的Intent被执行. 
icon 状态条所用的图片. 
iconLevel 假如状态条的图片有几个级别,就设置这里. 
ledARGB LED灯的颜色. 
ledOffMS LED关闭时的闪光时间(以毫秒计算) 
ledOnMS LED开始时的闪光时间(以毫秒计算) 
number 这个通知代表事件的号码 
sound 通知的声音 
tickerText 通知被显示在状态条时,所显示的信息 
vibrate 振动模式. 
when 通知的时间戳. 

将Notification发送到状态条上: 
Notification notification = new Notification(); 
Notification的设置过程…….. 
nm.notify(0, notification);   //发送到状态条上 

创建和触发Notification 

创建和配置新的Notification需要经历三步。 
   
  首先,你要创建一个新的Notification对象,传入要在状态条上显示的图 标、文字和Notification的 当前时间,如下面的代码片段所示: 
   
  // Choose a drawable to display as the status bar icon 
  int icon = R.drawable.icon; 
   
  // Text to display in the status bar when the notification is launched 
  String tickerText = “Notification”; 
   
  // The extended status bar orders notification in time order 
  long when = System.currentTimeMillis(); 
  Notification notification = new Notification(icon, tickerText, when); 
   
  当Notification触发时,文本将沿着状态条进行滚动 显示。 

其次,使用setLatestEventInfo方法来配置Notification在扩展的状态窗口中的外观。扩展的状态窗口将显示图标和在构造函数中传入的时间,以及显示标题和一个详细的字符串。Notification一般表示为对一个动作的请求或引起用户的注意,所以,当用户点击Notification项目时你可以指定一个PendingIntent来触发。 
   
  下面的代码片段使用了setLastestEventInfo来设置这些值: 
   
  
Context context = getApplicationContext(); 
   
  // Text to display in the extended status window 
  String expandedText = “Extended status text”; 
   
  // Title for the expanded status 
  String expandedTitle = “Notification Title”; 
   
  // Intent to launch an activity when the extended text is clicked 
  Intent intent = new Intent(this, MyActivity.class); 
  PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0); 
  notification.setLatestEventInfo(context, 
expandedTitle, 
expandedText, 
launchIntent); 
   
  一个好的形式是显示相同事件(例如,接 收多个SMS消息)的多个对象时 使用一个Notification图 标。为了呈现给用户,使用setLastestEventInfo更新数据集来呈现最近的消息以及重新触发Notification来更新它的值。 
   
  你还可以使用number属性来显示一个状态条图标所表示的事件数目。 
   
  设置为比1大的数,如下所示,将在状态条图标上以一个小小的数字进行 显示: 
   
  notification.number++; 
   
  任何对Notification的变更,你都需要重新触发来进行更 新。如果要删除这个数字,设置number的值为0或者-1。 
   
  最后,你可以对Notification对象使用多种属性来增强Notification的效果,如闪烁LED、震动电话和播放音乐文件。这些高级特征将在本章的后面部分进行详细描述。 
   
  触发Notification 
   
  为了触发一个Notification,使用NotificationManager的notify方法,将一个整数的ID和Notification对象传入,如下的片段所示: 
   
  
int notificationRef = 1; 
  notificationManager.notify(notificationRef, notification); 
   
  为了更新一个已经触发过的Notification,传入相同的ID。你既可以传入相同的Notification对象,也可以是一个全新的对象。只 要ID相同,新的Notification对象会替换状态条 
图标和扩展的状态窗口的细节。 
   
  你还可以使用ID来取消Notification,通过调用NotificationManager的cancel方法,如下所示: 
   
 
 notificationManager.cancel(notificationRef); 
   
  取消一个Notification时,将移除它的状态条图标以及清除 在扩展的状态窗口中的信息。 


Notification和NotificationManager的基本使用方法 

1. NotificationManager和Notification用来设置通知。 

通知的设置等操作相对比较简单,基本的使用方式就是用新建一个Notification对象,然后设置好通知的各项参数,然后使用系统后台运行的 NotificationManager服务将通知发出来。 

基本步骤如下: 

1)得到NotificationManager: 

String ns = Context.NOTIFICATION_SERVICE; 

NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); 



2)创建一个新的Notification对象: 

Notification notification = new Notification(); 

notification.icon = R.drawable.notification_icon; 



也可以使用稍微复杂一些的方式创建Notification: 

int icon = R.drawable.notification_icon; //通知图标 

CharSequence tickerText = "Hello";  //状态栏(Status Bar)显示的通知文本提示 

long when = System.currentTimeMillis(); //通知产生的时间,会在通知信息里显示 

Notification notification = new Notification(icon, tickerText, when); 


3)填充Notification的各个属性: 

Context context = getApplicationContext(); 

CharSequence contentTitle = "My notification"; 

CharSequence contentText = "Hello World!"; 

Intent notificationIntent = new Intent(this, MyClass.class); 

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

Notification提供了丰富的手机提示方式: 

a)在状态栏(Status Bar)显示的通知文本提示,如: 

notification.tickerText = "hello"; 


b)发出提示音,如: 

notification.defaults |= Notification.DEFAULT_SOUND; 

notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3"); 

notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6"); 


c)手机振动,如: 

notification.defaults |= Notification.DEFAULT_VIBRATE; 

long[] vibrate = {0,100,200,300}; 

notification.vibrate = vibrate; 

d)LED灯闪烁,如: 

notification.defaults |= Notification.DEFAULT_LIGHTS; 

notification.ledARGB = 0xff00ff00; 

notification.ledOnMS = 300; 

notification.ledOffMS = 1000; 

notification.flags |= Notification.FLAG_SHOW_LIGHTS; 

4)发送通知: 

private static final int ID_NOTIFICATION = 1; 

mNotificationManager.notify(ID_NOTIFICATION, notification); 


2. 通知的更新 

   如果需要更新一个通知,只需要在设置好notification之后,再调用setLatestEventInfo,然后重新发送一次通知即可。

    
最新技术文章:
▪Android开发之登录验证实例教程
移动开发 iis7站长之家
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3