use of com.google.android.gms.common.api.GoogleApiClient in project Android-ReactiveLocation by mcharmas.
the class BaseObservable method call.
@Override
public void call(Subscriber<? super T> subscriber) {
final GoogleApiClient apiClient = createApiClient(subscriber);
try {
apiClient.connect();
} catch (Throwable ex) {
subscriber.onError(ex);
}
subscriber.add(Subscriptions.create(new Action0() {
@Override
public void call() {
if (apiClient.isConnected() || apiClient.isConnecting()) {
onUnsubscribed(apiClient);
apiClient.disconnect();
}
}
}));
}
use of com.google.android.gms.common.api.GoogleApiClient in project muzei by romannurik.
the class ActivateMuzeiIntentService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String action = intent.getAction();
if (TextUtils.equals(action, ACTION_MARK_NOTIFICATION_READ)) {
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
return;
} else if (TextUtils.equals(action, ACTION_REMOTE_INSTALL_MUZEI)) {
Intent remoteIntent = new Intent(Intent.ACTION_VIEW).addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse("market://details?id=" + getPackageName()));
RemoteIntent.startRemoteActivity(this, remoteIntent, new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
if (resultCode == RemoteIntent.RESULT_OK) {
FirebaseAnalytics.getInstance(ActivateMuzeiIntentService.this).logEvent("activate_notif_install_sent", null);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
} else {
Toast.makeText(ActivateMuzeiIntentService.this, R.string.activate_install_failed, Toast.LENGTH_SHORT).show();
}
}
});
return;
}
// else -> Open on Phone action
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
return;
}
Set<Node> nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_REACHABLE).await().getCapability().getNodes();
if (nodes.isEmpty()) {
Toast.makeText(this, R.string.activate_failed, Toast.LENGTH_SHORT).show();
} else {
FirebaseAnalytics.getInstance(this).logEvent("activate_notif_message_sent", null);
// Show the open on phone animation
Intent openOnPhoneIntent = new Intent(this, ConfirmationActivity.class);
openOnPhoneIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
openOnPhoneIntent.putExtra(ConfirmationActivity.EXTRA_ANIMATION_TYPE, ConfirmationActivity.OPEN_ON_PHONE_ANIMATION);
startActivity(openOnPhoneIntent);
// Clear the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.cancel(INSTALL_NOTIFICATION_ID);
preferences.edit().putBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, true).apply();
// Send the message to the phone to open Muzei
for (Node node : nodes) {
Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), "notification/open", null).await();
}
}
googleApiClient.disconnect();
}
use of com.google.android.gms.common.api.GoogleApiClient in project muzei by romannurik.
the class ActivateMuzeiIntentService method maybeShowActivateMuzeiNotification.
public static void maybeShowActivateMuzeiNotification(Context context) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
if (preferences.getBoolean(ACTIVATE_MUZEI_NOTIF_SHOWN_PREF_KEY, false)) {
return;
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
StatusBarNotification[] notifications = notificationManager.getActiveNotifications();
boolean hasInstallNotification = false;
boolean hasActivateNotification = false;
for (StatusBarNotification notification : notifications) {
if (notification.getId() == INSTALL_NOTIFICATION_ID) {
hasInstallNotification = true;
} else if (notification.getId() == ACTIVATE_NOTIFICATION_ID) {
hasActivateNotification = true;
}
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setSmallIcon(R.drawable.ic_stat_muzei).setColor(ContextCompat.getColor(context, R.color.notification)).setPriority(NotificationCompat.PRIORITY_MAX).setDefaults(NotificationCompat.DEFAULT_VIBRATE).setAutoCancel(true).setContentTitle(context.getString(R.string.activate_title));
Intent deleteIntent = new Intent(context, ActivateMuzeiIntentService.class);
deleteIntent.setAction(ACTION_MARK_NOTIFICATION_READ);
builder.setDeleteIntent(PendingIntent.getService(context, 0, deleteIntent, 0));
// Check if the Muzei main app is installed
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(context).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
Set<Node> nodes = new TreeSet<>();
if (connectionResult.isSuccess()) {
nodes = Wearable.CapabilityApi.getCapability(googleApiClient, "activate_muzei", CapabilityApi.FILTER_ALL).await().getCapability().getNodes();
googleApiClient.disconnect();
}
if (nodes.isEmpty()) {
if (hasInstallNotification) {
// No need to repost the notification
return;
}
// Send an install Muzei notification
if (PlayStoreAvailability.getPlayStoreAvailabilityOnPhone(context) != PlayStoreAvailability.PLAY_STORE_ON_PHONE_AVAILABLE) {
builder.setContentText(context.getString(R.string.activate_no_play_store));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_no_play_store", null);
} else {
builder.setContentText(context.getString(R.string.activate_install_muzei));
Intent installMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
installMuzeiIntent.setAction(ACTION_REMOTE_INSTALL_MUZEI);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, installMuzeiIntent, 0);
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_install_action), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
builder.extend(new NotificationCompat.WearableExtender().setContentAction(0));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_play_store", null);
}
notificationManager.notify(INSTALL_NOTIFICATION_ID, builder.build());
return;
}
// else, Muzei is installed on the phone/tablet, but not activated
if (hasInstallNotification) {
// Clear any install Muzei notification
notificationManager.cancel(INSTALL_NOTIFICATION_ID);
}
if (hasActivateNotification) {
// No need to repost the notification
return;
}
String nodeName = nodes.iterator().next().getDisplayName();
builder.setContentText(context.getString(R.string.activate_enable_muzei, nodeName));
Intent launchMuzeiIntent = new Intent(context, ActivateMuzeiIntentService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, launchMuzeiIntent, 0);
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.open_on_phone, context.getString(R.string.activate_action, nodeName), pendingIntent).extend(new NotificationCompat.Action.WearableExtender().setHintDisplayActionInline(true).setAvailableOffline(false)).build());
Bitmap background = null;
try {
background = BitmapFactory.decodeStream(context.getAssets().open("starrynight.jpg"));
} catch (IOException e) {
Log.e(TAG, "Error reading default background asset", e);
}
builder.extend(new NotificationCompat.WearableExtender().setContentAction(0).setBackground(background));
FirebaseAnalytics.getInstance(context).logEvent("activate_notif_installed", null);
notificationManager.notify(ACTIVATE_NOTIFICATION_ID, builder.build());
}
use of com.google.android.gms.common.api.GoogleApiClient in project coins-android by bubelov.
the class SignInActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
ButterKnife.bind(this);
toolbar.setNavigationOnClickListener(v -> supportFinishAfterTransition());
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(BuildConfig.GOOGLE_CLIENT_ID).requestEmail().build();
googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions).addApi(Auth.CREDENTIALS_API).build();
}
use of com.google.android.gms.common.api.GoogleApiClient in project OneSignal-Android-SDK by OneSignal.
the class LocationGMS method startGetLocation.
// Started from this class or PermissionActivity
static void startGetLocation() {
// Prevents overlapping requests
if (fallbackFailThread != null)
return;
try {
startFallBackThread();
if (locationHandlerThread == null)
locationHandlerThread = new LocationHandlerThread();
GoogleApiClientListener googleApiClientListener = new GoogleApiClientListener();
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(classContext).addApi(LocationServices.API).addConnectionCallbacks(googleApiClientListener).addOnConnectionFailedListener(googleApiClientListener).setHandler(locationHandlerThread.mHandler).build();
mGoogleApiClient = new GoogleApiClientCompatProxy(googleApiClient);
mGoogleApiClient.connect();
} catch (Throwable t) {
OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "Location permission exists but there was an error initializing: ", t);
fireFailedComplete();
}
}
Aggregations