I have the following code in my app to initiate Map View
private boolean servicesOk() {
int isAvailable = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
} else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
this, GPS_ERRORDIALOG_REQUEST);
dialog.show();
} else {
Toast.makeText(this, "Connect Connect to Maps", Toast.LENGTH_SHORT)
.show();
}
return false;
}
But on the check the isAvailable has the value 9, moreover in LogCat its continously repeating message: Google Play services is invalid. Cannot recover.
Can anyone please tell me, what mistake Am I making?
From the documentation 9 is an invalid/inauthentic install of google play services.
Have you made sure you downloaded and updated gps from the play store?
Related
I am using in-app update but it is not working in production. I tried various ways but could not resolve the issue. The code is in java for android studio project
My code is below:-
private void checkUpdate() {
Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {
Toast.makeText(getApplicationContext(), "Update available", Toast.LENGTH_LONG).show();
startUpdateFlow(appUpdateInfo);
} else if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS){
Toast.makeText(getApplicationContext(), "Reached 2.. ", Toast.LENGTH_LONG).show();
startUpdateFlow(appUpdateInfo);
} else if (appUpdateInfo.updateAvailability()==UpdateAvailability.UPDATE_NOT_AVAILABLE){
Toast.makeText(getApplicationContext(), "Update unavailable", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), StartActivity.class);
startActivity(intent);
finish();
}
});
}
```
Please tell me what is the mistake I am doing
You have not created the code to force App Update. I also created code for app updates and mine is a Flexible update. Match your code with mine and make changes in your code or use my code to test your app.
private void inAppUpdate() {
appUpdateManager = AppUpdateManagerFactory.create(this);
Task<AppUpdateInfo> task = appUpdateManager.getAppUpdateInfo();
task.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
try {
appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, APP_UPDATE_CODE);
} catch (IntentSender.SendIntentException e) {
Log.d("Update", e.getMessage());
}
} else if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {
snackPopup();
}
});
appUpdateManager.registerListener(istListener);
}
Let me know if my code does not work in your app.
Thanks to #Martijn Pieters for reminding me to either tailor my answer or suggest as possible duplicate. I'd agree with #M-Dev you need to call appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.FLEXIBLE, MainActivity.this, APP_UPDATE_CODE); to start the update correctly.
You could also add appUpdateInfoTask.addOnFailureListener {} or appUpdateInfoTask.addOnCompleteListener to check that its successfully checking google play for new versions.
You should check that it works with internal App sharing.
Please also see my post on how Google App signing can cause problems with in-app updates in production
I'm following a tutuorial to use google location services. So, I'm trying to get location using Google API service. But I got isGooglePlayServicesAvailable(this) is deprecated error. Can anyone help. Thanks
Below is my code for checking if Play services exist on device:
private boolean checkPlayServices(){
int resultCode = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if(resultCode != ConnectionResult.SUCCESS){
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)){
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
}else {
Toast.makeText(getApplicationContext(),
"This device is not supported", Toast.LENGTH_LONG)
.show();
finish();
}
return false;
}
return true;
}
Use isGooglePlayServicesAvailable instead
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
The correct way of checking if play services are available is:
private boolean isGooglePlayServicesAvailable(Context context) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int resultCode = googleApiAvailability.isGooglePlayServicesAvailable(context);
return resultCode == ConnectionResult.SUCCESS;
}
Google Apps can access your location, but this functionality may be either enabled or disabled:
How can I programmatically check if a Google App can access your location?
I am use this code but nothing is changing.
boolean servicesOK() {
int isAvailable = GooglePlayServicesUtil
.isGooglePlayServicesAvailable(this);
if (isAvailable == ConnectionResult.SUCCESS) {
return true;
} else if (GooglePlayServicesUtil.isUserRecoverableError(isAvailable)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(isAvailable,
this, AtlastActivity.GPS_ERRORDIALOG_REQUEST);
dialog.show();
} else {
}
I try use Youtube API in my Android App, my app looke like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ytpv = (YouTubePlayerView) findViewById(R.id.youtubeplayer);
ytpv.initialize("this is my key", this);
et = (EditText) findViewById(R.id.eturl);
et.setOnEditorActionListener(this);
}
#Override
public void onInitializationFailure(Provider arg0,YouTubeInitializationResult arg1) {
if(arg1 == YouTubeInitializationResult.DEVELOPER_KEY_INVALID)
Toast.makeText(this, "Initialization Fail- key invalid", Toast.LENGTH_LONG).show();
else if(arg1 == YouTubeInitializationResult.SERVICE_INVALID)
Toast.makeText(this, "Initialization Fail- Service invalid", Toast.LENGTH_LONG).show();
else if(arg1 == YouTubeInitializationResult.INVALID_APPLICATION_SIGNATURE)
Toast.makeText(this, "Initialization Fail- invalid application", Toast.LENGTH_LONG).show();
}
#Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player,boolean wasrestored) {
ytp = player;
Toast.makeText(this, "Initialization Success", Toast.LENGTH_LONG).show();
}
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_GO ){
if(ytp !=null){
ytp.loadVideo(et.getText().toString());
}
}
return false;
}
But when i install on my real device, I get a error : Initialization Fail- Service invalid
I have no idea to fix this error. Let me hear your idea, thank you :)
The Android YouTube API docs at:
https://developers.google.com/youtube/android/player/ includes this note:
Note: Users need to run version 4.2.16 of the mobile YouTube app (or
higher) to use the API.
I was getting a similar error until I upgraded the version of the YouTube app on my testing device.
off topic: just if someone like me stumbles on this thread looking for a SERVICE_DISABLED error, this happens when the Youtube app is disabled.
It gives SERVICE_INVALID error if your clock isn't appropriately set.
I am using android studio with intentintegrator and intentResult classes for a barcode scanner app. The scan button does not open up the camera to scan. I have checked the code with all the tutorials and it is correct with no errors on build. I have all the permissions and libraries imported. All suggestions welcome thanks
I had your same issue and took me alot of time to find the reason...it's due to the permission....check your camera code you will find a code some thing like this:
`if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkPermission()) {
Toast.makeText(this, "Premission granted", Toast.LENGTH_LONG).show();
} else {
requestPermissions();
}
}`
this means that the permission will be send and granted to the devices which have only andriod version "M" or above...you can rewrite the if condition to send the permission to lower versions...for me I made it start from "JELLY_BEAN_MR1" and the if condition is like this :
` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
if (checkPermission()) {
Toast.makeText(this, "Premission granted", Toast.LENGTH_LONG).show();
} else {
requestPermissions();
}
}`
and make sure to rewrite every if condition to the same thing.
Hope this will help you :)