У меня есть для тебя загадка! Я могу получить приведенный ниже код для работы на моем тестовом телефоне Samsung Galaxy, который работает под управлением 2.2 (Froyo). Он не работает на моем тестовом телефоне HTC Thunderbolt, который работает под управлением 2.3.4 (Gingerbread). Это примерно так же просто, как и в случае сбора информации о местоположении, но я также применил лучшие практики, объясненные здесь с теми же результатами: Froyo - go, Gingerbread - мертв.
Что я должен попробовать, чтобы решить эту проблему? Это мой код? Это аппаратное, программное обеспечение? Права доступа? Я разозлил богов информатики? Я приму первый ответ с предложением, которое приведет к решению. Спасибо за помощь!
Моя активность:
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class SimpleLocationProjectActivity extends Activity {
private LocationManager mLocationManager;
private MyLocationListener mLocationListener;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mLocationListener = new MyLocationListener();
}
@Override
protected void onPause() {
mLocationManager.removeUpdates(mLocationListener);
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
Log.i("SIMPLE APP", "Starting location services.");
List<String> providers = mLocationManager.getAllProviders();
for (int i = 0 ; i < providers.size(); i++){
mLocationManager.requestLocationUpdates(providers.get(i), 1, 1, mLocationListener);
}
}
public class MyLocationListener implements LocationListener{
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
String statusStr;
switch (status){
case LocationProvider.OUT_OF_SERVICE:
statusStr = "Out of Service";
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
statusStr = "Temporarily unavailable";
break;
case LocationProvider.AVAILABLE:
statusStr = "Available";
break;
default:
statusStr = "Huhhh??";
}
Log.i("SIMPLE APP", "Provider: " + provider + " Status is: " + statusStr);
}
@Override
public void onProviderEnabled(String provider) {
Log.i("SIMPLE APP", "Provider: " + provider + " is enabled.");
}
@Override
public void onProviderDisabled(String provider) {
Log.i("SIMPLE APP", "Provider: " + provider + " is disabled.");
}
@Override
public void onLocationChanged(Location location) {
double latitute = location.getLatitude();
double longitude = location.getLongitude();
Toast.makeText(SimpleLocationProjectActivity.this, "Lat is " + latitute + " and lng is " + longitude, Toast.LENGTH_SHORT).show();
//This never gets called on my HTC Thunderbolt...
Log.i("SIMPLE APP", "Provider: " + location.getProvider() + " Lat is " + latitute + " and lng is " + longitude);
}
}
}
Мой манифест:
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="1" android:versionName="1.0"
package="com.silithcrowe.simplelocationproject" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk android:minSdkVersion="8"/>
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
<activity android:label="@string/app_name" android:name=".SimpleLocationProjectActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
РЕДАКТИРОВАТЬ: образец logcat во время работы:
03-01 11:37:43.529: D/RPC(1662): read RPC packet
03-01 11:37:43.529: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.529: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.529: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.529: D/RPC(1662): read RPC packet
03-01 11:37:43.529: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.529: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.529: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.529: D/RPC(1662): read RPC packet
03-01 11:37:43.529: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.529: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.529: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.529: D/RPC(1662): read RPC packet
03-01 11:37:43.529: D/RPC(1662): read RPC packet size: [96]
03-01 11:37:43.529: V/locapi_rpc_glue(1662): Callback received: 2 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.529: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.529: D/RPC(1662): read RPC packet
03-01 11:37:43.529: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.529: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.529: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.539: D/RPC(1662): read RPC packet
03-01 11:37:43.539: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.539: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.539: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.539: D/RPC(1662): read RPC packet
03-01 11:37:43.539: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.539: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.539: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.539: D/RPC(1662): read RPC packet
03-01 11:37:43.539: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:43.539: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:43.539: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:43.559: D/lib_locapi(1662): loc_eng_report_sv: valid_mask = 0x30, num of sv = 0
03-01 11:37:43.559: D/GpsLocationProvider(1662): reportSvStatus
03-01 11:37:44.410: D/RPC(1662): read RPC packet
03-01 11:37:44.410: D/RPC(1662): read RPC packet size: [208]
03-01 11:37:44.410: V/locapi_rpc_glue(1662): Callback received: 1 (cb_id=0x67E0001 handle=2)
03-01 11:37:44.410: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:44.410: D/lib_locapi(1662): loc_eng_report_position: valid mask = 0x61ed, sess status = 1
03-01 11:37:44.520: D/RPC(1662): read RPC packet
03-01 11:37:44.520: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:44.520: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:44.520: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:44.520: D/RPC(1662): read RPC packet
03-01 11:37:44.520: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:44.520: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:44.520: D/RPC(1662): written RPC packet size: [28]
03-01 11:37:44.520: D/RPC(1662): read RPC packet
03-01 11:37:44.520: D/RPC(1662): read RPC packet size: [272]
03-01 11:37:44.520: V/locapi_rpc_glue(1662): Callback received: 4 (cb_id=0x67E0001 handle=2)
03-01 11:37:44.520: D/RPC(1662): written RPC packet size: [28]
Пример logcat при запросе обновлений местоположения:
I/SIMPLE APP(12524): Starting location services.
D/AK8975 ( 1544): Ignore M_Sensor: (y, p, r) = ( 293, 1, 2), Status = 2
D/GpsLocationProvider( 1662): [handleMessage] message :8
D/GpsLocationProvider( 1662): [handleMessage] ADD_LISTENER
D/GpsLocationProvider( 1662): addListener(com.seedlabs.simplelocationproject)
D/GpsLocationProvider( 1662): setMinTime 0
V/GpsLocationProvider( 1662): enableLocationTracking ++
D/GpsLocationProvider( 1662): [handleMessage] message :3
D/GpsLocationProvider( 1662): [handleMessage] ENABLE_TRACKING
D/GpsLocationProvider( 1662): startNavigating
D/GpsLocationProvider( 1662): HtcBuildFlag.HtcCIQFlag(FALSE)
V/LocationManagerService( 1662): requestLocationUpdates
V/LocationManagerService( 1662): requestLocationUpdatesLocked: updateProvidersLocked
D/LocationManagerService( 1662): [updateProvidersLocked]
V/LocationManagerService( 1662): requestLocationUpdates
V/LocationManagerService( 1662): requestLocationUpdatesLocked: updateProvidersLocked
D/LocationManagerService( 1662): [updateProvidersLocked]
V/LocationManagerService( 1662): requestLocationUpdates
V/LocationManagerService( 1662): requestLocationUpdatesLocked: updateProvidersLocked
D/LocationManagerService( 1662): [updateProvidersLocked]
D/lib_locapi( 1662): [GPS:] loc_eng_set_qos_time_out(standalone = 16000, agps = 16000)
V/GpsLocationProvider( 1662): set_agps_qos_time_out complete
D/GpsLocationProvider( 1662): GpsLocationProvider_set_position_mode
D/lib_locapi( 1662): [GPS:] loc_eng_set_position mode, client = 2, interval = 1000, mode = 0
D/lib_locapi( 1662): [GPS:] loc_eng_set_position mode: GPS_POSITION_MODE_STANDALONE
D/lib_locapi( 1662): [GPS:] loc_eng_set_position mode before IOCTL, interval=1000, mode =4 preferred_accuracy=50, qos_timeout_standalone=16000, recurrence_type=1
V/lib_locapi( 1662): loc_eng_ioctl called: client = 2, ioctl_type = 2
V/locapi_rpc_glue( 1662): loc_ioctl
D/RPC ( 1662): written RPC packet size: [96]