即時通訊相當新的android和im開發不舒服如何解決這個問題。 我發佈了我的應用程序,並開始從android 2.1的一些脂肪酶報告崩潰。我的HTC Desire 2.2工作得很好,似乎工作在模擬1.6getLastKnownLocation崩潰android 2.1
和它在模擬2.1崩潰,如果我不快速發送一些GPS與Eclipse DDMS。
而且,如果我改變了一些代碼,不要求GPS位置不死機......
我搜索的谷歌也很多,它似乎錯誤是「getLastKnownLocatio」有時retrns零,這使得它崩潰,但我不能找到應該是一個解決辦法,以適應在我的代碼....即時通訊不是最好的程序員在世界:)
請幫我...
這是我的java:
public class WebPageLoader extends Activity implements LocationListener{
public static String Android_ID = null;
final Activity activity = this;
private Location mostRecentLocation;
private void getLocation() {
LocationManager locationManager =
(LocationManager)getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = locationManager.getBestProvider(criteria,true);
//In order to make sure the device is getting the location, request updates.
//locationManager.requestLocationUpdates(provider, 10, 1, this);
//mostRecentLocation = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 1000, 500, this);
mostRecentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
//getLocation();
Android_ID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
WebView webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
/** Allows JavaScript calls to access application resources **/
webView.addJavascriptInterface(new JavaScriptInterface(), "android16");
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Letar poliskontroller");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
getLocation();
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("http://m.domain.se/android/file.php");
}
/** Sets up the interface for getting access to Latitude and Longitude data from device
**/
private class JavaScriptInterface {
public double getLatitude(){
return mostRecentLocation.getLatitude();
}
public double getLongitude(){
return mostRecentLocation.getLongitude();
}
public String getAndroid_ID(){
return Android_ID;
}
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
getLocation();
//android16();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem item = menu.add("Meny");
item = menu.add("Stäng app");
item.setIcon(R.drawable.exit);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle() == "Stäng app") {
finish();
}
return true;
}
}
UPDATE
與您sugestion爲javacall至極防止崩潰,我也是在reciving谷歌地圖
latitude = window.android16.getLatitude();
longitude = window.android16.getLongitude();
if (isNaN(latitude)) {
latitude = 61.72680992165949;
} else {
latitude = latitude;
}
if (isNaN(longitude)) {
longitude = 17.10124969482422;
} else {
longitude = longitude;
}
現在它似乎工作的java的補充這一點。 ..乾杯和非常感謝,生病嘗試一些,並回來報告,當我討厭它一些。
感謝您的回覆,我不知道該怎麼做。你能給我一個小例子嗎? – Jerry 2010-11-28 23:16:46
@Jerry - 請參閱UPDATE部分。 – 2010-11-28 23:40:00