模拟GPS数据到Android AVD不起作用

时间:2012-05-31 02:50:57

标签: android eclipse gps avd

我希望有人可以帮我解决我在Eclipse中将模拟GPS数据发送到Android AVD时遇到的问题。如果我在真实设备上运行应用程序一切正常,但是当我尝试在eclipse中使用内置模拟器时,什么都不会发生。我也试过telneting到AVD并发出geo fix命令。下面是我正在使用的代码,虽然如果它在真实设备上工作,我认为它没有任何问题

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.TestGoogleMaps"
android:versionCode="1"
android:versionName="1.0" >
    <uses-sdk android:targetSdkVersion="10" android:minSdkVersion="8"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>  
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>  
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".TestingGoogleMapsActivity"
        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>
</manifest>

main.xml中

<?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
  >
</LinearLayout>

主要代码

package net.TestGoogleMaps;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class TestingGoogleMapsActivity extends Activity 
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LocationManager locationManager; 
        String context = Context.LOCATION_SERVICE; 
        locationManager = (LocationManager)getSystemService(context); 
        Criteria criteria = new Criteria(); 
        criteria.setAccuracy(Criteria.ACCURACY_FINE); 
        criteria.setAltitudeRequired(false); 
        criteria.setBearingRequired(false); 
        criteria.setCostAllowed(true); 
        criteria.setPowerRequirement(Criteria.POWER_LOW); 
        String provider = locationManager.getBestProvider(criteria, true); 

        Location location = locationManager.getLastKnownLocation(provider); 


        updateWithNewLocation(location);


        locationManager.requestLocationUpdates(provider, 2000, 10,    
                                               locationListener); 
    }



    private final LocationListener locationListener = new LocationListener() { 
        public void onLocationChanged(Location location) { 
          updateWithNewLocation(location); 
        } 

        public void onProviderDisabled(String provider){ 
          updateWithNewLocation(null); 
        } 

        public void onProviderEnabled(String provider){ } 
        public void onStatusChanged(String provider, int status,  
                                    Bundle extras){ } 
      };




    public void updateWithNewLocation(Location location)
    {

        Context contextApp = getApplicationContext();

        String text ;
        int duration = 2000;

        if(location == null)
        {
            text ="Null Location";

        }
        else
        {
            text = "Lat : " + location.getLatitude() + " Lon: " + location.getLongitude();
        }

        Toast toast = Toast.makeText(contextApp, text, duration);
        toast.show();
    }   
}

在eclipse的LogCat选项卡中模拟从eclipse到设备的GPS数据时,我也会遇到以下错误。

05-31 02:31:35.158: E/InputQueue-JNI(347): channel '406e6640  net.TestGoogleMaps/net.TestGoogleMaps.TestingGoogleMapsActivity (client)' ~ Publisher closed input channel or an error occurred.  events=0x8

非常感谢任何帮助!

2 个答案:

答案 0 :(得分:2)

我知道您的问题,您可以手动设置当前(长/滞后)

DDMS-&gt;设备 - &gt;仿真器控制 - &gt;位置控制 - &gt;手动 - &gt;输入(长/滞)和发送

答案 1 :(得分:0)

正如Tanvir Ahmed所说,它看起来像its a bug (Source)。我也偶然发现了这一天超过一天。 您可以尝试使用“Google API - API Level 10”代替AVM的“Android 2.3.3”。