public void sendNotification(Context context, String toast){ Notification notification = new Notification(android.R.drawable.ic_notification_overlay, toast, System.currentTimeMillis()); //建立通知,arg1是通知的圖標,arg2是通知的概要,arg3是通知的時間 Intent notificationIntent = new Intent(context, RemoteMp3ListActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 100, notificationIntent, 0); //點擊通知,執行startActivityForResult, arg2是requestCode, arg3是執行的intent notification.setLatestEventInfo(context, context.getPackageName(), toast, contentIntent); //通知的具體信息. arg2是通知的標題,arg3是通知的內容,arg4是點擊後的執行操做 notification.flags = Notification.FLAG_AUTO_CANCEL; //點擊後自動消失 NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); //狀態欄通知服務 notificationManager.notify( 100, notification);//發送通知, id是爲通知設置編號 System.out.println("notification>>>>"); }