Change PlayServices alert text - android

I'm using this code to check if Play Services are availble
public static boolean checkPlayServices(Context context, boolean showDialog) {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS) {
if (showDialog) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, (BaseActivity) context, GooglePlayServicesUtil.GOOGLE_PLAY_SERVICES_VERSION_CODE);
dialog.show();
} else {
Log.d("FUApp", "This device is not supported.");
//finish();
}
}
return false;
}
return true;
}
Is it possible to change the Dialog text without having to create a new dialog?
The reason being I only want to show the error if they are trying to use a feature which requires Play Services, and the current text says This app wont work..., whereas I want it to say This feature wont work...

Step 1:
import google-play-services_lib to your workspace
( you can find it on following path: <android-sdk>/extras/google/google_play_services/)
Step 2:
go to its values directory -> strings.xml
and change the text messages which you want to change.
Step 3:
Now come back to your own application, add google-play-services_lib as library project to your application.
You're done !!
EDIT :
Instead of making changes in library's strings.xml, you can override desired string value in your application's strings.xml
i.e.:
<string name="common_google_play_services_enable_text" msgid="227660514972886228">This feature won\'t work unless you enable Google Play services.</string>

Related

What the App is it that package name is android?

I have a list of package name that executed my app.
and the list is like this.
android (?)
com.gau.go.launcherex
android (?)
I confused I never seen this package name (android).
anyone has idea? thx for help.
here is the code to make list of package name
Uri ref = getReferrer();
if (ref != null) {
String host = ref.getHost();
if (host != null && !host.equals("")) {
boolean isWhite = false;
for (String item : whitelist) {
if (item.equals(host)) {
isWhite = true;
break;
}
}
if (!isWhite) {
// add to list
}
}
}
which package you've never seen? can you post more complete log and code which logged these lines? com.gau.go.launcherex is available HERE in Google Play, this is device launcher (what is launcher in HERE). and simple android package may mean app is bring-back from background using some system option, e.g. recents button/menu
edit due code posted in question - some suggestions: instead of for loop just use whiteList.contains(host), if you need to null/empty check host String then use TextUtils.isEmpty

The InAppUpdate dialog pops up every time, even if I click the update button

I have an app published in the play store with versionCode 3, in a new version, I want to implement the in app update functionality, so in build.gradle I add:
implementation 'com.google.android.play:core:1.8.2'
And in the main activity:
public class MainActivity extends BaseActivity {
//...
private AppUpdateManager mAppUpdateManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//....
checkForUpdate();
}
/**
* check for update
*/
private void checkForUpdate() {
// Creates instance of the manager.
mAppUpdateManager = AppUpdateManagerFactory.create(this);
mAppUpdateManager.registerListener(state -> {
if (state.installStatus() == InstallStatus.DOWNLOADED) {
// After the update is downloaded, show a notification
// and request user confirmation to restart the app.
popupSnackbarForCompleteUpdate();
}
});
// Returns an intent object that you use to check for an update.
Task<AppUpdateInfo> appUpdateInfoTask = mAppUpdateManager.getAppUpdateInfo();
// Checks that the platform will allow the specified type of update.
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE
//&& appUpdateInfo.clientVersionStalenessDays() != null
//&& appUpdateInfo.clientVersionStalenessDays() >= DAYS_FOR_FLEXIBLE_UPDATE
&& appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE)) {
// Request the update.
try {
mAppUpdateManager.startUpdateFlowForResult(
// Pass the intent that is returned by 'getAppUpdateInfo()'.
appUpdateInfo,
// Or 'AppUpdateType.IMMEDIATE' for flexible updates.
AppUpdateType.FLEXIBLE,
// The current activity making the update request.
this,
// Include a request code to later monitor this update request.
MY_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
Toast.makeText(this, R.string.update_failed, Toast.LENGTH_SHORT).show();
}
}
});
}
/**
* Displays the snackbar notification and call to action.
*/
private void popupSnackbarForCompleteUpdate() {
final Snackbar snackbar =
Snackbar.make(
findViewById(R.id.activity_main_layout),
R.string.an_update_has_been_just_downloaded,
Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.install, view -> mAppUpdateManager.completeUpdate());
snackbar.setActionTextColor(
ContextCompat.getColor(this, R.color.color_snackbar_action_text_color));
snackbar.show();
}
}
To be able to test this functionality, I change the versionCode to a lower number than the one published in the Playstore (2 in this case and the app published with 3)When I run my app, it shows me the dialog to update the app and when I click the update button the update starts and installs without any errors, but when the app restarts, it shows me the update dialog again and the app seems to be not updated, I don't know if this is a bug in my app or i should upload the app to play store to be working correctly.
I am using a app bundle (.aab)
You need a Signed .apk for In App Update. Apps in debug mode will show you update dialog & even download new version, but app wont be installed/updated.

