到达特定位置通知

cetgtptt  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(284)

我目前正在开罗地铁指南应用程序中与我的团队合作,我当前的任务是在用户到达目的地地铁站100米范围内发出通知。使用androidmanifest.xml权限:

android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        <uses-permission android:name="android.permission.INTERNET"/>
     <uses-feature android:name="android.hardware.location.network"/>
        <uses-feature android:name="android.hardware.location.gps"/>
<application
    android:usesCleartextTraffic="true"
    android:allowBackup="true"
    android:icon="@drawable/ic_metro_logo"
    android:label="@string/app_name"
    android:roundIcon="@drawable/ic_metro_logo"
    android:supportsRtl="true"
    android:theme="@style/Theme.Metro">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

主要活动:

LocationManager manager;

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults){
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 1) {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                try {
                    manager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, null);
                } catch (SecurityException e) {
                    e.printStackTrace();
                }
            } else {
                Toast.makeText(this, "feature not supported", Toast.LENGTH_SHORT).show();
            }
        }

    }
``` `onCreate()` :

manager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
String[] perm = {Manifest.permission.ACCESS_FINE_LOCATION};
ActivityCompat.requestPermissions(this, perm, 1);
} else {
manager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, this, null);
}

我不知道下一步该怎么办
我试着阅读了地理围栏的文档,但是我仍然不知道如何使用它,所以如果有人给我一些建议,我会告诉他。
谢谢你

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题