gps activity stuck at onStart() - gps

I wanted to call an activity to get the current gsp location and return the longitude and latidute but nothing happens, so i tried the simple following code from an programming book:
{private static final String TAG = GetGps.class.getSimpleName();
private LocationManager manager;
private LocationListener listener;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gps);
// LocationManager-Instanz ermitteln
manager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Liste mit Namen aller Provider erfragen
List<String> providers = manager.getAllProviders();
// Infos zu Location Providern ausgeben
for (String name : providers) {
LocationProvider lp = manager.getProvider(name);
Log.d(TAG,
lp.getName() + " --- isProviderEnabled(): "
+ manager.isProviderEnabled(name));
Log.d(TAG, "requiresCell(): " + lp.requiresCell());
Log.d(TAG, "requiresNetwork(): " + lp.requiresNetwork());
Log.d(TAG, "requiresSatellite(): " + lp.requiresSatellite());
}
// Provider mit grober Auflösung
// und niedrigen Energieverbrauch
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
// Namen ausgeben
String name = manager.getBestProvider(criteria, true);
Log.d(TAG, name);
// LocationListener-Objekt erzeugen
listener = new LocationListener() {
public void onStatusChanged(String provider, int status,
Bundle extras) {
Log.d(TAG, "onStatusChanged()");
}
public void onProviderEnabled(String provider) {
Log.d(TAG, "onProviderEnabled()");
}
public void onProviderDisabled(String provider) {
Log.d(TAG, "onProviderDisabled()");
}
public void onLocationChanged(Location location) {
Log.d(TAG, "onLocationChanged()");
if (location != null) {
String s = "Breite: " + location.getLatitude()
+ "\nLänge: " + location.getLongitude();
Toast.makeText(GetGps.this,
s,
Toast.LENGTH_LONG).show();
}
}
};
}
#Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart()");
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0,
listener);
}
#Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause()");
manager.removeUpdates(listener);
}}
As i said, nothing happens, so here is the catlog:
12-05 15:59:54.490: D/GetGps(6833): network --- isProviderEnabled(): true
12-05 15:59:54.490: D/GetGps(6833): requiresCell(): true
12-05 15:59:54.490: D/GetGps(6833): requiresNetwork(): true
12-05 15:59:54.490: D/GetGps(6833): requiresSatellite(): false
12-05 15:59:54.500: D/GetGps(6833): passive --- isProviderEnabled(): true
12-05 15:59:54.500: D/GetGps(6833): requiresCell(): false
12-05 15:59:54.500: D/GetGps(6833): requiresNetwork(): false
12-05 15:59:54.500: D/GetGps(6833): requiresSatellite(): false
12-05 15:59:54.500: D/GetGps(6833): gps --- isProviderEnabled(): true
12-05 15:59:54.500: D/GetGps(6833): requiresCell(): false
12-05 15:59:54.500: D/GetGps(6833): requiresNetwork(): true
12-05 15:59:54.500: D/GetGps(6833): requiresSatellite(): true
12-05 15:59:54.500: D/GetGps(6833): network
12-05 15:59:54.500: D/GetGps(6833): onStart()
12-05 15:59:54.530: D/OpenGLRenderer(6833): Flushing caches (mode 0)
can someone help me pls ??

Related

Can't read the value that comes with the GATT Service characteristic; Not sure if I setup the GATT server correctly