Disable select button while selecting location of anonymous location using Place picker google API in android

I want to save user form information with location field. For location I want to open google map on some button click and location to be selected when user click on location over map and post-filled location into form.
I found place picker as related solution, So
I have used Place Picker Google API and I am able to open google map, when I move arrow over preferred location and click on Select this location (Appearing black color with now coordinates showing under that).
Confirmation box opens with 2 option :
1.) Change location
2.) Select (Disabled mode)
I want to select anonymous location and return to main activity.
Below is my code :
private TextView get_place;
int PLACE_PICKER_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
get_place = (TextView)findViewById(R.id.textView1);
get_place.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Intent intent;
try {
intent = builder.build(getApplicationContext());
startActivityForResult(intent,PLACE_PICKER_REQUEST );
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
protected void onActivityResult( int requestCode , int resultCode , Intent data ){
if( requestCode == PLACE_PICKER_REQUEST)
{
if(resultCode == RESULT_OK)
{
Place place = PlacePicker.getPlace(data,this);
Double latitude = place.getLatLng().latitude;
Double longitude = place.getLatLng().longitude;
String address = String.valueOf(latitude)+String.valueOf(longitude);
get_place.setText(address);
}
}
}
Current location coordinates not visible
.
After click on SELECT THIS BUTTON, below window opens with Select button is disabled
.
Please let me know, If there is any other best solution.
Code reply will be much helpful or reference link.
Solution: Enable Google Places API for Android from dev console.
I had the same issue (see comments in original post) and it turned out to be caused by a mismatch in the API key entry in the AndroidManifest.xml file.
I'm using Xamarin.Android but the principle should be the same in Java - but your mileage may vary.
Basically my app was using the Maps API and in my manifest I had the API key specified as com.google.android.maps.v2.API_KEY - and everything worked fine. When I implemented the Places Picker i needed to change the key name to com.google.android.geo.API_KEY (I did NOT have to change the key itself!). I had done this for the debug configuration but NOT for the release configuration - which still used the Maps key name. Hence building a releasable package was resulting in a manifest which would satisfy the Maps API but not Places.
Changing the release configuration has resolved my issue.
I faced the same problem and it got resolved when I enabled Google Places API for Android API in my google cloud project.
All answers are either old, or irrelevant. I tried 2 solutions, which worked for me.
Solution 1
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.google.android.gms:play-services-base:9.4.0'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'com.google.android.gms:play-services-contextmanager:9.4.0'
compile 'com.google.android.gms:play-services-places:9.4.0'
compile 'com.google.android.gms:play-services-nearby:9.4.0'
compile 'com.google.android.gms:play-services-maps:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile 'com.google.android.gms:play-services-analytics:9.4.0'
compile 'com.google.android.gms:play-services-location:9.4.0'
Reference : googledocumentation
Solution 2
Google API Console
Identify the Android Key the project is using
Select Android OS, enter the package name and SHA1
Check the google-services.json (from Firebase), it should be using this key.
Rebuild, and everything works well.
You should use this
<application>
...
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>
</application>
instead of
<application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY"/>
<application>
Make sure you have enabled this API in console.developers.google.com
Also (this is was my case) make sure your API key is correct - copy package from gradle applicationId field. Good test will be if you disable restrictions from API key.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode==PLACE_PICKER_REQUEST|requestCode==REQUEST_CHECK_SETTING){
if(resultCode==RESULT_OK) {
mlocationUpdate = true;
// startLocationUpdate();
Place place = PlacePicker.getPlace(data, this);
String str_txt = place.getName().toString();
str_txt += "\n" + place.getAddress().toString();
placeMarkerOnMap(place.getLatLng());
mStringBuilder = new StringBuilder();
String mplacename = String.format("%s", place.getName());
mlatitude = (place.getLatLng().latitude);
mlongitude = (place.getLatLng().longitude);
String maddress = String.format("%s", place.getAddress());
mStringBuilder.append("NAME :");
mStringBuilder.append(mplacename);
mStringBuilder.append("\n");
Log.e("SRC-->",mplacename);
Log.e("THIS-->",maddress);
mStringBuilder.append("ADDRESS :");
mStringBuilder.append(maddress);
/*mStringBuilder.append("\n");*/
if (isPickUp==true){
edt_pickup.setText(mStringBuilder);
isPickUp=false;
}
else if (isDrop==true){
edt_drop.setText(mStringBuilder);
mlatitudeEnd = (place.getLatLng().latitude);
mlongitudeEND = (place.getLatLng().longitude);
isDrop=false;
}
}}
super.onActivityResult(requestCode, resultCode, data);
}
I also had to enable Geocoding API. These are the APIs that I'm using:

How to detect sign out via the Google Play Leaderboards UI?

