java - addProximityAlert不适用于api 17及更高版本

addProximityAlert无法在api 4及更高版本上使用api 17及更高版本,并且在android 4及以下版本上可以正常工作,并输入到接收方广播,但在api 17及更高版本上却无法正常工作我添加了FINE_LOCATION权限我的应用程序检查用户是否输入特定区域,并在内部或外部触发通知并存储它在数据库中

功能码:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Intent intent = new Intent("ACTION_PROXIMITY_ALERT");
        intent.putExtra("phone",phone);
        intent.putExtra("name",name);
        intent.putExtra("empnum",empnum);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

        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 {
            Toast.makeText(this, "enter", Toast.LENGTH_SHORT).show();
            if (locationManager != null) {
                locationManager.addProximityAlert(28.0837576, 30.7637102, 50, -1, pendingIntent);
            }
        }

表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.galalrabie.companytrack">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

    <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/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
        </activity>
        <activity
            android:name=".RegisterActivity"
            android:screenOrientation="portrait" />
        <activity
            android:name=".LoginActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".BackgroundService" >
            <intent-filter>
                <action android:name="ACTION_PROXIMITY_ALERT" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

非常感谢

转载请注明来自askonline.tech,本文标题:java - addProximityAlert不适用于api 17及更高版本


 Top