开发者

Android DDMS GPS location inserted, but no reaction anywhere in the system

I try to use the DDMS location mockup with a very simple Log.i() call in the functions of all LocationListener attributes. When I start the program I get the Log.i() message for onStatusChanged() in my LogCat, so I think that I registered the listener correctly. But when I put a location into the VM using the DDMS menus in Eclipse I get nothing. No change in LogCat, Console, or inside the VM. As if nothing happened at all.

How can I even start to find the problem?

Here is the code for my simple GPS Event logger:

public class gpsActivity extends Activity {

    private static final String TAG="gpsActivity";
    private static TextView label;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        label = (TextView) findViewById(R.id.label);
        LocationManager manager = (LocationManager) this
                .getSystemService(LOCATION_SERVICE);
        LocationListener listener = new LocationListener() {
            @Override
            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                Log.i(TAG, "onStatusChanged: "+arg0);
            }
            @Override
            public void onProviderEnabled(String arg0) {
                Log.i(TAG, "onProviderEnabled: "+arg0);
            }
            @Override
            public void onProviderDisabled(String arg0) {
                Log.i(TAG, "onProviderDisabled: "+arg0);
            }
            @Override
            public void onLocationChanged(Location location) {
                Log.i(TAG, "onLocationChanged");
            }
        };
        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 0,
                listener);
        setContentView(R.layout.main);
    }
}

and here the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mypackage.example.gps"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

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

Also as another side note, I am using a German Windows XP and found out that there are problems with GP开发者_JAVA百科S packages, because in a German system the number format for 1/2 is not 0.5 but 0,5 which leads to errors in the GPS parser grammar. But also changing my systems number format to English(US) didn't change that I don't get any message, exception or result at all.


Be sure that your device/emmulator is selected in the device menu of DDMS.

EDIT:

Oops. I should have seen these earlier:

You are using NETWORK_PROVIDER. In order to receive mock locations from DDMS (and I think also the command line through geo), you must register the GPS_PROVIDER. Your code works by changing the last line of the onCreate method:

manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2, 0,
                listener); 

NETWORK_PROVIDER is signals through the phone network (e.g 3G) or WIFI


There where 3 problems involved. Because finding all of them took more then 12 hours of pure research time please excuse that I won't even try to find the according sources again.

The problems involved where:

  1. You should use Google API <version> as target and not Android <version> because there are nesssesary things not activated in the latter.
  2. You should send the updates via telnet and not DDMS because DDMS creates some uncertain, undocumented and not logged results, especially if you are using a non-US version of Windows.
  3. The time zone in your emulator is automatically chosen, but maybe to the wrong locale (as mine is Germany, for example). You can switch it off inside a running emulator in the Android settings and also choose your correct locale. This only seems to appear in older versions of Android.

Good luck to everybody who tries his way to this kind of errors!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