The BLE is advertising just fine. I can establish a connection with it but I can't read the characteristic value I set here on the initialization of GATT server.
This is the GATT Server setup
#ReactMethod
public void startServer(Callback srvCallBack) {
mBluetoothGattServer = mBluetoothManager.openGattServer(getReactApplicationContext(), mGattServerCallback);
if (mBluetoothGattServer == null) {
srvCallBack.invoke(false);
return;
}
BluetoothGattService gattService = new BluetoothGattService(SERVICE_UUID,
BluetoothGattService.SERVICE_TYPE_PRIMARY);
BluetoothGattCharacteristic mCharacteristics = new BluetoothGattCharacteristic(SERVICE_UUID, 2, 1);
String currentDeviceName = BluetoothAdapter.getDefaultAdapter().getName();
boolean isValAdded = mCharacteristics.setValue(currentDeviceName);
if (isValAdded == false) {
Toast.makeText(getReactApplicationContext(), "Can't add value to characteristics.", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(getReactApplicationContext(), "Value added to characteristics.", Toast.LENGTH_SHORT).show();
}
boolean isCharAdded = gattService.addCharacteristic(mCharacteristics);
if (isCharAdded == false) {
Toast.makeText(getReactApplicationContext(), "Can't add characteristics.", Toast.LENGTH_SHORT).show();
}
boolean isServAdded = mBluetoothGattServer.addService(gattService);
if (isServAdded == true) {
srvCallBack.invoke(true, gattService.getUuid().toString());
return;
}
}
Im not sure if the problem is with the GATT server callback, or is it even needed? Here is my callback
private BluetoothGattServerCallback mGattServerCallback = new BluetoothGattServerCallback() {
#Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
return;
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
return;
}
}
#Override
public void onCharacteristicReadRequest(BluetoothDevice device, int requestId, int offset,
BluetoothGattCharacteristic characteristic) {
if (SERVICE_UUID.equals(characteristic.getUuid())) {
Toast.makeText(getReactApplicationContext(), "Sending device name.", Toast.LENGTH_SHORT).show();
mBluetoothGattServer.sendResponse(device, requestId, BluetoothGatt.GATT_SUCCESS, 0,
characteristic.getValue());
} else {
Toast.makeText(getReactApplicationContext(), "uuid didn't matched.", Toast.LENGTH_SHORT).show();
}
}
};

Google Play Sign in Failure Api Exception 4

Im trying to integrate google sign in and took the code from another project that it works on, but for the new app it goes thru the log in but the dialog to allow doesnt show up and instead I get sign in failure with Api Exception 4.
Here is all the applicable code:
//Create the client used to sign in to Google services
mGoogleSignInClient = GoogleSignIn.getClient(this,
new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN)
.requestServerAuthCode(getString(R.string.client_id))
.requestEmail()
.build());
private void signInSilently(){
Log.d(TAG, "signInSilently()");
mGoogleSignInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
#Override
public void onComplete(#NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
Log.d(TAG, "signInSilently(): success");
onConnected(task.getResult());
} else {
Log.d(TAG, "signInSilently(): failure", task.getException());
onDisconnected();
}
}
});
}
private void startSignInIntent() {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
onConnected(account);
} catch (ApiException apiException) {
String message = apiException.getMessage();
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error);
}
onDisconnected();
new AlertDialog.Builder(this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}
}
}
private void onDisconnected() {
Log.d(TAG, "onDisconnected()");
mPlayersClient = null;
// Show sign-in button on main menu
if(game.user != null) {
game.user.setDisplayName(null);
game.user.setPlayerID(null);
}
}
private void onConnected(final GoogleSignInAccount googleSignInAccount) {
Log.d(TAG, "onConnected(): connected to Google APIs");
GamesClient gamesClient = Games.getGamesClient(AndroidLauncher.this, googleSignInAccount);
View view = ((AndroidGraphics) Gdx.graphics).getView();
gamesClient.setViewForPopups(view);
gamesClient.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
mPlayersClient = Games.getPlayersClient(this, googleSignInAccount);
// Set the greeting appropriately on main menu
mPlayersClient.getCurrentPlayer()
.addOnCompleteListener(new OnCompleteListener<Player>() {
#Override
public void onComplete(#NonNull Task<Player> task) {
String displayName;
if (task.isSuccessful()) {
user = new User();
user.setDisplayName(task.getResult().getDisplayName());
user.setPlayerID(task.getResult().getPlayerId());
game.user = user;
firebaseAuthWithPlayGames(googleSignInAccount);
} else {
Exception e = task.getException();
handleException(e, getString(R.string.players_exception));
displayName = "???";
}
}
});
}
private void handleException(Exception e, String details) {
int status = 0;
if (e instanceof ApiException) {
ApiException apiException = (ApiException) e;
status = apiException.getStatusCode();
}
String message = getString(R.string.status_exception_error, details, status, e);
new AlertDialog.Builder(AndroidLauncher.this)
.setMessage(message)
.setNeutralButton(android.R.string.ok, null)
.show();
}

Extent report is throwing Close was called before test could end safely using EndTest

