here is my code to get the location of user Please help me I'm stuck in this part
public class MainActivity extends AppCompatActivity {
LocationManager locationManager;
String provider;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = locationManager.getBestProvider(new Criteria(), true);
Location location =locationManager.getLastKnownLocation(provider);
if (location!=null){
Log.i("Location","Found");
}
else{
Log.i("Location","Not Found");
}
}
}
note:the location is enabled in my phone ,I'm connected to wifi ,I added 2 user permission for location,gps enabled