即時通訊工作在這個應用程序,使用GPS顯示在谷歌地圖上的位置。 Bu似乎有問題,導致應用程序在開始時崩潰,如果在設置中打開了gps,並且以前從未使用過gps。 除此之外,該應用程序似乎工作,因爲它應該應用程序崩潰,如果GPS從未本使用
任何人都可以看到任何可能的原因?
這裏是我的代碼
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);
locationManager.requestLocationUpdates(provider, 2000, 500, this);
mostRecentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
@Override
public void onCreate(Bundle savedInstanceState)
{
//AdManager.setTestDevices(new String[] { AdManager.TEST_EMULATOR });
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
//getLocation();
Android_ID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);
/* Kan man kickstarta GPS såhär ? */
//mostRecentLocation.getLatitude();
getLocation();
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);
}
});
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;
}
});
if (Locale.getDefault().getLanguage().equals("sv")){
//webView.loadUrl("file:///android_asset/android.html");
webView.loadUrl("file:///android_asset/findgps_sv.html");
}else{
//webView.loadUrl("http://m.bryggplatsen.se/android/polis/index.php");
//webView.loadUrl("file:///android_asset/android_en.html");
webView.loadUrl("file:///android_asset/findgps_en.html");
}
}
/** Sets up the interface for getting access to Latitude and Longitude data from device
**/
private class JavaScriptInterface {
public double getLatitude(){
return mostRecentLocation != null ? mostRecentLocation.getLatitude() : Double.NaN;
}
public double getLongitude(){
return mostRecentLocation != null ? mostRecentLocation.getLongitude() : Double.NaN;
}
public String getAndroid_ID(){
return Android_ID;
}
public void sharethisapp(){
startActivity(Intent.createChooser(sharespotIntent(), "Share this warning"));
}
}
@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("Close menu");
item = menu.add("Shut down");
item.setIcon(R.drawable.exit);
item = menu.add("Share");
item.setIcon(R.drawable.m_share);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getTitle() == "Shut down") {
System.exit(0);
finish();
}
if (item.getTitle() == "Share") {
if (Locale.getDefault().getLanguage().equals("sv")){
startActivity(Intent.createChooser(shareIntent(), "Dela denna app"));
}else{
startActivity(Intent.createChooser(shareIntent(), "Share this app"));
}
}
return true;
}
private Intent shareIntent() {
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
if (Locale.getDefault().getLanguage().equals("sv")){
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Testa denna android app...");
return shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.bryggplatsen.se/android/polisapp/index.php");
}else{
shareIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Try this cool android app...");
return shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.bryggplatsen.se/android/polisapp/index_en.php");
}
}
private Intent sharespotIntent() {
Intent sharespotIntent = new Intent(android.content.Intent.ACTION_SEND);
sharespotIntent.setType("text/plain");
if (Locale.getDefault().getLanguage().equals("sv")){
sharespotIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " la just upp en ny varning i appen Polisradar");
return sharespotIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.bryggplatsen.se/android/polisapp/warn.php?lat=" + mostRecentLocation.getLatitude() + "&lng=" + mostRecentLocation.getLongitude() + "");
}else{
sharespotIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " just added a new warning in the app Policeradar");
return sharespotIntent.putExtra(android.content.Intent.EXTRA_TEXT, "http://www.bryggplatsen.se/android/polisapp/warn_en.php?lat=" + mostRecentLocation.getLatitude() + "&lng=" + mostRecentLocation.getLongitude() + "");
}
}
}
這可能有助於發佈logcat的。 – iarwain01 2010-12-18 11:32:53
你說得對...病態更新logcat – Jerry 2010-12-18 11:49:36
這裏是logcat,過濾警告和錯誤http://www.bryggplatsen.se/android/polisapp/logcat_eclipse.txt – Jerry 2010-12-18 11:54:23