Android 发送通知
				
									
					
					
						|  | 
							admin 2013年2月25日 14:43
								本文热度 5559 | 
					
				 
				
实现代码如下,代码中有详细注释:
- public class MainActivity extends Activity {  
-     private TextView tvTitle;  
-     private TextView tvContent;  
-     private Button btnSend;  
-     private String title;  
-     private String content;  
-       
-     public void onCreate(Bundle savedInstanceState) {  
-         super.onCreate(savedInstanceState);  
-         setContentView(R.layout.activity_main);  
-           
-         tvTitle=(TextView) findViewById(R.id.etTitle);  
-         tvContent=(TextView) findViewById(R.id.etContent);  
-         btnSend=(Button) findViewById(R.id.btnSend);  
-   
-         btnSend.setOnClickListener(new OnClickListener(){  
-             public void onClick(View v) {  
-                 send();  
-             }  
-         });  
-           
-     }  
-     public void send(){  
-         title=tvTitle.getText().toString();  
-         content=tvContent.getText().toString();  
-           
-           
-         NotificationManager nm=(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);  
-           
-         Notification n=new Notification(R.drawable.ic_launcher,"通知",System.currentTimeMillis());  
-           
-         Intent intent = new Intent(this, MainActivity.class);  
-         PendingIntent pi= PendingIntent.getActivity(this, 0, intent, 0);  
-         n.setLatestEventInfo(this, title, content, pi);  
-           
-           
-           
-         nm.notify(1, n);  
-     }  
-   
- }  
 
该文章在 2013/2/25 14:43:52 编辑过