I am getting this error when I am trying to generate extent report.
I have closed the report already with reports.endTest(test);
Here is my code:
#BeforeMethod
public void beforeMethod(Method method) {
test = reports.startTest((this.getClass().getSimpleName() + "::" + method.getName()), method.getName());
test.assignAuthor("Roy");
test.assignCategory("SMOKE TEST");
}
#Test(priority = 0)
public static void initialSetup() throws InterruptedException, IOException {
System.setProperty("webdriver.ie.driver", "\\IEDriverServer.exe");
b = new InternetExplorerDriver();
b.get("https://something.com");
Alert alert = b.switchTo().alert();
String _user_name = "kirstie";
String _password = "88525";
alert.authenticateUsing(new UserAndPassword(_user_name, _password));
b.switchTo().defaultContent();
}
#Test(priority = 1, enabled = true)
public static void secondClient() throws Exception {
b.findElement(By.xpath("//*[#class='main-sidebar open']")).click();
b.findElement(By.xpath("//*[#class='sub-menu group open']/li")).click();
}
#AfterMethod
public void afterMethod(ITestResult iTestResult) throws IOException {
if (iTestResult.getStatus() == ITestResult.FAILURE) {
String screenshotPath = GetScreenshot.capture(driver, "screenShots");
test.log(LogStatus.FAIL, "Screenshot", test.addScreenCapture(screenshotPath));
test.log(LogStatus.FAIL, "Test Case Failed is " + iTestResult.getName());
test.log(LogStatus.FAIL, "Test Case Failed is " + iTestResult.getThrowable());
} else if (iTestResult.getStatus() == ITestResult.SKIP) {
test.log(LogStatus.SKIP, "Test Case Skipped is " + iTestResult.getName());
}
reports.endTest(test);
}
#AfterSuite
public void afterSuite() {
reports.flush();
reports.close();
}
I just Copy and paste the template which I used my project.Hope Your Problem will be solved by using this
WebDriver driver;
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
#BeforeTest
public void setUp() {
// where we need to generate the report
htmlReporter = new ExtentHtmlReporter("Your report Path");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// Set our document title, theme etc..
htmlReporter.config().setDocumentTitle("Rentalhomes");
htmlReporter.config().setReportName("Rentalhomes Production Testing");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
}
#Test
public void HomepageLogo() throws Exception {
test = extent.createTest("rentalhomesHomePage");
//Your Test
}
#AfterMethod
public void setTestResult(ITestResult result) throws IOException {
if (result.getStatus() == ITestResult.FAILURE) {
test.log(Status.FAIL, result.getName());
test.log(Status.FAIL,result.getThrowable());
//test.fail("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SUCCESS) {
test.log(Status.PASS, result.getName());
//test.pass("Screen Shot : " + test.addScreenCaptureFromPath(screenShot));
} else if (result.getStatus() == ITestResult.SKIP) {
test.skip("Test Case : " + result.getName() + " has been skipped");
}
extent.flush();
driver.close();
}
}
Remove //extent.startTest("TestCaseName", "Description"); from your code

How to implement a endless Recylerview?

