android 定位

2024-06-21 15:38
文章标签 android 定位

本文主要是介绍android 定位,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

android 定位

参考:
android.location:https://developer.android.com/reference/android/location/package-summary.html
Location and Maps:https://developer.android.com/guide/topics/location/index.html#location
Location Strategies:https://developer.android.com/guide/topics/location/strategies.html
Location:https://developer.android.com/reference/android/location/Location.html


下面介绍基于android框架APIs - android.location的定位。


android定位框架 - android.location

有两种定位的方式:
1.基于GPS定位;
2.基于网络定位。

GPS定位的 好处 :精确度高; 坏处 :仅能在户外使用,获取定位信息速度慢,耗费电池。
网络定位的 好处 :户内户外都能使用,定位速度快,电量耗费低; 坏处 :精确度不太高。

我们可以综合使用两种定位方式,也可以单独使用其中一种

关键组件

LocationManager

android原生定位框架的核心组件是
LocationManager
系统服务,获取这个组件并不需要实例化,通常是通过函数
getSystemService(Context.LOCATION_SERVICE)
获得,该函数会返回一个LocationManager的实例,示例代码如下:

// Acquire a reference to the system Location Manager

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);

LocationListener

通过回调(callback)来获取用户定位信息,首先我们需要通过新建一个
LocationListener
类,并实现其中的几个回调方法,示例代码如下:

// Define a listener that responds to location updates
LocationListener locationListener = new LocationListener() {public void onLocationChanged(Location location) {// Called when a new location is found by the network location provider.// 这个函数中的location就是获取到的位置信息}public void onStatusChanged(String provider, int status, Bundle extras) {}public void onProviderEnabled(String provider) {}public void onProviderDisabled(String provider) {}};    

同时我们需要调用函数 requestLocationUpdates 绑定

LocationManager和LocationListener,示例代码如下:  // Register the listener with the Location Manager to receive location updateslocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);

参数介绍:
第一个参数表示定位提供商的类型(the type of location provider),可以是
GPS_PROVIDER
或者
NETWORK_PROVIDER;
第二个参数表示更新定位信息的最短时间间隔;
第三个参数表示更新定位信息的最短改变距离;
第四个参数就是LocationListener实例。
注:如果第二个和第三个参数均为0表示尽可能快的更新定位信息

如果你想要获取同时使用两种定位方式,那么需要使用两次 requestLocationUpdate 函数,示例代码如下:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 

Location

这是一个数据类,保存了定位的信息,在

public void onLocationChanged(Location location)

中得到的location就是最新的定位信息,其中包括了维度(latitude),经度(longitude)等位置信息。

定位权限

定位功能的使用需要获取定位权限
如果使用 NETWORK_PROVIDER ,那么需要请求

android.permission.ACCESS_COARSE_LOCATION

如果使用 GPS_PROVIDER 或者同时使用上述两种定位方式,那么需要请求

android.permission.ACCESS_FINE_LOCATION

同时,如果你的app的运行环境是Android 5.0(API Level 21)或更高(If your app targets Android 5.0 (API level 21) or higher),那么你还需要显式请求

android.hardware.location.network
或者
android.hardware.location.gps

示例代码如下:

<manifest ... >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
...
<!-- Needed only if your app targets Android 5.0 (API level 21) or higher. -->
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />
...
</manifest>

同时当你的运行环境大于等于Android 6.0(API Level 23),你还需要在代码中显式进行权限检查,本次示例代码如下:

if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;
}
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;
}
示例

下面展示一个简单的应用示例:

新建一个工程LocationTest,使用默认Activity

MainActivity.java代码如下:

package com.zj.location;import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;public class MainActivity extends AppCompatActivity {private static final String TAG = MainActivity.class.getSimpleName();private LocationManager locationManager;private LocationListener locationListener;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);locationListener = new LocationListener() {@Overridepublic void onLocationChanged(Location location) {Log.d(TAG, "onLocationChanged: ");Log.d(TAG, "onLocationChanged: latitude = "+location.getLatitude());Log.d(TAG, "onLocationChanged: longitude = "+location.getLongitude());Log.d(TAG, "onLocationChanged: provider = "+location.getProvider());}@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {}@Overridepublic void onProviderEnabled(String provider) {}@Overridepublic void onProviderDisabled(String provider) {}};if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;}if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;}locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);}
}

