English 中文(简体)
不在Android 4.0.2模拟器工作的地点管理员
原标题:Location Manager not working in Android 4.0.2 Emulator

我在应用程序中使用Location 管理员 来跟踪GPS。 应用程序返回了在 Android 2. 2, 2.2.3.3 模拟器和设备中使用的合适位置。 但是, 奇怪的是我在 < strong> Emulator 4.0. 2 中测试了该应用程序。 它返回了逼近错误, 编号为 < code> 05- 28 15: 13: 46.584: E/AndroidRuntime( 4458): com. package.TestRun.registLocation Location Realleners (TestRun.java:191) in < strong > logcat 。 我实施了以下代码:

    LocationManager lm;
    LocationManager lmNet;
    private void registerLocationListeners() {
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (myGPSLocationListener == null || mynetworkprovider == null)
    {
        createLocationListeners();  
    }  
    lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER ,0,0,mynetworkprovider);
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER ,60000,0,myGPSLocationListener);

}
private void createLocationListeners() {
    mynetworkprovider = new LocationListener() {  
       public void onLocationChanged(Location argLocation) {
           if (argLocation != null) {
            gps[0] = argLocation.getLatitude(); 
            gps[1] = argLocation.getLongitude(); 
            //Toast.makeText( getApplicationContext(),"Network provider Lat =" + gps[0] + " Lon = " + gps[1] , Toast.LENGTH_SHORT).show();
            }
                //Toast.makeText( getApplicationContext(),"On Location change" , Toast.LENGTH_SHORT).show();
            }
            public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub
            //  Toast.makeText( getApplicationContext(),"Disable" , Toast.LENGTH_SHORT).show();
            }
            public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub
            //  Toast.makeText( getApplicationContext(),"enabled" , Toast.LENGTH_SHORT).show();
            }
            public void onStatusChanged(String provider,
             int status, Bundle extras) {
            // TODO Auto-generated method stub
                //Toast.makeText( getApplicationContext(),"Status change" , Toast.LENGTH_SHORT).show();

            }
            };

            myGPSLocationListener = new LocationListener() {  
                   public void onLocationChanged(Location argLocation) {
                       if (argLocation != null) {
                        gps[0] = argLocation.getLatitude(); 
                        gps[1] = argLocation.getLongitude(); 
                        //Toast.makeText( getApplicationContext(),"GPS Lat =" + gps[0] + " Lon = " + gps[1] , Toast.LENGTH_SHORT).show();
                        }
                            //Toast.makeText( getApplicationContext(),"On Location change" , Toast.LENGTH_SHORT).show();
                        }
                        public void onProviderDisabled(String provider) {
                        // TODO Auto-generated method stub
                            //Toast.makeText( getApplicationContext(),"Disable" , Toast.LENGTH_SHORT).show();
                            //launchGPS();
                        }
                        public void onProviderEnabled(String provider) {
                        // TODO Auto-generated method stub
                            //Toast.makeText( getApplicationContext(),"enabled" , Toast.LENGTH_SHORT).show();
                        }
                        public void onStatusChanged(String provider,
                         int status, Bundle extras) {
                        // TODO Auto-generated method stub
                            //Toast.makeText( getApplicationContext(),"Status change" , Toast.LENGTH_SHORT).show();

                        }
            };
}

< 强力 > UPDATE : 这是我的日志 :

   05-28 15:42:46.375: E/AndroidRuntime(5585): FATAL EXCEPTION: main
   05-28 15:42:46.375: E/AndroidRuntime(5585): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.package/com.package.TestRun}: java.lang.IllegalArgumentException: provider=network
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at  android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.os.Handler.dispatchMessage(Handler.java:99)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.os.Looper.loop(Looper.java:137)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.app.ActivityThread.main(ActivityThread.java:4340)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at java.lang.reflect.Method.invokeNative(Native Method)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at java.lang.reflect.Method.invoke(Method.java:511)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at dalvik.system.NativeStart.main(Native Method)
   05-28 15:42:46.375: E/AndroidRuntime(5585): Caused by: java.lang.IllegalArgumentException: provider=network
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.os.Parcel.readException(Parcel.java:1331)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.os.Parcel.readException(Parcel.java:1281)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:646)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.location.LocationManager._requestLocationUpdates(LocationManager.java:582)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.location.LocationManager.requestLocationUpdates(LocationManager.java:446)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at com.package.TestRun.registerLocationListeners(TestRun.java:191)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at com.package.TestRun.onCreate(TestRun.java:135)
   05-28 15:42:46.375: E/AndroidRuntime(5585):  at android.app.Activity.performCreate(Activity.java:4465)
    05-28 15:42:46.375: E/AndroidRuntime(5585):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    05-28 15:42:46.375: E/AndroidRuntime(5585):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)

Location management in Android4.0 API是否有更新?如果任何人遇到同样的问题,请分享观点/解决方案链接。

最佳回答

这是个问题。 看看 < a href=" "http://code.google.com/p/android/issues/ detail?id=19857" rel="no follow" > this 。

上面写道:

不要直接使用 p提供者 字符串,因为不能保证它在运行时存在。

仅使用从 管理器 获得的 提供者 , 像这样 :

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

    Criteria criteria = new Criteria();
    criteria.setAccuracy( Criteria.ACCURACY_COARSE );
    String provider = locationManager.getBestProvider( criteria, true );

    if ( provider == null ) {
        Log.e( TAG, "No location provider found!" );
        return;
    }

    lastLocation = locationManager.getLastKnownLocation(provider);

lovemanager 中另一个有用的方法就是 LocationManager.get AllProviders ()

/**
 * Returns a list of the names of all known location providers.  All
 * providers are returned, including ones that are not permitted to be
 * accessed by the calling activity 或 are currently disabled.
 *
 * @return list of Strings containing names of the providers
 */
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签