com.google.android.gms.tasks.OnFailureListener Java Examples

The following examples show how to use com.google.android.gms.tasks.OnFailureListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Manager.java    From react-native-fitness with MIT License 9 votes vote down vote up
public void subscribeToSteps(Context context, final Promise promise){
    final GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if(account == null){
        promise.resolve(false);
        return;
    }
    Fitness.getRecordingClient(context, account)
            .subscribe(DataType.TYPE_STEP_COUNT_DELTA)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    promise.resolve(true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.resolve(false);
                }
            });
}
 
Example #2
Source File: NotificationActivity.java    From Hify with MIT License 6 votes vote down vote up
private void updateReadStatus() {

        String read=getIntent().getStringExtra("read");
        if(read.equals("false")){
            Map<String,Object> readMap=new HashMap<>();
            readMap.put("read","true");

            mFirestore.collection("Users").document(current_id).collection("Notifications")
                    .document(getIntent().getStringExtra("doc_id")).update(readMap).addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.i("done","read:true");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i("error","read:false::"+e.getLocalizedMessage());
                }
            });
        }

    }
 
Example #3
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
/**
 * Sends a {@link Payload} to all currently connected endpoints.
 *
 * @param payload The data you want to send.
 */
protected void sendPayload(final String serviceId, final String endpointId, final Payload payload) {
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);

	clientSingleton
		.sendPayload(endpointId, payload)
		.addOnFailureListener(
			new OnFailureListener() {
				@Override
				public void onFailure(@NonNull Exception e) {
					ApiException apiException = (ApiException) e;

					logW("sendPayload() failed.", e);

					onSendPayloadFailed(serviceId, endpointId, payload, apiException.getStatusCode());
				}
			});
}
 
Example #4
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        GeofencingClient geofencingClient = LocationServices.getGeofencingClient(this);
        geofencingClient.addGeofences(createGeofencingRequest(), createGeofencePendingIntent())
                .addOnSuccessListener(this, new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        Toast.makeText(MainActivity.this, "onSuccess()", Toast.LENGTH_SHORT).show();
                    }
                })
                .addOnFailureListener(this, new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(MainActivity.this,
                                "onFailure(): " + e.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                });
    } else {
        ActivityCompat.requestPermissions(this,
                new String[] {android.Manifest.permission.ACCESS_FINE_LOCATION},1);
    }
}
 
Example #5
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
@Override
protected void onStop() {
    super.onStop();

    GeofencingClient geofencingClient = LocationServices.getGeofencingClient(this);
    geofencingClient.removeGeofences(createGeofencePendingIntent())
            .addOnSuccessListener(this, new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    //Success
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    //Failure
                }
            });
}
 
Example #6
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
@ReactMethod
public void rejectConnection(final String serviceId, final String endpointId) {
	final Endpoint endpoint = mEndpoints.get(serviceId+"_"+endpointId);

	logV("rejecting connection from " + endpointId);
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);

	clientSingleton
		.rejectConnection(endpointId)
		.addOnFailureListener(
			new OnFailureListener() {
				@Override
				public void onFailure(@NonNull Exception e) {
					ApiException apiException = (ApiException) e;

					logW("rejectConnection() failed.", e);
				}
			});
}
 
Example #7
Source File: Manager.java    From react-native-fitness with MIT License 6 votes vote down vote up
public void subscribeToActivity(Context context, final Promise promise){
    final GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if(account == null){
        promise.resolve(false);
        return;
    }
    Fitness.getRecordingClient(context, account)
            .subscribe(DataType.TYPE_ACTIVITY_SAMPLES)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    promise.resolve(true);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.resolve(false);
                }
            });

}
 
Example #8
Source File: DriverMapPresenter.java    From ridesharing-android with MIT License 6 votes vote down vote up
public void endRide() {
    if (mState.getOrder() != null) {
        mView.showProgressBar();

        DocumentReference washingtonRef = db.collection("orders").document(mState.getOrder().id);
        washingtonRef
                .update("status", Order.COMPLETED)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        mView.hideProgressBar();
                        Log.d(TAG, "DocumentSnapshot successfully updated!");
                        trackingPresenter.adjustTrackingState();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        mView.hideProgressBar();
                        Log.w(TAG, "Error updating document", e);
                    }
                });
    }
}
 