How to implement a endless Recylerview?
This is Activity code:
public class ShopList extends AppCompatActivity {
RecyclerView rview;
RatingBar ratingbar;
private String `urlParameters`;
Recyclerviewshopl adapter;
String category;
JSONArray arr = null;
private Boolean Isinternetpresent = false;
ConnectionDetector cd;
String cat;
ProgressDialog dialog;
String lat,lon;
TextView nodata;
ImageView oops;
double latitude, longitude;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop_list);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ratingbar = (RatingBar) findViewById(R.id.ratingbar);
List<Itemshopl> rowListItem = getAllItemList();
rview=(RecyclerView)findViewById(R.id.recycleshop);
nodata=(TextView)findViewById(R.id.nodata);
oops=(ImageView)findViewById(R.id.oops);
nodata.setVisibility(View.GONE);
oops.setVisibility(View.GONE);
// LayerDrawable stars = (LayerDrawable) ratingbar.getProgressDrawable();
//stars.getDrawable(5).setColorFilter(Color.parseColor("#26ce61"),
// PorterDuff.Mode.SRC_ATOP);
// stars.getDrawable(1).setColorFilter(Color.YELLOW, PorterDuff.Mode.SRC_ATOP);
/* RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, //width
ViewGroup.LayoutParams.WRAP_CONTENT);//height
rview.setLayoutParams(lp);*/
Bundle extras = getIntent().getExtras();
cat = extras.getString("category");
lat=extras.getString("lat");
lon=extras.getString("lon");
System.out.println("gr++"+cat);
cd = new ConnectionDetector(getApplicationContext());
Isinternetpresent = cd.isConnectingToInternet();
// onBackPressed();
if(Isinternetpresent)
{
shoplist tasku=new shoplist();
tasku.execute(new String[]{"http://abc**.com/****/getshoplist"});
}else{
// Toast.makeText(UserProfileActivity.this,"No Internet connection",Toast.LENGTH_SHORT).show();
showAlertDialog(ShopList.this, "No Internet Connection", "You don't have internet connection.", false);
}
}
public void showAlertDialog(Context context, String title, String message, Boolean status)
{
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
// alertDialog.setIcon((status) ? R.drawable.success : R.drawable.fail);
alertDialog.setButton("OK", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
}
});
alertDialog.show();
}
private List<Itemshopl> getAllItemList() {
List<Itemshopl> allItems = new ArrayList<Itemshopl>();
allItems.add(new Itemshopl());
allItems.add(new Itemshopl());
allItems.add(new Itemshopl());
allItems.add(new Itemshopl());
return allItems;
}
private class shoplist extends AsyncTask<String, String, List<Itemshopl>> {
#Override
protected void onPreExecute() {
super.onPreExecute();
dialog = ProgressDialog.show(ShopList.this, "Loading", "Please Wait...", true);
dialog.show();
}
#Override
protected List<Itemshopl> doInBackground(String... urls) {
URL url;
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
urlParameters = "&cat=" + URLEncoder.encode(cat, "UTF-8")+
"&lat="+ URLEncoder.encode(lat, "UTF-8")+
"&lon="+ URLEncoder.encode(lon, "UTF-8");
url = new URL(urls[0]);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line + "\n");
}
String finalJson = buffer.toString();
List<Itemshopl> itemshoplist = new ArrayList<>();
arr = new JSONArray(finalJson);
for (int i = 0; i < arr.length(); i++) {
JSONObject obj = arr.getJSONObject(i);
/// String state = obj.getString("status");
Itemshopl model = new Itemshopl();
model.setName(obj.getString("shopname"));
model.setcat1(obj.getString("subcat1"));
model.setcat2(","+obj.getString("subcat2"));
model.setcat3(","+obj.getString("subcat3"));
model.setcat4(","+obj.getString("subcat4"));
model.setThumbnailUrl(obj.getString("logo"));
model.setid(obj.getString("id"));
model.setrating(obj.getString("rating"));
model.setreview(obj.getString("reviews")+"Reviews");
model.setcat(obj.getString("category"));
itemshoplist.add(model);
}
// cacheThis.writeObject(ShopList.this, "name", "hai");
return itemshoplist;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(List<Itemshopl> detailsModels) {
super.onPostExecute(detailsModels);
dialog.dismiss();
if (detailsModels != null && detailsModels.size() > 0) {
nodata.setVisibility(View.GONE);
oops.setVisibility(View.GONE);
rview=(RecyclerView)findViewById(R.id.recycleshop);
rview.setHasFixedSize(true);
adapter = new Recyclerviewshopl(getApplicationContext(), detailsModels);
rview.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false));
rview.setAdapter(adapter);
}else
{
nodata.setVisibility(View.VISIBLE);
oops.setVisibility(View.VISIBLE);
}
}
}}
Adapter:
public class Recyclerviewshopl extends RecyclerView.Adapter<Recyclerviewshopl.ViewHolder> {
private List<Itemshopl> itemList;
private Context context;
public Recyclerviewshopl(Context context, List<Itemshopl> itemList) {
this.itemList = itemList;
this.context = context;
}
#Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.name.setText(itemList.get(position).getName());
holder.icons.setImageResource(itemList.get(position).getPhoto());
holder.cat1.setText(itemList.get(position).getcat1());
holder.cat2.setText(itemList.get(position).getcat2());
holder.cat3.setText(itemList.get(position).getcat3());
holder.cat4.setText(itemList.get(position).getcat4());
holder.id.setText(itemList.get(position).getid());
// holder.review.setText(itemList.get(position).getreview());
holder.image.setText(itemList.get(position).getimg());
Glide.with(context).load(itemList.get(position).getThumbnailUrl()).into(holder.icons );
holder.phone.setText(itemList.get(position).getPhone());
holder.cat.setText(itemList.get(position).getcat());
if(itemList.get(position).getrating().equals(""))
{
itemList.get(position).getrating().equals("0");
} else {
//int value= Integer.parseInt(holder.rate.toString());
holder.rate.setRating(Float.parseFloat(itemList.get(position).getrating()));
}
holder.review.setText(itemList.get(position).getreview());
}
public ViewHolder onCreateViewHolder(ViewGroup parent, int i)
{
View layoutview = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardshoplist, null);
ViewHolder sg = new ViewHolder(layoutview);
return sg;
}
#Override
public int getItemCount() {
return this.itemList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView name, cat1,cat2,cat3,cat4,review,image,id,phone,cat;
ImageView photo;
ImageView icons;
RatingBar rate;
public ViewHolder(final View itemView) {
super(itemView);
icons = (ImageView) itemView.findViewById(R.id.img1);
name = (TextView) itemView.findViewById(R.id.shopname);
cat=(TextView)itemView.findViewById(R.id.cat);
cat1=(TextView)itemView.findViewById(R.id.cat1);
cat2=(TextView)itemView.findViewById(R.id.cat2);
cat3=(TextView)itemView.findViewById(R.id.cat3);
cat4=(TextView)itemView.findViewById(R.id.cat4);
review=(TextView)itemView.findViewById(R.id.review);
image=(TextView)itemView.findViewById(R.id.img);
id=(TextView)itemView.findViewById(R.id.idvalue);
phone=(TextView)itemView.findViewById(R.id.phone);
rate=(RatingBar)itemView.findViewById(R.id.ratingbar);
itemView.setOnClickListener(new View.OnClickListener() {
int pos = getAdapterPosition();
#Override
public void onClick(View v) {
int pos = getAdapterPosition();
Intent in = new Intent(v.getContext(),ShopeProfile.class);
in.putExtra("id",id.getText().toString());
in.putExtra("shopname",name.getText().toString());
in.putExtra("phone",phone.getText().toString());
in.putExtra("rate",rate.getRating());
in.putExtra("cat",cat.getText().toString());
v.getContext().startActivity(in);
}
});
}
}
}