Signing out or disconnecting the GamesClient is straightforward when it is from your own UI, such as a button on the main menu.
However, users can also sign out from the game from the Google Play UI in the acheivements and leaderboard views displayed by the intents such as getAllLeaderboardsIntent(). (It's a bit hidden, but if you tap the menu in the upper right, it lets you sign out.)
There are a few promising listener interfaces like OnSignOutCompleteListener but they don't seem to work with a sign out via the google UI, only from your own UI calling GamesClient.signOut().
How can I detect that the user has signed out from the leaderboards or achievement intents? Is it possible to have a callback for this?
I want to be able to update my in-game UI to reflect the logged-in status.
Unfortunately GameHelper doesn't detect when you logout from Google play games.
What you need to do is to put this in your onActivityResult() method in your activity.
I encounter a crash error when I tried using aHelper.signOut() when res == RESULT_RECONNECT_REQUIRED is true.
Instead I created a resetAllValues() method which resets back all values to its default in GameHelper.
In my MainActivity.java
protected void onActivityResult(int req, int res, Intent data) {
super.onActivityResult(req, res, data);
if (res == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED) {
aHelper.resetAllValues();
} else {
aHelper.onActivityResult(req, res, data);
}
}
My method in GameHelper.java
public void resetAllValues()
{
mProgressDialog = null;
mAutoSignIn = true;
mUserInitiatedSignIn = false;
mConnectionResult = null;
mSignInError = false;
mExpectingActivityResult = false;
mSignedIn = false;
mDebugLog = false;
}
Duplicate from:
How can i check if user sign's out from games services default view?
As I see it, there is no elegant solution to that. You can check the response_code in onActivityResult for INCONSISTENT_STATE and cut off the GamesClient, but I'm not sure, if you can potetially get to an inconsistent state in any other manner...

How to make an Android app that depends on another app?

If I create an app that depends on another app or apps (eg: the Facebook and Twitter apps), yet they are not installed, is there a method of checking for those dependencies and installing them at the same time as my own app?
I did this in my application which requires the zxing scanner app to be installed.
You will want this inside your onclick or ontouch:
try{
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
startActivityForResult(intent, 0);
} catch (Exception e) {
createAlert("Barcode Scanner not installed!", "This application uses " +
"the open source barcode scanner by ZXing Team, you need to install " +
"this before you can use this software!", true);
}
which calls
public void createAlert(String title, String message, Boolean button) {
// http://androidideasblog.blogspot.com/2010/02/how-to-add-messagebox-in-android.html
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
if ((button == true)) {
alertDialog.setButton("Download Now",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
Intent browserIntent = new Intent(
Intent.ACTION_VIEW,
Uri.parse("market://search?q=pname:com.google.zxing.client.android"));
startActivity(browserIntent);
}
});
}
alertDialog.show();
}
Then after sorting out all that code out I realise you asked for it to be installed at the same time as your app. Not sure if i should post this code, but it may be helpful
Short answer: No, you cannot automatically install other applications as dependencies.
Longer answer:
Android Market does not let you declare other applications to install as a dependency. As a system, Market appears to be designed for single application installs -- not Linux distro style mega dependency graphs.
At runtime, you can test for installed apps and punt your user over to the Market if so. See the techniques suggested by #QuickNick (testing if an app is installed) and #TerryProbert (punting to market) if that's what you want.
Your best bet is probably to design your app to gracefully degrade if dependencies are not available, and suggest (or insist) that they head over to market to install them.
Start from this:
Intent mediaIntent = new Intent("com.example.intent.action.NAME");
// add needed categories
List<ResolveInfo> listResolveInfo = getPackageManager().queryIntentServices(mediaIntent, 0);
if (listResolveInfo.size() != 0) {
//normal behavior
} else {
//install what you need
}
I give you example of querying services. If you want to check activities, then you will call queryIntentActivities().
I think following the pattern outlined in this post on the Android Developer Blog will help you.
http://android-developers.blogspot.com/2009/01/can-i-use-this-intent.html
As TerryProbert points out if you know that the Intent is not available prompt the user to install the missing app.
Here's what I use to return the first mission activity that exists:
try {
Class<?> missionClass = Class.forName(mPackageName+".Mission"+mission);
Method missionDescription;
missionDescription = missionClass.getMethod("missionDescription");
mMissionDescription = (String) missionDescription.invoke(null);
if (mMissionDescription.length() > 0) {
nextMission = mission;
break;
}
} catch (Exception e) {
//DEBUG*/Log.v(this.getClass().getName(), "onResume: Mission no "+mission+" not found: "+e.getMessage());
}
Each mission is held in a separate class, derived from a Mission base class. Derived classes are called Mission1, Mission24 etc.
Not all missions are defined.
The base class has an abstract class missionDescription which returns a string describing the mission.
This code is inside a loop so tests mission=1 to 99, trying to call missionDescription. It returns when the Description for the first mission found is returned.

Categories

Resources