一些API的使用

本文深入探讨了Android服务的生命周期管理、全屏显示、通知提示等关键特性,包括如何停止服务及其对startId的影响,以及如何在服务运行期间展示通知。详细介绍了设置屏幕属性、停止服务的方法和通知系统的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   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);
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值