1. <i id='pbZdR'><tr id='pbZdR'><dt id='pbZdR'><q id='pbZdR'><span id='pbZdR'><b id='pbZdR'><form id='pbZdR'><ins id='pbZdR'></ins><ul id='pbZdR'></ul><sub id='pbZdR'></sub></form><legend id='pbZdR'></legend><bdo id='pbZdR'><pre id='pbZdR'><center id='pbZdR'></center></pre></bdo></b><th id='pbZdR'></th></span></q></dt></tr></i><div id='pbZdR'><tfoot id='pbZdR'></tfoot><dl id='pbZdR'><fieldset id='pbZdR'></fieldset></dl></div>

    2. <legend id='pbZdR'><style id='pbZdR'><dir id='pbZdR'><q id='pbZdR'></q></dir></style></legend>

      • <bdo id='pbZdR'></bdo><ul id='pbZdR'></ul>

      <small id='pbZdR'></small><noframes id='pbZdR'>

        <tfoot id='pbZdR'></tfoot>
      1. Android:使用 LocationManager.requestLocationUpdates() 时如何

        时间:2023-09-02

          <tfoot id='IinPU'></tfoot>
            <i id='IinPU'><tr id='IinPU'><dt id='IinPU'><q id='IinPU'><span id='IinPU'><b id='IinPU'><form id='IinPU'><ins id='IinPU'></ins><ul id='IinPU'></ul><sub id='IinPU'></sub></form><legend id='IinPU'></legend><bdo id='IinPU'><pre id='IinPU'><center id='IinPU'></center></pre></bdo></b><th id='IinPU'></th></span></q></dt></tr></i><div id='IinPU'><tfoot id='IinPU'></tfoot><dl id='IinPU'><fieldset id='IinPU'></fieldset></dl></div>

                <bdo id='IinPU'></bdo><ul id='IinPU'></ul>
              • <small id='IinPU'></small><noframes id='IinPU'>

                  <tbody id='IinPU'></tbody>

                <legend id='IinPU'><style id='IinPU'><dir id='IinPU'><q id='IinPU'></q></dir></style></legend>

                1. 本文介绍了Android:使用 LocationManager.requestLocationUpdates() 时如何从 Intent 捆绑包中获取位置信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Android 的 LocationManager requestLocationUpdates.一切正常,直到我尝试提取广播接收器中的实际位置对象.我是否需要专门为我的自定义意图定义附加",以便 Android LocationManager 在我将它传递给 requestLocationUpdates 之前知道如何将其添加到意图中,或者它是否会创建附加捆绑包,无论它何时通过触发广播接收者的意图?

                  I am trying to use Android's LocationManager requestLocationUpdates. Everything is working until I try to extract the actual location object that in my broadcast receiver. Do I need to specifically define the "extras" to my custom intent so that the Android LocationManager before I pass it to requestLocationUpdates so it knows how to add it into the intent, or will it create the extras-bundle regardless when it passes the fired intent to the broadcast receiver?

                  我的代码如下所示:

                  Intent intent = new Intent("com.myapp.swarm.LOCATION_READY");
                  PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
                      0, intent, 0);
                  
                  //Register for broadcast intents
                  int minTime = 5000;
                  int minDistance = 0;
                  lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime,
                      minDistance, pendingIntent);
                  

                  我有一个广播接收器,它在宣言中定义为:

                  I have a broadcast receiver that is defined in the manifesto as:

                  <receiver android:name=".LocationReceiver">
                      <intent-filter>
                          <action android:name="com.myapp.swarm.LOCATION_READY" />
                          <category android:name="android.intent.category.DEFAULT" />
                      </intent-filter>
                  </receiver>
                  

                  广播接收器类为:

                  public class LocationReceiver extends BroadcastReceiver {
                      @Override
                      public void onReceive(Context context, Intent intent) {
                      //Do this when the system sends the intent
                      Bundle b = intent.getExtras();
                      Location loc = (Location)b.get("KEY_LOCATION_CHANGED");
                  
                      Toast.makeText(context, loc.toString(), Toast.LENGTH_SHORT).show(); 
                      }
                  }
                  

                  我的loc"对象即将为空.

                  My "loc" object is coming up null.

                  推荐答案

                  好的,我设法通过将广播接收器代码中的 KEY_LOCATION_CHANGED 更改为:

                  OK, I managed to fix it by changing the KEY_LOCATION_CHANGED in the broadcast receiver code to:

                  public class LocationReceiver extends BroadcastReceiver {
                      @Override
                      public void onReceive(Context context, Intent intent) {
                      //Do this when the system sends the intent
                      Bundle b = intent.getExtras();
                      Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
                  
                      Toast.makeText(context, loc.toString(), Toast.LENGTH_SHORT).show(); 
                      }
                  }
                  

                  这篇关于Android:使用 LocationManager.requestLocationUpdates() 时如何从 Intent 捆绑包中获取位置信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从坐标获取国家? 下一篇:Android - 可靠地获取当前位置

                  相关文章

                  最新文章

                2. <small id='bWrnD'></small><noframes id='bWrnD'>

                    <legend id='bWrnD'><style id='bWrnD'><dir id='bWrnD'><q id='bWrnD'></q></dir></style></legend>

                    1. <i id='bWrnD'><tr id='bWrnD'><dt id='bWrnD'><q id='bWrnD'><span id='bWrnD'><b id='bWrnD'><form id='bWrnD'><ins id='bWrnD'></ins><ul id='bWrnD'></ul><sub id='bWrnD'></sub></form><legend id='bWrnD'></legend><bdo id='bWrnD'><pre id='bWrnD'><center id='bWrnD'></center></pre></bdo></b><th id='bWrnD'></th></span></q></dt></tr></i><div id='bWrnD'><tfoot id='bWrnD'></tfoot><dl id='bWrnD'><fieldset id='bWrnD'></fieldset></dl></div>
                      • <bdo id='bWrnD'></bdo><ul id='bWrnD'></ul>
                    2. <tfoot id='bWrnD'></tfoot>