0
我是新來的Eclipse和Android應用程序,所以這裏提出了一個非常新的問題。我如何使這個功能正常工作?我剛剛複製>粘貼到我的public class nowActivity extends Activity {
並修復了符合的錯誤。功能如下:如何使GPS功能正常工作?
package weather.right;
import weather.right.now.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class nowActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show();
}else{
showGPSDisabledAlertToUser();
}
}
public void goToSo(View view) {
goToUrl("http://erik-edgren.nu/weather");
}
private void goToUrl(String url) {
Uri uriUrl = Uri.parse(url);
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
private void showGPSDisabledAlertToUser(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setMessage("GPS is disabled in your device. Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Goto Settings Page To Enable GPS",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
Intent callGPSSettingIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(callGPSSettingIntent);
}
});
alertDialogBuilder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int id){
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
}
在此先感謝。
嗯。是?這是該代碼的第二行。你想說什麼?記住,我是這些「圍牆」內的新人。 – Erik 2012-04-02 01:18:06
對不起,我試圖變得有趣。請參閱編輯。 – Jasoneer 2012-04-02 01:21:05
@ErikEdgren它應該是'onCreate()',而不是'onCreate1()'(注意尾部的'1')。但是,如果您實際上正在使用尾部「1」來聲明方法,則忽略上述響應。但onCreate()會自動調用,因爲它是Android中所有Activies的重要方法。 :) – ninetwozero 2012-04-02 01:21:58