Notification 详细运用
2012-09-05 14:04:01 来源:WEB开发网package com.example.noti;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends
Activity {
@Override
public void onCreate(
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//NotificationManager获取NOTIFICATION_SERVICE
final NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
findViewById(R.id.button1)
.setOnClickListener(
new OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(
View v) {
// TODO Auto-generated method stub
//创建一个Notification
Notification notification = new Notification();
//状态栏显示信息
notification.icon = R.drawable.ic_launcher;
notification.tickerText = "This is test notification55555";
notification.vibrate = new long[] {
0,
100,
200,
300 };
//系统铃声
String ringname = RingtoneManager
.getActualDefaultRingtoneUri(
MainActivity.this,
RingtoneManager.TYPE_RINGTONE)
.toString();
notification.sound = Uri
.parse(ringname);
//闪光灯
notification.ledOnMS=300;
notification.ledOffMS=1000;
//切换到另一个ACTIVITY
PendingIntent pendingIntent = PendingIntent
.getActivity(
MainActivity.this,
0,
new Intent(
MainActivity.this,
MainActivity.class),
0);
//信息
notification
.setLatestEventInfo(
MainActivity.this,
"NOTIFICATION",
"This is test notification",
pendingIntent);
notificationManager
.notify(0,
notification);
}
});
}
@Override
public boolean onCreateOptionsMenu(
Menu menu) {
getMenuInflater().inflate(
R.menu.activity_main,
menu);
return true;
}
}
Tags:Notification 详细 运用
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接