Example #9
Source File: ProfileActivity.java    From SnapchatClone with MIT License 6 votes vote down vote up
private void saveProfileImage() {
    if (newProfileImageUrl != null) {
        if (!currentProfileImageUrl.equals("default")) {
            StorageReference photoDelete = FirebaseStorage.getInstance().getReferenceFromUrl(currentProfileImageUrl);

            photoDelete.delete().addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    uploadImage();
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    saveProfileImage();
                }
            });
        } else {
            uploadImage();
        }
    } else {
        saveProfile();
    }
}
 
Example #10
Source File: PictureActivity.java    From GoogleFaceDetectDemo with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
    faceDetector.detectInImage(image).addOnSuccessListener(new OnSuccessListener<List<FirebaseVisionFace>>() {
        @Override
        public void onSuccess(List<FirebaseVisionFace> firebaseVisionFaces) {
            faceview.setContent(bitmap, firebaseVisionFaces);
            FirebaseVisionFace face = firebaseVisionFaces.get(0);
            float leftEyeOpenProbability = face.getLeftEyeOpenProbability();
            float rightEyeOpenProbability = face.getRightEyeOpenProbability();
            float smilingProbability = face.getSmilingProbability();

            mFaceBound.setText("Face Bound:  " + "--" + face.getBoundingBox().left + "--" + face.getBoundingBox().top
                    + "--" + face.getBoundingBox().right + "--" + face.getBoundingBox().bottom);
            mEyeLevel.setText("Eye Open Possible:  " + "leftEyeOpenProbability=" + leftEyeOpenProbability +
                    "--rightEyeOpenProbability=" + rightEyeOpenProbability);
            mSmileLevel.setText("Smile Possible:  " + "smilingProbability=" + smilingProbability);

        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {

        }
    });
}
 
Example #11
Source File: BitmapTextRecognizer.java    From VehicleInfoOCR with GNU General Public License v3.0 6 votes vote down vote up
private void detectInVisionImage( FirebaseVisionImage image) {
    detector.processImage(image)
    .addOnSuccessListener(
        new OnSuccessListener<FirebaseVisionText>() {
            // Note: StringBuilder is MUCH MUCH FASTER THAN Strings
            @Override
            public void onSuccess(FirebaseVisionText results) {
               textBlocks = results.getTextBlocks();
               StringBuilder builder = new StringBuilder();
               for (int i = 0; i < textBlocks.size(); i++) {
                   builder.append(textBlocks.get(i).getText());
                }
             allText = builder.toString();
            Log.d(TAG,"Bitmap Success read: "+allText);
            allText = filterCaptcha(allText);
            listener.onCaptchaUpdate(allText);
        }
    })
    .addOnFailureListener(
        new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "Bitmap Text detection failed." + e);
            }
        });
}
 
Example #12
Source File: MainActivity.java    From aircon with MIT License 6 votes vote down vote up
private void loadFireBaseConfig() {
	FirebaseRemoteConfig.getInstance()
	                    .fetch(0)
	                    .addOnSuccessListener(new OnSuccessListener<Void>() {
		                    @Override
		                    public void onSuccess(final Void aVoid) {
			                    FirebaseRemoteConfig.getInstance()
			                                        .activate();
			                    Log.i(App.TAG, "Firebase config loaded");
			                    onFireBaseConfigLoaded();
		                    }
	                    })
	                    .addOnFailureListener(new OnFailureListener() {
		                    @Override
		                    public void onFailure(@NonNull final Exception e) {
			                    Log.e(App.TAG, "Failed to load firebase config: " + e);
			                    onFireBaseConfigLoaded();
		                    }
	                    });
}
 
Example #13
Source File: VisionProcessorBase.java    From fast_qr_reader_view with MIT License 6 votes vote down vote up
private void detectInVisionImage(
            FirebaseVisionImage image,
            final FrameMetadata metadata) {//,
//            final GraphicOverlay graphicOverlay) {
        detectInImage(image)
                .addOnSuccessListener(
                        new OnSuccessListener<T>() {
                            @Override
                            public void onSuccess(T results) {
                                shouldThrottle.set(false);
                                VisionProcessorBase.this.onSuccess(results, metadata);//,
                                //graphicOverlay);
                            }
                        })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                shouldThrottle.set(false);
                                VisionProcessorBase.this.onFailure(e);
                            }
                        });
        // Begin throttling until this frame of input has been processed, either in onSuccess or
        // onFailure.
        shouldThrottle.set(true);
    }
 
