1

在我的项目中,我使用了接近警报,它在 android 4.1 版本(API 16)上运行良好,但在 android 4.2(API 17)上它不起作用。我需要添加一些额外的标志或其他东西吗?

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

Intent intent1 = new Intent(PROXIMITY_ALERT);
PendingIntent proximityIntent = PendingIntent.getBroadcast(this, 0, intent1, 0);

locationManager.addProximityAlert(lat, lng, 4, -1, proximityIntent); 

IntentFilter filter = new IntentFilter(PROXIMITY_ALERT);

 registerReceiver(new ProximityIntentReceiver(), filter);

显现:

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

<application

    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.proximityalert.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

0 回答 0