Paint paint = new Paint();
// setColor 须在 setAlpha 方法之前设置,原因请参见 Android API
paint.setColor(Color.GRAY);
// 值越大越不透明
paint.setAlpha(255);
//取得屏幕分辨率
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
// 去掉标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 设置为全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 如何一个 service 被调用很多次,即 onStartCommand() 响应过很多个请求,
// 那么会相应的产生很多个 startId,比如:1,2,3 三个
// 那么,stopSelfResult(int startId) 只会在参数为 3 的时候才会真正地停止这个服务
// 另外,stopSelf() 是stopSelfResult()的老版本,推荐使用新版本
boolean result = stopSelfResult(msg.arg1);
/**
* Show a notification while this service is running.
*/
private void showNotification() {
// In this sample, we'll use the same text for the ticker and the expanded notification
CharSequence text = getText(R.string.local_service_started);
// Set the icon, scrolling text and timestamp
Notification notification = new Notification(R.drawable.stat_sample, text,
System.currentTimeMillis());
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, LocalServiceActivities.Controller.class), 0);
// Set the info for the views that show in the notification panel.
notification.setLatestEventInfo(this, getText(R.string.local_service_label),
text, contentIntent);
// Send the notification.
// We use a layout id because it is a unique number. We use it later to cancel.
mNM.notify(R.string.local_service_started, notification);
}