Seventh Edition
7
The $1,000,000,0
It's time to celeb
Q:
Sorting an NSA
package client //
I recently discove
Beta-endorphin doe
Q:
Is there a sta
The present invent
Gmina Stary Targ
Q:
Error 'Failed to find provider info for 'com.google.android.gms.location''
I am new in Android programming. I am doing an Android location tracking in which my application is asking for the location permission after I gave my application location permissions.
In AndroidManifest.xml I have written the below code:
and in android Activity I wrote the following code to initialize Google Location Services:
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(provider, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
After all I am getting error 'Failed to find provider info for com.google.android.gms.location' in my LogCat. Can anyone please help me to solve this error.
A:
This error occurs because of you have written permission in xml, but missed it in java. You need to add permission in java also.
public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private Marker mCurrentPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
if(ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
{
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
//start location service here
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient,
mLocationRequest,
this);
}
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-33.87365, 151.20689);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
For more info check this.
A:
You need to add the following permission in your manifest file.
Hope it works for you.
A:
Just go through the docs for Google Location Service:
Add this permission and build the project.
A:
You need to add the below dependency in your module-level gradle file.
implementation 'com.google.android.gms:play-services-location:15.0.1'
Also need to add the following permission
For Android Manifest
For Gradle
implementation 'com.google.android.gms:play-services-location:15.0.1'
Check Official Documentation
https://developers.google.com/android/guides/setup
Note:
Add this code in your app level gradle file
defaultConfig {
..
..
..
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
}
Also add this code in your build.gradle file of your app.
android {
defaultConfig {
..
..
..
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Check Official Documentation for Release Build Types
https://developer.android.com/topic/libraries/architecture/adding-components.html