Example #14
Source File: NotificationImageReply.java    From Hify with MIT License 6 votes vote down vote up
private void updateReadStatus() {

        String read=getIntent().getStringExtra("read");
        if(read=="false"){
            Map<String,Object> readMap=new HashMap<>();
            readMap.put("read","true");

            mFirestore.collection("Users").document(current_id).collection("Notifications_reply_image")
                    .document(getIntent().getStringExtra("doc_id")).update(readMap).addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.i("done","read:true");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i("error","read:false::"+e.getLocalizedMessage());
                }
            });
        }

    }
 
Example #15
Source File: MainActivity.java    From Hify with MIT License 6 votes vote down vote up
private void updateToken() {

        final String token_id = getApplicationContext().getSharedPreferences(Config.SHARED_PREF, MODE_PRIVATE).getString("regId","");
        Map<String, Object> tokenMap = new HashMap<>();
        tokenMap.put("token_ids", FieldValue.arrayUnion(token_id));

        if(isOnline()) {

            firestore.collection("Users").document(currentuser.getUid()).update(tokenMap)
                    .addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            Log.d("TOKEN", token_id);
                        }
                    })
                    .addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Log.d("Error Token", e.getMessage());
                        }
                    });

        }
    }
 
Example #16
Source File: NotificationReplyActivity.java    From Hify with MIT License 6 votes vote down vote up
private void updateReadStatus() {

        String read=getIntent().getStringExtra("read");
        if(read=="false"){
            Map<String,Object> readMap=new HashMap<>();
            readMap.put("read","true");

            mFirestore.collection("Users").document(current_id).collection("Notifications_reply")
                    .document(getIntent().getStringExtra("doc_id")).update(readMap).addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.i("done","read:true");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i("error","read:false::"+e.getLocalizedMessage());
                }
            });
        }

    }
 
Example #17
Source File: ConnectionsActivity.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a connection request to the endpoint. Either {@link #onConnectionInitiated(Endpoint,
 * ConnectionInfo)} or {@link #onConnectionFailed(Endpoint)} will be called once we've found out
 * if we successfully reached the device.
 */
protected void connectToEndpoint(final Endpoint endpoint) {
  logV("Sending a connection request to endpoint " + endpoint);
  // Mark ourselves as connecting so we don't connect multiple times
  mIsConnecting = true;

  // Ask to connect
  mConnectionsClient
      .requestConnection(getName(), endpoint.getId(), mConnectionLifecycleCallback)
      .addOnFailureListener(
          new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
              logW("requestConnection() failed.", e);
              mIsConnecting = false;
              onConnectionFailed(endpoint);
            }
          });
}
 
Example #18
Source File: NotificationImage.java    From Hify with MIT License 6 votes vote down vote up
private void updateReadStatus() {

        String read=getIntent().getStringExtra("read");
        if(read=="false"){
            Map<String,Object> readMap=new HashMap<>();
            readMap.put("read","true");

            mFirestore.collection("Users").document(current_id).collection("Notifications_image")
                    .document(getIntent().getStringExtra("doc_id")).update(readMap).addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    Log.i("done","read:true");
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.i("error","read:false::"+e.getLocalizedMessage());
                }
            });
        }

    }
 
Example #19
Source File: ViewModels.java    From firebase_mlkit_language with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void handleEvent(final MethodChannel.Result result) {
    FirebaseTranslateModelManager.getInstance().getAvailableModels(FirebaseApp.getInstance())
            .addOnSuccessListener(new OnSuccessListener<Set<FirebaseTranslateRemoteModel>>() {
                @Override
                public void onSuccess(Set<FirebaseTranslateRemoteModel> models) {
                    List<Map<String, Object>> translateModels = new ArrayList<>(models.size());
                    for (FirebaseTranslateRemoteModel model : models) {
                        Map<String, Object> langData = new HashMap<>();
                        langData.put("languageCode", model.getLanguageCode());
                        translateModels.add(langData);
                    }
                    result.success(translateModels);
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    result.error("viewError", e.getLocalizedMessage(), null);
                }
            });
}
 