Current location on map using WIFI in android

i just need to find the current location on maps using WIFI.I used tha below code to do that.
My code:
public class LocationActivity extends MapActivity implements LocationListener {
private MapView mapView;
private LocationManager locationManager;
private String latitude,longtitude;
#Override
protected boolean isRouteDisplayed() {
return false;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getIntent().getExtras();
latitude = bundle.getString("latitude");
longtitude = bundle.getString("longtitude");
setContentView(R.layout.locationtab);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
locationIdentifier();
}
private void createMyLocOverlay(Double latitude, Double longtitude) {
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.mylocation);
GeoPoint point = new GeoPoint((int) (latitude * 1E6),
(int) (longtitude * 1E6));
OverlayItem overlayitem = new OverlayItem(point, null, "You are here!");
MyLocationOverlay itemizedoverlay = new MyLocationOverlay(drawable,
this);
itemizedoverlay.addOverlay(overlayitem);
MyLocationOverlay overlayToRemove = null;
for (Overlay overlay : mapOverlays) {
if (overlay instanceof MyLocationOverlay) {
overlayToRemove = (MyLocationOverlay) overlay;
}
}
if (overlayToRemove != null) {
mapOverlays.remove(overlayToRemove);
}
mapOverlays.add(itemizedoverlay);
}
public void locationIdentifier() {
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(true);
criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = locationManager.getBestProvider(criteria,true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
createMyLocOverlay(location.getLatitude(), location.getLongitude());
Toast.makeText(
this,
"Latitude : " + location.getLatitude() + " : Longtitude : "
+ location.getLongitude(), Toast.LENGTH_LONG)
.show();
} else {
Toast.makeText(this, "Latitude/Longtitude not found",
Toast.LENGTH_LONG).show();
}
}
#Override
public void onLocationChanged(Location location) {
if (location != null) {
createMyLocOverlay(location.getLatitude(), location.getLongitude());
Toast.makeText(
this,
"LocationChanged Latitude : " + location.getLatitude()
+ " Longtitude : " + location.getLongitude(),
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Location is null", Toast.LENGTH_LONG).show();
}
}
#Override
public void onProviderDisabled(String provider) {
Toast.makeText(this, "Disabled provider " + provider, Toast.LENGTH_LONG)
.show();
}
#Override
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_LONG).show();
}
#Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
How could i check it on emulator whether its working or not.?
For now, It is not possible to simulate it using emulator because it is simply doesn't support it. As alternative, you may put a flag constant (e.g. DEBUG=false/true) then if DEBUG=true, use the constant location otherwise use WIFI location.
Or use location provider which can support IP Address location. Which you can use as alternative if DEBUG=true.