同时请求GPS定位信息以及Network定位信息,在 AndroidManifest.xml 中加入:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.location.network" />

运行结果如下:

01-26 21:20:16.234 24056-24099/com.zj.location I/OpenGLRenderer: Initialized EGL, version 1.4
01-26 21:20:16.375 24056-24056/com.zj.location D/MainActivity: onLocationChanged: 
01-26 21:20:16.376 24056-24056/com.zj.location D/MainActivity: onLocationChanged: latitude = 28.991173
01-26 21:20:16.376 24056-24056/com.zj.location D/MainActivity: onLocationChanged: longitude = 120.254411
01-26 21:20:16.376 24056-24056/com.zj.location D/MainActivity: onLocationChanged: provider = network
01-26 21:20:46.471 24056-24056/com.zj.location D/MainActivity: onLocationChanged: 
01-26 21:20:46.471 24056-24056/com.zj.location D/MainActivity: onLocationChanged: latitude = 28.991173
01-26 21:20:46.472 24056-24056/com.zj.location D/MainActivity: onLocationChanged: longitude = 120.254411
01-26 21:20:46.472 24056-24056/com.zj.location D/MainActivity: onLocationChanged: provider = network 

在logcat中显示出了手机的经纬度以及信息提供方

获取定位信息过程中遇到的问题

在android的官方文档中提到,获取到的定位信息可能包含错误或者存在精度问题

Challenges in Determining User Location

里面提到了3种原因:

  • 多个定位源(Multitude of location sources)
  • 手机的移动(User movement)
  • 定位信息的精度问题(Varying accuracy)
创建最佳体验的定位模型

需要考虑下面几个问题

什么时候开始

长时间的监听定位更新会耗费大量的电量,但是,如果监听时间太短可能会导致定位精度问题。
开始监听定位更新是通过调用函数 requestLocationUpdates ,示例代码如下:

String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or, use GPS location data:
// String locationProvider = LocationManager.GPS_PROVIDER;locationManager.requestLocationUpdates(locationProvider, 0, 0, locationListener);

获取最后已知的定位信息

在开始监听定位到获取到第一个定位信息可能会需要一段较长的时间,你可以利用函数 getLastKnownLocation 先获取一个缓存的定位信息,示例代码如下:

String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDERLocation lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);  

注:这个定位信息有可能并不准确,也有可能和真正的位置一致

什么时候结束监听

因为长时间的监听定位会耗费大量的电量,所以当使用完定位功能后,可以手动移除定位监听,示例代码如下:

// Remove the listener you previously added
locationManager.removeUpdates(locationListener);

获取最佳定位

并不是最新得到的定位信息就是最好的,因为存在精度问题,可能最新获取的定位信息在精度和时间上并不是最好的,官方文档提到了几种方法来获取最佳的定位信息:

  • 判断获取到的定位信息是否比当前定位信息更新(Check if the location retrieved is significantly newer than the previous estimate.)
  • 判断获取到的定位信息的精度是否比当前定位信息更好(Check if the accuracy claimed by the location is better or worse than the previous estimate.)
  • 判断获取到的定位信息的提供商是否是你更加信任的(Check which provider the new location is from and determine if you trust it more.)

官方的示例代码如下:

private static final int TWO_MINUTES = 1000 * 60 * 2;/** Determines whether one Location reading is better than the current Location fix* @param location  The new Location that you want to evaluate* @param currentBestLocation  The current Location fix, to which you want to compare the new one*/
protected boolean isBetterLocation(Location location, Location currentBestLocation) {if (currentBestLocation == null) {// A new location is always better than no locationreturn true;}// Check whether the new location fix is newer or olderlong timeDelta = location.getTime() - currentBestLocation.getTime();boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;boolean isNewer = timeDelta > 0;// If it's been more than two minutes since the current location, use the new location// because the user has likely movedif (isSignificantlyNewer) {return true;// If the new location is more than two minutes older, it must be worse} else if (isSignificantlyOlder) {return false;}// Check whether the new location fix is more or less accurateint accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());boolean isLessAccurate = accuracyDelta > 0;boolean isMoreAccurate = accuracyDelta < 0;boolean isSignificantlyLessAccurate = accuracyDelta > 200;// Check if the old and new location are from the same providerboolean isFromSameProvider = isSameProvider(location.getProvider(),currentBestLocation.getProvider());// Determine location quality using a combination of timeliness and accuracyif (isMoreAccurate) {return true;} else if (isNewer && !isLessAccurate) {return true;} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {return true;}return false;
}/** Checks whether two providers are the same */
private boolean isSameProvider(String provider1, String provider2) {if (provider1 == null) {return provider2 == null;}return provider1.equals(provider2);
}
示例2

利用上面提到的策略,修改代码

MainActivity.java代码如下:

package com.zj.location;import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;public class MainActivity extends AppCompatActivity {private static final String TAG = MainActivity.class.getSimpleName();private static final int TWO_MINUTES = 1000 * 60 * 2;private final String NetworkProvider = LocationManager.NETWORK_PROVIDER;private final String GpsProvider = LocationManager.GPS_PROVIDER;private Location currentLocation;private LocationManager locationManager;private LocationListener locationListener;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);locationListener = new LocationListener() {@Overridepublic void onLocationChanged(Location location) {Log.d(TAG, "onLocationChanged: ");if (isBetterLocation(location, currentLocation)) {currentLocation = location;showLocation(currentLocation);}}@Overridepublic void onStatusChanged(String provider, int status, Bundle extras) {}@Overridepublic void onProviderEnabled(String provider) {}@Overridepublic void onProviderDisabled(String provider) {}};if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;}if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {return ;}Location lastKnownGpsLocation = locationManager.getLastKnownLocation(GpsProvider);Location lastKnownNetworkLocation = locationManager.getLastKnownLocation(NetworkProvider);showLocation(lastKnownGpsLocation);showLocation(lastKnownNetworkLocation);locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);}private void showLocation(Location location) {if (location == null) {Log.e(TAG, "showLocation: location == null");return ;}Log.d(TAG, "latitude = "+location.getLatitude());Log.d(TAG, "longitude = "+location.getLongitude());Log.d(TAG, "provider = "+location.getProvider());}/** Determines whether one Location reading is better than the current Location fix* @param location  The new Location that you want to evaluate* @param currentBestLocation  The current Location fix, to which you want to compare the new one*/protected boolean isBetterLocation(Location location, Location currentBestLocation) {if (currentBestLocation == null) {// A new location is always better than no locationreturn true;}// Check whether the new location fix is newer or olderlong timeDelta = location.getTime() - currentBestLocation.getTime();boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;boolean isNewer = timeDelta > 0;// If it's been more than two minutes since the current location, use the new location// because the user has likely movedif (isSignificantlyNewer) {return true;// If the new location is more than two minutes older, it must be worse} else if (isSignificantlyOlder) {return false;}// Check whether the new location fix is more or less accurateint accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());boolean isLessAccurate = accuracyDelta > 0;boolean isMoreAccurate = accuracyDelta < 0;boolean isSignificantlyLessAccurate = accuracyDelta > 200;// Check if the old and new location are from the same providerboolean isFromSameProvider = isSameProvider(location.getProvider(),currentBestLocation.getProvider());// Determine location quality using a combination of timeliness and accuracyif (isMoreAccurate) {return true;} else if (isNewer && !isLessAccurate) {return true;} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {return true;}return false;}/** Checks whether two providers are the same */private boolean isSameProvider(String provider1, String provider2) {if (provider1 == null) {return provider2 == null;}return provider1.equals(provider2);}
}

logcat 信息显示如下:

1-27 13:12:03.714 31281-31281/? V/BoostFramework: mReleaseFunc method = public int com.qualcomm.qti.Performance.perfLockRelease()
01-27 13:12:03.714 31281-31281/? V/BoostFramework: mAcquireTouchFunc method = public int com.qualcomm.qti.Performance.perfLockAcquireTouch(android.view.MotionEvent,android.util.DisplayMetrics,int,int[])
01-27 13:12:03.714 31281-31281/? V/BoostFramework: mIOPStart method = public int com.qualcomm.qti.Performance.perfIOPrefetchStart(int,java.lang.String)
01-27 13:12:03.714 31281-31281/? V/BoostFramework: mIOPStop method = public int com.qualcomm.qti.Performance.perfIOPrefetchStop()
01-27 13:12:03.716 31281-31281/? V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@71e6aaa
01-27 13:12:03.753 31281-31281/com.zj.location W/System: ClassLoader referenced unknown path: /data/app/com.zj.location-1/lib/arm64
01-27 13:12:03.768 31281-31281/com.zj.location W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-27 13:12:03.790 31281-31281/com.zj.location V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@be3f850
01-27 13:12:03.790 31281-31281/com.zj.location V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@3994a49
01-27 13:12:03.812 31281-31281/com.zj.location E/MainActivity: showLocation: location == null
01-27 13:12:03.812 31281-31281/com.zj.location D/MainActivity: latitude = 28.991141
01-27 13:12:03.812 31281-31281/com.zj.location D/MainActivity: longitude = 120.25443
01-27 13:12:03.812 31281-31281/com.zj.location D/MainActivity: provider = network
01-27 13:12:03.839 31281-31301/com.zj.location D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-27 13:12:03.850 31281-31281/com.zj.location D/ActivityThreadInjector: clearCachedDrawables.
01-27 13:12:03.897 31281-31301/com.zj.location I/Adreno: QUALCOMM build                   : 0a3bdfc, Ifb508eebcdBuild Date                       : 08/04/16OpenGL ES Shader Compiler Version: XE031.09.00.03Local Branch                     : Remote Branch                    : Remote Branch                    : Reconstruct Branch               : 
01-27 13:12:03.902 31281-31301/com.zj.location I/OpenGLRenderer: Initialized EGL, version 1.4
01-27 13:12:04.056 31281-31281/com.zj.location D/MainActivity: onLocationChanged: 
01-27 13:12:04.057 31281-31281/com.zj.location D/MainActivity: latitude = 28.991141
01-27 13:12:04.057 31281-31281/com.zj.location D/MainActivity: longitude = 120.254431
01-27 13:12:04.057 31281-31281/com.zj.location D/MainActivity: provider = network
01-27 13:12:12.144 31281-31281/com.zj.location V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@288f8d6
01-27 13:12:34.255 31281-31281/com.zj.location D/MainActivity: onLocationChanged: 
01-27 13:12:34.255 31281-31281/com.zj.location D/MainActivity: latitude = 28.991141
01-27 13:12:34.256 31281-31281/com.zj.location D/MainActivity: longitude = 120.254431
01-27 13:12:34.256 31281-31281/com.zj.location D/MainActivity: provider = network
01-27 13:13:04.323 31281-31281/com.zj.location D/MainActivity: onLocationChanged: 
01-27 13:13:04.324 31281-31281/com.zj.location D/MainActivity: latitude = 28.991141
01-27 13:13:04.324 31281-31281/com.zj.location D/MainActivity: longitude = 120.254431
01-27 13:13:04.324 31281-31281/com.zj.location D/MainActivity: provider = network
01-27 13:13:34.401 31281-31281/com.zj.location D/MainActivity: onLocationChanged: 
01-27 13:13:34.401 31281-31281/com.zj.location D/MainActivity: latitude = 28.991141
01-27 13:13:34.401 31281-31281/com.zj.location D/MainActivity: longitude = 120.254431
01-27 13:13:34.402 31281-31281/com.zj.location D/MainActivity: provider = network
提供模拟定位数据

当你使用模拟设备时,Android Studio可以提供模拟定位数据

Providing Mock Location Data

这篇关于android 定位的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1081629

相关文章

Eclipse+ADT与Android Studio开发的区别

下文的EA指Eclipse+ADT,AS就是指Android Studio。 就编写界面布局来说AS可以边开发边预览(所见即所得,以及多个屏幕预览),这个优势比较大。AS运行时占的内存比EA的要小。AS创建项目时要创建gradle项目框架,so,创建项目时AS比较慢。android studio基于gradle构建项目,你无法同时集中管理和维护多个项目的源码,而eclipse ADT可以同时打开

android 免费短信验证功能

没有太复杂的使用的话,功能实现比较简单粗暴。 在www.mob.com网站中可以申请使用免费短信验证功能。 步骤: 1.注册登录。 2.选择“短信验证码SDK” 3.下载对应的sdk包,我这是选studio的。 4.从头像那进入后台并创建短信验证应用,获取到key跟secret 5.根据技术文档操作(initSDK方法写在setContentView上面) 6.关键:在有用到的Mo

android一键分享功能部分实现

为什么叫做部分实现呢,其实是我只实现一部分的分享。如新浪微博,那还有没去实现的是微信分享。还有一部分奇怪的问题:我QQ分享跟QQ空间的分享功能,我都没配置key那些都是原本集成就有的key也可以实现分享,谁清楚的麻烦详解下。 实现分享功能我们可以去www.mob.com这个网站集成。免费的,而且还有短信验证功能。等这分享研究完后就研究下短信验证功能。 开始实现步骤(新浪分享,以下是本人自己实现

Android我的二维码扫描功能发展史(完整)

最近在研究下二维码扫描功能,跟据从网上查阅的资料到自己勉强已实现扫描功能来一一介绍我的二维码扫描功能实现的发展历程: 首页通过网络搜索发现做android二维码扫描功能看去都是基于google的ZXing项目开发。 2、搜索怎么使用ZXing实现自己的二维码扫描:从网上下载ZXing-2.2.zip以及core-2.2-source.jar文件,分别解压两个文件。然后把.jar解压出来的整个c

android 带与不带logo的二维码生成

该代码基于ZXing项目,这个网上能下载得到。 定义的控件以及属性: public static final int SCAN_CODE = 1;private ImageView iv;private EditText et;private Button qr_btn,add_logo;private Bitmap logo,bitmap,bmp; //logo图标private st

Android多线程下载见解

通过for循环开启N个线程,这是多线程,但每次循环都new一个线程肯定很耗内存的。那可以改用线程池来。 就以我个人对多线程下载的理解是开启一个线程后: 1.通过HttpUrlConnection对象获取要下载文件的总长度 2.通过RandomAccessFile流对象在本地创建一个跟远程文件长度一样大小的空文件。 3.通过文件总长度/线程个数=得到每个线程大概要下载的量(线程块大小)。

时间服务器中,适用于国内的 NTP 服务器地址,可用于时间同步或 Android 加速 GPS 定位

NTP 是什么?   NTP 是网络时间协议(Network Time Protocol),它用来同步网络设备【如计算机、手机】的时间的协议。 NTP 实现什么目的?   目的很简单,就是为了提供准确时间。因为我们的手表、设备等,经常会时间跑着跑着就有误差,或快或慢的少几秒,时间长了甚至误差过分钟。 NTP 服务器列表 最常见、熟知的就是 www.pool.ntp.org/zo

高仿精仿愤怒的小鸟android版游戏源码

这是一款很完美的高仿精仿愤怒的小鸟android版游戏源码,大家可以研究一下吧、 为了报复偷走鸟蛋的肥猪们,鸟儿以自己的身体为武器,仿佛炮弹一样去攻击肥猪们的堡垒。游戏是十分卡通的2D画面,看着愤怒的红色小鸟,奋不顾身的往绿色的肥猪的堡垒砸去,那种奇妙的感觉还真是令人感到很欢乐。而游戏的配乐同样充满了欢乐的感觉,轻松的节奏,欢快的风格。 源码下载

Android SurfaceFlinger——图形内存分配器(十一)

前面的文章中的图层合成器(HWC),这里我们接着看一下 SurfaceFlinger 中的另一个重要服务——图形内存分配器。 一、简介         android.hardware.graphics.allocator@2.0 是 Android 系统中硬件抽象层(HAL)的一个组件,专门用于图形内存的分配和管理。它是 SurfaceFlinger 在处理图形数据时所依赖的

设置android返回键,保存和取得最高分

1.在.h中声明一些方法 virtual void keyBackClicked();           //Android返回键 bool isHaveSaveFile(); void getHighestHistoryScore(); 在.cpp中实现这个几个方法 void WelcomeLayer::keyBackClicked(