Example #20
Source File: DeleteModel.java    From firebase_mlkit_language with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void handleEvent(String modelName, final MethodChannel.Result result) {
    FirebaseTranslateRemoteModel model =
            new FirebaseTranslateRemoteModel.Builder(FirebaseTranslateLanguage.languageForLanguageCode(modelName)).build();
    FirebaseTranslateModelManager.getInstance().deleteDownloadedModel(model)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void v) {
                    result.success("Deleted");
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    result.error("deleteError", e.getLocalizedMessage(), null);
                }
            });
}
 
Example #21
Source File: DownloadModel.java    From firebase_mlkit_language with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void handleEvent(String modelName, final MethodChannel.Result result) {
    Integer languageCode = FirebaseTranslateLanguage.languageForLanguageCode(modelName);
    FirebaseModelDownloadConditions conditions = new FirebaseModelDownloadConditions.Builder().build();
    FirebaseTranslateRemoteModel model = new FirebaseTranslateRemoteModel.Builder(languageCode)
            .setDownloadConditions(conditions)
            .build();
    FirebaseTranslateModelManager.getInstance().downloadRemoteModelIfNeeded(model)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void v) {
                    result.success("Downloaded");
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    result.error("downloadError", e.getLocalizedMessage(), null);
                }
            });
}
 
Example #22
Source File: DriverMapPresenter.java    From ridesharing-android with MIT License 6 votes vote down vote up
public void startRide() {
    if (mState.getOrder() != null) {
        mView.showProgressBar();

        DocumentReference washingtonRef = db.collection("orders").document(mState.getOrder().id);
        washingtonRef
                .update("status", Order.STARTED_RIDE)
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        mView.hideProgressBar();
                        Log.d(TAG, "DocumentSnapshot successfully updated!");
                        trackingPresenter.adjustTrackingState();
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        mView.hideProgressBar();
                        Log.w(TAG, "Error updating document", e);
                    }
                });
    }
}
 
Example #23
Source File: PlayGamesPlugin.java    From play_games with MIT License 6 votes vote down vote up
private void signOut() {
    GoogleSignInOptions.Builder builder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    GoogleSignInOptions opts = builder.build();
    GoogleSignInClient signInClient = GoogleSignIn.getClient(registrar.activity(), opts);
    signInClient.signOut().addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            currentAccount = null;
            Map<String, Object> successMap = new HashMap<>();
            successMap.put("type", "SUCCESS");
            result(successMap);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            error("ERROR_SIGN_OUT", e);
            Log.i(TAG, "Failed to signout", e);
        }
    });

}
 
Example #24
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void loadPlayerCenteredScores(String leaderboardId, String timeSpan, String collectionType, int maxResults, boolean forceReload) {
    LeaderboardsClient leaderboardsClient = Games.getLeaderboardsClient(this.registrar.activity(), currentAccount);
    leaderboardsClient.loadPlayerCenteredScores(leaderboardId, convertTimeSpan(timeSpan), convertCollection(collectionType), maxResults, forceReload)
            .addOnSuccessListener(scoreSuccessHandler())
            .addOnFailureListener(new OnFailureListener() {
                                      @Override
                                      public void onFailure(@NonNull Exception e) {
                                          Log.e(TAG, "Could not fetch leaderboard player centered (retrieve failure)", e);
                                          error("LEADERBOARD_PLAYER_CENTERED_FAILURE", e);
                                      }
                                  }
            );
}
 
