项目:react-native-location-switch
文件:LocationSwitch.java
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsstatusCodes.SUCCESS:
// All location settings are satisfied -> nothing to do
callSuccessCallback();
break;
case LocationSettingsstatusCodes.RESOLUTION_required:
// Location settings are not satisfied. Show the user a dialog to upgrade location settings
try {
// Show the dialog by calling startResolutionForResult(),and check the result
status.startResolutionForResult(mActivity,REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG,"PendingIntent unable to execute request.",e);
callErrorCallback();
}
break;
case LocationSettingsstatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.e(TAG,"Location settings are inadequate,and cannot be fixed here. Dialog not created.");
callErrorCallback();
break;
}
}
项目:q-mail
文件:OpenPgpKeyPreference.java
@Override
public void onReturn(Intent result) {
switch (result.getIntExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS: {
long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID,NO_KEY);
save(keyId);
break;
}
case OpenPgpApi.RESULT_CODE_USER_INteraCTION_required: {
PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
try {
Activity act = (Activity) getContext();
act.startIntentSenderFromChild(
act,pi.getIntentSender(),requestCode,null,0);
} catch (IntentSender.SendIntentException e) {
Log.e(OpenPgpApi.TAG,"SendIntentException",e);
}
break;
}
case OpenPgpApi.RESULT_CODE_ERROR: {
OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
Log.e(OpenPgpApi.TAG,"RESULT_CODE_ERROR: " + error.getMessage());
break;
}
}
}
项目:dbsync
文件:BaseMainDbActivity.java
@OnClick(R.id.btCreateFileForSync)
public void actionCreateFileForSync() {
try {
MetadataChangeSet MetadataChangeSet = new MetadataChangeSet.Builder()
.setMimeType("text/plain").build();
IntentSender intentSender = Drive.DriveApi.newCreateFileActivityBuilder()
.setinitialMetadata(MetadataChangeSet)
.setinitialDriveContents(null)
.setActivityTitle("Create file for sync")
.build(mGoogleapiclient);
startIntentSenderForResult(intentSender,REQUEST_CODE_NEW_FILE,0);
} catch (Exception e) {
Log.w(TAG,"Unable to send intent",e);
}
}
项目:thingplug-app-android
文件:GoogleDriveHandler.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
// Called whenever the API client fails to connect.
Log.i(TAG,"Googleapiclient connection Failed: " + connectionResult.toString());
if (!connectionResult.hasResolution()) {
// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(activity,connectionResult.getErrorCode(),0).show();
return;
}
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized,and an
// authorization
// dialog is displayed to the user.
try {
connectionResult.startResolutionForResult(activity,CONNECTION_Failed_POPUP);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG,"Exception while starting resolution activity",e);
}
}
项目:ProgressManager
文件:a.java
private void startIntentSenderForResultInner(IntentSender intent,String who,int requestCode,Intent fillInIntent,int flagsMask,int flagsValues,Bundle options)
throws IntentSender.SendIntentException {
try {
String resolvedType = null;
if (fillInIntent != null) {
fillInIntent.migrateExtraStreamToClipData();
fillInIntent.preparetoLeaveProcess(this);
resolvedType = fillInIntent.resolveTypeIfNeeded(getContentResolver());
}
int result = ActivityManagerNative.getDefault()
.startActivityIntentSender(mMainThread.getApplicationThread(),intent,fillInIntent,resolvedType,mToken,who,flagsMask,flagsValues,options);
if (result == ActivityManager.START_CANCELED) {
throw new IntentSender.SendIntentException();
}
Instrumentation.checkStartActivityResult(result,null);
} catch (remoteexception e) {
}
if (requestCode >= 0) {
// If this start is requesting a result,we can avoid making
// the activity visible until the result is received. Setting
// this code during onCreate(Bundle savedInstanceState) or onResume() will keep the
// activity hidden during this time,to avoid flickering.
// This can only be done when a result is requested because
// that guarantees we will get @R_94_4045@ion back when the
// activity is finished,no matter what happens to it.
mStartedActivity = true;
}
}
项目:VirtualHook
文件:VPackageInstallerService.java
@Override
public void uninstall(String packageName,String callerPackageName,int flags,IntentSender statusReceiver,int userId) throws remoteexception {
boolean success = VAppManagerService.get().uninstallPackage(packageName);
if (statusReceiver != null) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME,packageName);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS,success ? PackageInstaller.STATUS_SUCCESS : PackageInstaller.STATUS_FAILURE);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE,PackageHelper.deleteStatusToString(success));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS",success ? 1 : -1);
try {
statusReceiver.sendIntent(mContext,fillIn,null);
} catch (IntentSender.SendIntentException e) {
e.printstacktrace();
}
}
}
项目:RxSocialAuth
文件:RxSmartLockPasswordsFragment.java
private void resolveResult(Status status) {
if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_required) {
try {
//status.startResolutionForResult(mActivity,RC_READ);
startIntentSenderForResult(status.getResolution().getIntentSender(),RC_READ,null);
} catch (IntentSender.SendIntentException e) {
e.printstacktrace();
mCredentialsapiclient.disconnect();
mAccountSubject.onError(new Throwable(e.toString()));
}
}
else {
// The user must create an account or sign in manually.
mCredentialsapiclient.disconnect();
mAccountSubject.onError(new Throwable(getString(R.string.status_canceled_request_credential)));
}
}
项目:CouponsTracker
文件:SettingsFragment.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
DebugLog.logMethod();
DebugLog.logMessage("ConnectionResult: " + connectionResult.toString());
DebugLog.logMessage("ConnectionResult error: " + connectionResult.getErrorCode() + "\n" + connectionResult.getErrorMessage());
if (!connectionResult.hasResolution()) {
GoogleApiAvailability.getInstance()
.getErrorDialog(getActivity(),0)
.show();
return;
}
try {
connectionResult.startResolutionForResult(getActivity(),Constants.CONNECTION_RESOLUTION_REQUEST_CODE);
connectionFailed = true;
} catch (IntentSender.SendIntentException e) {
// Unable to resolve,message user appropriately
e.printstacktrace();
DebugLog.logMessage(e.getMessage());
Utilities.showToast(getActivity(),getString(R.string.google_drive_no_resolution));
}
}
项目:TPlayer
文件:VPackageInstallerService.java
@Override
public void uninstall(String packageName,null);
} catch (IntentSender.SendIntentException e) {
e.printstacktrace();
}
}
}
项目:TPlayer
文件:VPackageInstallerService.java
@Override
public void onPackageInstalled(String basePackageName,int returnCode,String msg,Bundle extras) {
final Intent fillIn = new Intent();
fillIn.putExtra(PackageInstaller.EXTRA_PACKAGE_NAME,basePackageName);
fillIn.putExtra(PackageInstaller.EXTRA_SESSION_ID,mSessionId);
fillIn.putExtra(PackageInstaller.EXTRA_STATUS,installStatusToPublicStatus(returnCode));
fillIn.putExtra(PackageInstaller.EXTRA_STATUS_MESSAGE,installStatusToString(returnCode,msg));
fillIn.putExtra("android.content.pm.extra.LEGACY_STATUS",returnCode);
if (extras != null) {
final String existing = extras.getString("android.content.pm.extra.FAILURE_EXISTING_PACKAGE");
if (!TextUtils.isEmpty(existing)) {
fillIn.putExtra(PackageInstaller.EXTRA_OTHER_PACKAGE_NAME,existing);
}
}
try {
mTarget.sendIntent(mContext,null);
} catch (IntentSender.SendIntentException ignored) {
}
}
项目:AndiCar
文件:PreferenceActivity.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (mProgress != null) {
mProgress.dismiss();
}
secureBkGDriveFolderPreference.setEnabled(false);
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(BackupRestorePreferenceFragment.this.getActivity(),ConstantValues.REQUEST_GDRIVE_AUTHORIZATION);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve,message user appropriately
}
} else {
GoogleApiAvailability.getInstance().getErrorDialog(getActivity(),0).show();
}
}
项目:Farmacias
文件:MainActivity.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (mResolvingConnectionError) {
return;
} else if (connectionResult.hasResolution()) {
try {
mResolvingConnectionError = true;
connectionResult.startResolutionForResult(this,REQUEST_RESOLVE_CONNECTION_ERROR);
} catch (IntentSender.SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleapiclient.connect();
}
} else {
// Show dialog using GoogleApiAvailability.getErrorDialog()
showErrorDialog(connectionResult.getErrorCode());
mResolvingConnectionError = true;
}
}
项目:feup-lpoo-armadillo
文件:BaseGameUtils.java
/**
* Resolve a connection failure from
* {@link com.google.android.gms.common.api.Googleapiclient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
*
* @param activity the Activity trying to resolve the connection failure.
* @param client the Googleapiclient instance of the Activity.
* @param result the ConnectionResult received by the Activity.
* @param requestCode a request code which the calling Activity can use to identify the result
* of this resolution in onActivityResult.
* @param fallbackerrorMessage a generic error message to display if the failure cannot be resolved.
* @return true if the connection failure is resolved,false otherwise.
*/
public static boolean resolveConnectionFailure(Activity activity,Googleapiclient client,ConnectionResult result,int fallbackerrorMessage) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(activity,requestCode);
return true;
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
client.connect();
return false;
}
} else {
// not resolvable... so show an error message
int errorCode = result.getErrorCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(errorCode,activity,requestCode);
if (dialog != null) {
dialog.show();
} else {
// no built-in dialog: show the fallback error message
showAlert(activity,activity.getString(fallbackerrorMessage));
}
return false;
}
}
项目:1946
文件:BaseGameUtils.java
/**
* Resolve a connection failure from
* {@link com.google.android.gms.common.api.Googleapiclient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
*
* @param activity the Activity trying to resolve the connection failure.
* @param client the Googleapiclient instance of the Activity.
* @param result the ConnectionResult received by the Activity.
* @param requestCode a request code which the calling Activity can use to identify the result
* of this resolution in onActivityResult.
* @param fallbackerrorMessage a generic error message to display if the failure cannot be resolved.
* @return true if the connection failure is resolved,String fallbackerrorMessage) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(activity,fallbackerrorMessage);
}
return false;
}
}
private void launchPendingIntent(CryptoResultAnnotation cryptoResultAnnotation) {
try {
PendingIntent pendingIntent = cryptoResultAnnotation.getopenPgpPendingIntent();
if (pendingIntent != null) {
messageSecurityMvpView.startPendingIntentForCryptoPresenter(
pendingIntent.getIntentSender(),REQUEST_CODE_UNKNowN_KEY,0);
}
} catch (IntentSender.SendIntentException e) {
Timber.e(e,"SendIntentException");
}
}
项目:ProgressManager
文件:a.java
/**
* Like {@link #startIntentSenderFromChild},but taking a Fragment; see
* {@link #startIntentSenderForResult(IntentSender,int,Intent,int)}
* for more @R_94_4045@ion.
*
* @hide
*/
public void startIntentSenderFromChildFragment(Fragment child,IntentSender intent,int extraFlags,@Nullable Bundle options)
throws IntentSender.SendIntentException {
startIntentSenderForResultInner(intent,child.mWho,options);
}
项目:ProgressManager
文件:a.java
/**
* Same as calling {@link #startIntentSenderFromChild(Activity,IntentSender,* int,Bundle)} with no options.
*/
public void startIntentSenderFromChild(Activity child,int extraFlags)
throws IntentSender.SendIntentException {
startIntentSenderFromChild(child,extraFlags,null);
}
项目:iosched-reader
文件:ViewFilesInAppFolderActivity.java
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!result.hasResolution()) {
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(),this,0).show();
return;
}
try {
result.startResolutionForResult(this,RESOLVE_CONNECTION_REQUEST_CODE);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG,e);
}
}
项目:penguins-in-space
文件:BaseGameUtils.java
/**
* Resolve a connection failure from
* {@link com.google.android.gms.common.api.Googleapiclient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
*
* @param activity the Activity trying to resolve the connection failure.
* @param client the Googleapiclient instance of the Activity.
* @param result the ConnectionResult received by the Activity.
* @param requestCode a request code which the calling Activity can use to identify the result
* of this resolution in onActivityResult.
* @param fallbackerrorMessage a generic error message to display if the failure cannot be resolved.
* @return true if the connection failure is resolved,fallbackerrorMessage);
}
return false;
}
}
项目:BookED
文件:MapsActivity.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
// Start an Activity that tries to resolve the error
connectionResult.startResolutionForResult(this,9000);
} catch (IntentSender.SendIntentException e) {
e.printstacktrace();
}
} else {
Log.i("a","Location services connection Failed with code " + connectionResult.getErrorCode());
}
}
项目:GitHub
文件:MainActivity.java
private void resolveSignInError() {
if (mGoogleConnectionResult.hasResolution()) {
try {
mGoogleIntentInProgress = true;
mGoogleConnectionResult.startResolutionForResult(this,RC_GOOGLE_LOGIN);
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mGoogleIntentInProgress = false;
mGoogleapiclient.connect();
}
}
}
项目:LaunchEnr
文件:Launcher.java
@Override
public void startIntentSenderForResult (IntentSender intent,Bundle options) {
try {
super.startIntentSenderForResult(intent,options);
} catch (IntentSender.SendIntentException e) {
throw new ActivityNotFoundException();
}
}
项目:ProgressManager
文件:a.java
项目:NightSkyGuide
文件:MainActivity.java
private void startLocationUpdates() {
// if settings are satisfied initialize location requests
mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this,new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
locUpdates = true;
// All location settings are satisfied.
//noinspection MissingPermission - this comment needs to stay here to stop inspection on next line
mFusedLocationClient.requestLocationUpdates(mLocationRequest,mLocationCallback,Looper.myLooper());
}
})
// if settings need to be changed prompt user
.addOnFailureListener(this,new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch (statusCode) {
case LocationSettingsstatusCodes.RESOLUTION_required:
// location settings are not satisfied,but this can be fixed by showing the user a dialog.
try {
// show the dialog by calling startResolutionForResult(),and check the result in onActivityResult().
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(MainActivity.this,REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException sendEx) {
// Ignore the error
}
break;
case LocationSettingsstatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
// location settings are not satisfied,however no way to fix the settings so don't show dialog.
Toast.makeText(MainActivity.this,"Location Services Unavailable",Toast.LENGTH_LONG).show();
useGPS = false;
SharedPreferences.Editor edit = preferences.edit();
edit.putBoolean("use_device_location",false);
edit.apply();
break;
}
}
});
}
项目:gdx-gamesvcs
文件:BaseGameUtils.java
/**
* Resolve a connection failure from
* {@link com.google.android.gms.common.api.Googleapiclient.OnConnectionFailedListener#onConnectionFailed(com.google.android.gms.common.ConnectionResult)}
*
* @param activity the Activity trying to resolve the connection failure.
* @param client the Googleapiclient instance of the Activity.
* @param result the ConnectionResult received by the Activity.
* @param requestCode a request code which the calling Activity can use to identify the result
* of this resolution in onActivityResult.
* @param fallbackerrorMessage a generic error message to display if the failure cannot be resolved.
* @return true if the connection failure is resolved,fallbackerrorMessage);
}
return false;
}
}
项目:civify-app
文件:LocationAdapter.java
@NonNull
private ResultCallback<Result> getLocationSettingsResultCallback() {
return new ResultCallback<Result>() {
@Override
public void onResult(@NonNull Result result) {
Status status = result.getStatus();
if (status.getStatusCode() == CommonStatusCodes.SUCCESS) {
Log.i(TAG,"All location settings are satisfied.");
Runnable requestUpdatesTask = new OnPermissionsTask();
if (isConnected()) requestUpdatesTask.run();
else {
mOnConnectedUpdateCallback = requestUpdatesTask;
Log.d(TAG,"Google Api is not connected. "
+ "Updates delayed until Google Api is connected again.");
}
} else if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_required) {
Log.i(TAG,"Location settings are not satisfied. "
+ "Showing the user a dialog to upgrade location settings.");
try {
setRequestingPermissions(true);
// Show the dialog by calling startResolutionForResult(),// and check the result in the onActivityResult() of mContext
status.startResolutionForResult(mContext,REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.wtf(TAG,"PendingIntent unable to execute request",e);
}
} else if (status.getStatusCode()
== LocationSettingsstatusCodes.SETTINGS_CHANGE_UNAVAILABLE) {
if (checkNetwork()) {
Log.w(TAG,"Location settings can't be changed to meet the requirements");
setHasPermissions(false);
mOnPermissionsChangedListeners.run();
setRequestingPermissions(false);
}
}
}
};
}
项目:ProgressManager
文件:a.java
@Override
public void onStartIntentSenderFromFragment(Fragment fragment,@Nullable Intent fillInIntent,Bundle options) throws IntentSender.SendIntentException {
if (mParent == null) {
startIntentSenderForResultInner(intent,fragment.mWho,options);
} else if (options != null) {
mParent.startIntentSenderFromChildFragment(fragment,options);
}
}
项目:AndiCar
文件:TestActivity.java
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
if (connectionResult.hasResolution()) {
try {
connectionResult.startResolutionForResult(this,REQUEST_CODE_RESOLVE_CONNECTION);
} catch (IntentSender.SendIntentException e) {
// Unable to resolve,message user appropriately
}
} else {
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(),0).show();
}
}
项目:android-rxlocationsettings
文件:RxLocationSettings.java
private Single<Boolean> startResolutionForResult(PendingIntent resolution) {
try {
startIntentSenderForResult(resolution.getIntentSender(),LOCATION_SETTINGS_REQUEST,null);
return resolutionResult.firstOrDefault(false).toSingle();
} catch (IntentSender.SendIntentException e) {
Log.w(TAG,"Failed to start resolution for location settings result",e);
return Single.just(false);
}
}
项目:BLE-Indoor-Positioning
文件:AndroidLocationProvider.java
private void setupLocationService() {
Log.v(TAG,"Setting up location service");
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(getLocationRequest());
SettingsClient client = LocationServices.getSettingsClient(activity);
Task<LocationSettingsResponse> task = client.checkLocationSettings(builder.build());
task.addOnSuccessListener(activity,new OnSuccessListener<LocationSettingsResponse>() {
@Override
public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
Log.v(TAG,"Location settings satisfied");
}
});
task.addOnFailureListener(activity,new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
int statusCode = ((ApiException) e).getStatusCode();
switch (statusCode) {
case CommonStatusCodes.RESOLUTION_required:
Log.w(TAG,"Location settings not satisfied,attempting resolution intent");
try {
ResolvableApiException resolvable = (ResolvableApiException) e;
resolvable.startResolutionForResult(activity,REQUEST_CODE_LOCATION_SETTINGS);
} catch (IntentSender.SendIntentException sendIntentException) {
Log.e(TAG,"Unable to start resolution intent");
}
break;
case LocationSettingsstatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.w(TAG,"Location settings not satisfied and can't be changed");
break;
}
}
});
}
项目:TPlayer
文件:PackageInstallerSession.java
@Override
public void commit(IntentSender statusReceiver) throws remoteexception {
final boolean wasSealed;
synchronized (mlock) {
wasSealed = mSealed;
if (!mSealed) {
// Verify that all writers are hands-off
for (FileBridge bridge : mBridges) {
if (!bridge.isClosed()) {
throw new SecurityException("Files still open");
}
}
mSealed = true;
}
// Client staging is fully done at this point
mClientProgress = 1f;
computeProgressLocked(true);
}
if (!wasSealed) {
// Persist the fact that we've sealed ourselves to prevent
// mutations of any hard links we create. We do this without holding
// the session lock,since otherwise it's a lock inversion.
mCallback.onSessionSealedBlocking(this);
}
// This ongoing commit should keep session active,even though client
// will probably close their end.
mActiveCount.incrementAndGet();
final VPackageInstallerService.PackageInstallObserverAdapter adapter
= new VPackageInstallerService.PackageInstallObserverAdapter(mContext,statusReceiver,sessionId,userId);
mHandler.obtainMessage(MSG_COMMIT,adapter.getBinder()).sendToTarget();
}
项目:VirtualHook
文件:PackageInstallerSession.java
@Override
public void commit(IntentSender statusReceiver) throws remoteexception {
final boolean wasSealed;
synchronized (mlock) {
wasSealed = mSealed;
if (!mSealed) {
// Verify that all writers are hands-off
for (FileBridge bridge : mBridges) {
if (!bridge.isClosed()) {
throw new SecurityException("Files still open");
}
}
mSealed = true;
}
// Client staging is fully done at this point
mClientProgress = 1f;
computeProgressLocked(true);
}
if (!wasSealed) {
// Persist the fact that we've sealed ourselves to prevent
// mutations of any hard links we create. We do this without holding
// the session lock,adapter.getBinder()).sendToTarget();
}
项目:MapsWithPlacesAutoComplete
文件:MapsActivity.java
/**
* Method to check if GPS is on or not
*/
private void isGpsOn() {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
.addLocationRequest(mLocationRequest);
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(mGoogleapiclient,builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(@NonNull LocationSettingsResult locationSettingsResult) {
final Status status = locationSettingsResult.getStatus();
switch (status.getStatusCode()) {
case LocationSettingsstatusCodes.SUCCESS:
getCurrentLocationAddress();
break;
case LocationSettingsstatusCodes.RESOLUTION_required:
try {
status.startResolutionForResult(
MapsActivity.this,REQUEST_CHECK_SETTINGS);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG,"Exception : " + e);
}
break;
case LocationSettingsstatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
Log.e(TAG,"Location settings are not satisfied.");
break;
}
}
});
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。