android notification 的例子

public class SimpleNotification extends Activity { 
    
   private NotificationManager mNotificationManager; 
   private int SIMPLE_NOTFICATION_ID; 
    
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
        
        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
      final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis()); 
       

        Button start = (Button)findViewById(R.id.notifyButton); 
        Button cancel = (Button)findViewById(R.id.cancelButton); 
        
        start.setOnClickListener(new OnClickListener() { 
            
           public void onClick(View v) { 
               
               
              Context context = getApplicationContext(); 
              CharSequence contentTitle = "Notification Details..."; 
              CharSequence contentText = "Browse Android Official Site by clicking me"; 
              Intent notifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://www.android.com")); 
              PendingIntent intent = 
                 PendingIntent.getActivity(SimpleNotification.this, 0, 
                 notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK); 
               
              notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent); 
              mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails); 
           } 
        }); 
        
        cancel.setOnClickListener(new OnClickListener() { 
            
           public void onClick(View v) { 
               
              mNotificationManager.cancel(SIMPLE_NOTFICATION_ID); 
           } 
        }); 
    } 
}

 

//hello word级别的例子。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值