Example #25
Source File: Manager.java    From react-native-fitness with MIT License 5 votes vote down vote up
public void getDistance(Context context, double startDate, double endDate, String customInterval, final Promise promise) {
    TimeUnit interval = getInterval(customInterval);

    DataReadRequest readRequest = new DataReadRequest.Builder()
            .aggregate(DataType.TYPE_DISTANCE_DELTA, DataType.AGGREGATE_DISTANCE_DELTA)
            .bucketByTime(1, interval)
            .setTimeRange((long) startDate, (long) endDate, TimeUnit.MILLISECONDS)
            .build();

    Fitness.getHistoryClient(context, GoogleSignIn.getLastSignedInAccount(context))
            .readData(readRequest)
            .addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {
                @Override
                public void onSuccess(DataReadResponse dataReadResponse) {
                    if (dataReadResponse.getBuckets().size() > 0) {
                        WritableArray distances = Arguments.createArray();
                        for (Bucket bucket : dataReadResponse.getBuckets()) {
                            List<DataSet> dataSets = bucket.getDataSets();
                            for (DataSet dataSet : dataSets) {
                                processDistance(dataSet, distances);
                            }
                        }
                        promise.resolve(distances);
                    }
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    promise.reject(e);
                }
            })
            .addOnCompleteListener(new OnCompleteListener<DataReadResponse>() {
                @Override
                public void onComplete(@NonNull Task<DataReadResponse> task) {
                }
            });
}
 
Example #26
Source File: MapPresenter.java    From ridesharing-android with MIT License 5 votes vote down vote up
public void cancelOrder() {
    if (orderListenerRegistration != null) {
        orderListenerRegistration.remove();
    }
    if (mState.getOrder() != null) {
        mView.showProgressBar();

        DocumentReference washingtonRef = db.collection("orders").document(mState.getOrder().id);
        washingtonRef
                .update(
                        "status", Order.CANCELLED
                )
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        mView.hideProgressBar();
                        if (mState.getOrder() != null && mState.getOrder().marker != null) {
                            mState.getOrder().marker.remove();
                        }
                        mState.updateOrder(null);
                        mView.dismissOrderInfo();
                        mView.dismissTripEndInfo();
                        onOrderChanged();
                        Log.d(TAG, "DocumentSnapshot successfully updated!");
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        mView.hideProgressBar();
                        Log.w(TAG, "Error updating document", e);
                    }
                });
    }
}
 
Example #27
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void openSnapshot(String snapshotName) {
    SnapshotsClient snapshotsClient = Games.getSnapshotsClient(this.registrar.activity(), currentAccount);
    snapshotsClient.open(snapshotName, true).addOnSuccessListener(generateCallback(snapshotName)).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.e(TAG, "Could not open snapshot", e);
            error("SNAPSHOT_FAILURE", e);
        }
    });
}
 
Example #28
Source File: PlayGamesPlugin.java    From play_games with MIT License 5 votes vote down vote up
public void showAllLeaderboards() {
    Games.getLeaderboardsClient(registrar.activity(), currentAccount).getAllLeaderboardsIntent().addOnSuccessListener(new OnSuccessListener<Intent>() {
        @Override
        public void onSuccess(Intent intent) {
            registrar.activity().startActivityForResult(intent, RC_ALL_LEADERBOARD_UI);
            result(new HashMap<>());
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            error("ERROR_SHOW_LEADERBOARD", e);
        }
    });
}
 
Example #29
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void incrementAchievement(String id, int amount) {
    Games.getAchievementsClient(registrar.activity(), currentAccount).incrementImmediate(id, amount)
            .addOnSuccessListener(new OnSuccessListener<Boolean>() {
                @Override
                public void onSuccess(Boolean b) {
                    result(true);
                }
            }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.e(TAG, "Could not increment achievement", e);
            result(false);
        }
    });
}
 
Example #30
Source File: verifyPatient2.java    From Doctorave with MIT License 5 votes vote down vote up
private  void putInformationInFb(final Context context) {

        // TODO: Send messages on click
        FirebaseDatabase mFirebaseDatabase = FirebaseDatabase.getInstance();
        final DatabaseReference mDatabaseReference = mFirebaseDatabase.getReference();
        Query hekkQuery = mDatabaseReference;

        hekkQuery.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                boolean alreadyHas = false;
                for (DataSnapshot snapshot: dataSnapshot.getChildren()) {
                    if (snapshot.getKey().equals(phone)){
                        alreadyHas = true;
                        saveUserInSP(context);
                    }
                }
                if(!alreadyHas){
                    mDatabaseReference.child(phone).setValue("").addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            saveUserInSP(context);
                        }
                    })
                            .addOnFailureListener(new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {

                                }
                            });
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });

    }