package com.------------.webview;
import org.apache.http.util.EncodingUtils;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
import android.widget.Toast;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Criteria;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class Location extends Activity implements LocationListener{
WebView mWeb;
LocationManager location = null;
LocationManager locationManager = null;
public static TabHost mTab;
private Handler mHandler; //백키 누를시 받는 핸들러
private boolean mFlag = false;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.location);
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == 0) {
mFlag = false;
}
}
};
mWeb = (WebView)findViewById(R.id.web);
mWeb.setWebViewClient(new WebViewClient());
WebSettings setting = mWeb.getSettings();
setting.setJavaScriptEnabled(true);
setting.setBuiltInZoomControls(true);
String context = Context.LOCATION_SERVICE;
locationManager = (LocationManager)getSystemService(context);
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
//실내에서도 사용하려면 추가 ||(!locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
//NETWORK_PROVIDER <= 3G 혹은 Wi-fi 신호 사용
//LocationManager.GPS_PROVIDER <= gps신호사용
// GPS가 꺼져있을 시 앱이 수행할 작업 코드
alertCheckGPS();
} else{
setConfigGPS();
}
}
private void alertCheckGPS() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your GPS is disabled! Would you like to enable it?")
.setCancelable(false)
.setPositiveButton("Enable GPS",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
moveConfigGPS();
setConfigGPS();
}
})
.setNegativeButton("Do nothing",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
// GPS 설정화면으로 이동
private void moveConfigGPS() {
Intent gpsOptionsIntent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(gpsOptionsIntent);
}
private void setConfigGPS() {
location = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Toast.makeText(this,"Starting..", Toast.LENGTH_SHORT).show();
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.NO_REQUIREMENT);
criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
String provider = location.getBestProvider(criteria, true);
location.requestLocationUpdates(provider,1000, 0, this);
}
@Override
public void onLocationChanged(android.location.Location location) {
// TODO Auto-generated method stub
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Toast.makeText(this,latitude+","+longitude,Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
}
* 추가
탭을 만들기 위해
1. 위의 소스 Location.java만들음
2.location.xml만들음
3.strings.xml에
<string name="title_activity_webview">WebView</string> 추가
4.메인탭엑티비에
import . -----------.Location
intent 마지막탭
addTab 추가
5.안드로이드매니페스트.xml에
<activity> 추가
6. 엑티비티_메인.xml에
버튼 추가 + 리니어 레이아웃 추가