notification

package cn.itcast.notifaction;

import java.io.File;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class DemoActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    public void click(View view){
    	//1.Get a reference to the NotificationManager:
    	// 得到一个notification的服务 
    	NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        
       // 2.Instantiate the Notification:
	   //tickertext 冒出来的文字
    	Notification notification = new Notification(R.drawable.ic_launcher, "tickertext", System.currentTimeMillis());
    
    	notification.sound= Uri.fromFile(new File("/sdcard/haha.mp3"));
    	notification.flags = Notification.FLAG_NO_CLEAR;
    	//3.Define the notification's message and PendingIntent:
    	Intent intent = new Intent(this,DemoActivity.class);
		//contentIntent
    	 PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
		 
    	notification.setLatestEventInfo(this, "notife 标题", "noti 正文", contentIntent);
    
    	//4.Pass the Notification to the NotificationManager:
    	manager.notify(0, notification);
    }
}

你可能感兴趣的:(notification)