Android FusedLocationProviderApi: Incoming intent has no LocationResult or LocationAvailability

前端 未结 3 1920
故里飘歌
故里飘歌 2021-02-14 06:10

I am trying to subscribe to location updates via Google\'s FusedLocationProviderApi. I want to receive updates in the background, so that I will receive updates even if the app

相关标签:
3条回答
  • 2021-02-14 06:47

    Remove the extras from the pending intent, otherwise the location result is not delivered. I can't find where in the documentation this is explained but I found out after lot of trial and error.

    0 讨论(0)
  • 2021-02-14 07:06

    You can use:

    int id = 7;
    String name = "myName";
    uriBuilder.scheme("http")
                .authority("workaround.com")
                .appendPath("extra")
                .appendQueryParameter("id", String.valueOf(id))
                .appendQueryParameter("name", name);
    intent.setData(uriBuilder.build());
    

    and

    @Override
    protected void onHandleIntent(Intent intent) {
        if (LocationResult.hasResult(intent)) {
            int id = Integer.valueOf(uri.getQueryParameter("id"));
            String name = uri.getQueryParameter("name");
            ....
        }
    }
    
    0 讨论(0)
  • 2021-02-14 07:09

    A workaround (Christophe Beyls suggested that only Intent Data should be used) So, since I only need to send a few parameters, so I do something like this: while building the Intent before the requestLocationUpdates: intent.setData(Uri.parse("http://a.com/a?"+ Param1+ "?" + Param2+ "?" + Param3); and in the BroadcastReceiver: String[] parameters = intent.getDataString().split("[?]"); This works fine, and intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED) does return the location.

    0 讨论(0)
提交回复
热议问题