-------.Xml-------------------------------
<Button android:id="@+id/bt_1" android:text="检测设备状态" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_2" android:text="定位服务" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_3" android:text="活动识别" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <!-- <Button--> <!-- android:id="@+id/bt_4"--> <!-- android:text="地理围栏"--> <!-- android:layout_width="wrap_content"--> <!-- android:layout_height="wrap_content"/>--> <Button android:id="@+id/bt_5" android:text="地理围栏" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
-----------------------------------.Xml2---------------------------------------------
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" xmlns:hwads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" tools:context=".MainActivity2"> <com.huawei.hms.ads.banner.BannerView android:id="@+id/huaweiBanner" android:layout_width="match_parent" android:layout_height="wrap_content" hwads:adId="testw6vs28auh3" hwads:bannerSize="BANNER_SIZE_360_57"/> <Button android:id="@+id/bt_1" android:text="OAID获取本设备的标识信息" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_2" android:text="安全检测服务" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_3" android:text="文本识别" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_4" android:text="图片分类" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/bt_5" android:text="文档校正" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
</LinearLayout>
------------------------Manifest------------ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hms_5_25"> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <!-- 位置权限 --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 持续定位权限 --> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> <!-- 活动识别 --> <uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION" /> <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" /> <!--相机权限--> <uses-permission android:name="android.hardware.camera" /> <!-- 软硬件集成--> <uses-permission android:name="android.permission.CAMERA"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.HMS_5_25" android:usesCleartextTraffic="true"> <activity android:name=".MainActivity2"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"> </activity> <meta-data android:name="com.huawei.hms.client.channel.androidMarket" android:value="false" /> <!-- 注册活动识别服务广播接收器 --> <receiver android:name=".LocationBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="com.huawei.hmssample.location.LocationBroadcastReceiver.ACTION_PROCESS_LOCATION" /> </intent-filter> </receiver> <!-- 注册地理围栏服务广播接收器 --> <receiver android:name=".GeoFenceBroadcastReceiver" android:exported="true"> <intent-filter> <action android:name="com.huawei.hmssample.geofence.GeoFenceBroadcastReceiver.ACTION_PROCESS_LOCATION" /> </intent-filter> </receiver> </application> </manifest>
-------------------------------------MainActivity---------------------------------------
package com.example.hms_5_25; import android.Manifest; import android.annotation.SuppressLint; import android.app.PendingIntent; import android.content.Intent; import android.content.pm.PackageManager; import android.location.Location; import android.os.Build; import android.os.Bundle; import android.os.Looper; impo