android GPS临近警告无反应?receiver也注册了

public class MainActivity extends AppCompatActivity {
private LocationManager locationManager;//定位器处理

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

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

    double lon=119.205;
    double lat=26.026;

  //定义半径为5000米
    float radius =50000;
    //定义Intent
    Intent intent = new Intent(this , ProximityAlertReciever.class);
    //将 Intent 包装成 PendingIntent
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this,-1,intent,0);
    //添加临近警告
    //noinspection MissingPermission
    locationManager.addProximityAlert(lat,lon,radius,-1,pendingIntent);
}

}

/***********************************************/

public class ProximityAlertReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("info","onReceive");
//获取是否进入指定区域
boolean isEnter =intent.getBooleanExtra(LocationManager.KEY_PROXIMITY_ENTERING,false);
if (isEnter)
{

            Log.i("info","onReceive==true");
            //显示提示信息
            Toast.makeText(context,"进入指定区域",Toast.LENGTH_LONG).show();
        }
        else{
            Log.i("info","onReceive==false");
            //显示提示信息
            Toast.makeText(context,"离开指定区域",Toast.LENGTH_LONG).show();
        }
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!