com.google.android.gms.tasks.Task.addOnSuccessListener()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(202)

本文整理了Java中com.google.android.gms.tasks.Task.addOnSuccessListener()方法的一些代码示例,展示了Task.addOnSuccessListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.addOnSuccessListener()方法的具体详情如下:
包路径:com.google.android.gms.tasks.Task
类名称:Task
方法名:addOnSuccessListener

Task.addOnSuccessListener介绍

暂无

代码示例

代码示例来源:origin: survivingwithandroid/Surviving-with-android

private void getConnection(String endpointId) {
  Nearby.getConnectionsClient(ctx)
      .requestConnection(endpointId, endpointId,connectionLifecycleCallback)
      .addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
          Log.d(TAG, "Requesting connection..");
        }
      })
      .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
          Log.e(TAG, "Error requesting connection", e);
        }
      });
}

代码示例来源:origin: survivingwithandroid/Surviving-with-android

public NearbyDsvManager(Context ctx, final EventListener listener) {
  this.listener = listener;
  this.ctx = ctx;
  Log.i(TAG, "NearbyDsvManager");
  Nearby.getConnectionsClient(ctx)
      .startDiscovery(SERVICE_ID,
          endpointDiscoveryCB,
          new DiscoveryOptions(Strategy.P2P_STAR))
      .addOnSuccessListener(
          new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
              Log.i(TAG, "OnSuccess...");
              listener.startDiscovering();
            }
          }
      )
      .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
          Log.e(TAG, "OnFailure", e);
          e.printStackTrace();
        }
      });
}

代码示例来源:origin: survivingwithandroid/Surviving-with-android

public NearbyAdvManager(Context ctx, EventListener listener) {
  Log.d(TAG, "Constructor..");
  this.ctx = ctx;
  this.listener = listener;
  client = Nearby.getConnectionsClient(ctx);
  client.startAdvertising("AndroidThings",
      SERVICE_ID,
      connectionLifeCycleCB,
      new AdvertisingOptions(Strategy.P2P_STAR))
      .addOnSuccessListener(
          new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
              Log.i(TAG, "OnSuccess...");
            }
          }
      )
      .addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
          Log.e(TAG, "OnFailure 1");
          e.printStackTrace();
        }
      });
}

代码示例来源:origin: mohak1712/UberUX

@RequiresPermission(Manifest.permission.ACCESS_FINE_LOCATION)
private void onLocationPermissionGranted() {
  if (!checkPermission()) return;
  mMap.getUiSettings().setMyLocationButtonEnabled(false);
  mMap.setMyLocationEnabled(true);
  mFusedLocationClient.getLastLocation()
      .addOnSuccessListener(this, new OnSuccessListener<Location>() {
        @Override
        public void onSuccess(Location location) {
          if (location != null) {
            userLocation = location;
            CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()))
                .zoom(17)
                .build();
            addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude()));
            mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
          } else {
            userLocation = null;
          }
        }
      });
}

代码示例来源:origin: chat-sdk/chat-sdk-android

fileRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
  @Override
  public void onSuccess(Uri uri) {

代码示例来源:origin: ruuvi/com.ruuvi.station

private void updateLocation() {
  if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
      @Override
      public void onSuccess(Location location) {
        tagLocation = location;
      }
    });
  }
}

代码示例来源:origin: ianhanniballake/TripleSolitaire

@Override
  public void onClick(final View v) {
    Games.getAchievementsClient(TripleSolitaireActivity.this, mGoogleSignInAccount)
        .getAchievementsIntent()
        .addOnSuccessListener(TripleSolitaireActivity.this,
            new OnSuccessListener<Intent>() {
              @Override
              public void onSuccess(final Intent intent) {
                startActivityForResult(intent, REQUEST_ACHIEVEMENTS);
              }
            });
  }
});

代码示例来源:origin: ianhanniballake/TripleSolitaire

@Override
  public void onClick(final View v) {
    Games.getLeaderboardsClient(TripleSolitaireActivity.this, mGoogleSignInAccount)
        .getAllLeaderboardsIntent()
        .addOnSuccessListener(TripleSolitaireActivity.this,
            new OnSuccessListener<Intent>() {
              @Override
              public void onSuccess(final Intent intent) {
                startActivityForResult(intent, REQUEST_LEADERBOARDS);
              }
            });
  }
});

代码示例来源:origin: FrangSierra/RxFirebase

public static <T> void assignOnTask(MaybeEmitter<? super T> emitter, Task<T> task) {
  RxHandler handler = new RxHandler(emitter);
  task.addOnSuccessListener(handler);
  task.addOnFailureListener(handler);
  try {
    task.addOnCompleteListener(handler);
  } catch (Throwable t) {
    // ignore
  }
}

代码示例来源:origin: FrangSierra/RxFirebase

public static <T> void assignOnTask(CompletableEmitter completableEmitter, Task<T> task) {
  RxCompletableHandler handler = new RxCompletableHandler(completableEmitter);
  task.addOnFailureListener(handler);
  task.addOnSuccessListener(handler);
  try {
    task.addOnCompleteListener(handler);
  } catch (Throwable t) {
    // ignore
  }
}

代码示例来源:origin: ruuvi/com.ruuvi.station

private void updateLocation() {
  FusedLocationProviderClient mFusedLocationClient = LocationServices.getFusedLocationProviderClient(getApplicationContext());
  if (ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    mFusedLocationClient.getLastLocation().addOnSuccessListener(new OnSuccessListener<Location>() {
      @Override
      public void onSuccess(Location location) {
        tagLocation = location;
      }
    });
  }
}

代码示例来源:origin: nmoskalenko/RxFirebase

public static <T> void assignOnTask(Subscriber<? super T> observer, Task<T> task) {
  RxTask handler = new RxTask(observer);
  task.addOnSuccessListener(handler);
  task.addOnFailureListener(handler);
  try {
    task.addOnCompleteListener(handler);
  } catch (Throwable t) {
    // ignore
  }
}

代码示例来源:origin: firebase/snippets-android

public void linkCredential(AuthCredential credential) {
  // [START ddl_referral_link_cred]
  FirebaseAuth.getInstance().getCurrentUser()
      .linkWithCredential(credential)
      .addOnSuccessListener(new OnSuccessListener<AuthResult>() {
        @Override
        public void onSuccess(AuthResult authResult) {
          // Complete any post sign-up tasks here.
        }
      });
  // [END ddl_referral_link_cred]
}

代码示例来源:origin: nmoskalenko/RxFirebase

private <T> void setupTask(Task<T> task) {
  when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
  when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
  when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}

代码示例来源:origin: nmoskalenko/RxFirebase

private <T> void setupTask(Task<T> task) {
  when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
  when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
  when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}

代码示例来源:origin: FrangSierra/RxFirebase

static <T> void setupTask(Task<T> task) {
  when(task.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(task);
  when(task.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(task);
  when(task.addOnFailureListener(testOnFailureListener.capture())).thenReturn(task);
}

代码示例来源:origin: nmoskalenko/RxFirebase

@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  testOnCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
  testOnSuccessListener = ArgumentCaptor.forClass(OnSuccessListener.class);
  when(mockTask.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(mockTask);
  when(mockTask.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(mockTask);
  when(httpsCallableReference.call()).thenReturn(mockTask);
  when(httpsCallableReference.call(any())).thenReturn(mockTask);
  when(mockFunctions.getHttpsCallable(anyString())).thenReturn(httpsCallableReference);
}

代码示例来源:origin: nmoskalenko/RxFirebase

@Before
public void setup() {
  MockitoAnnotations.initMocks(this);
  testOnCompleteListener = ArgumentCaptor.forClass(OnCompleteListener.class);
  testOnSuccessListener = ArgumentCaptor.forClass(OnSuccessListener.class);
  when(mockTask.addOnCompleteListener(testOnCompleteListener.capture())).thenReturn(mockTask);
  when(mockTask.addOnSuccessListener(testOnSuccessListener.capture())).thenReturn(mockTask);
  when(mockConfig.fetch()).thenReturn(mockTask);
  when(mockConfig.fetch(1)).thenReturn(mockTask);
}

代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app

@Override
public void updateQuizBookmarkStatus(String quizIdentifier, boolean isBookmarked, Callback<Void> callback) {
  if (mCurrentUser == null) {
    mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
  }
  mUsersRef.child(mCurrentUser.getUid()).child(KEY_USER_BOOKMARKS).child(quizIdentifier)
      .setValue(isBookmarked)
      .addOnSuccessListener(aVoid -> callback.onReponse(null))
      .addOnFailureListener(e -> callback.onError());
}

代码示例来源:origin: UdacityAndroidDevScholarship/quiz-app

@Override
public void updateMyAttemptedQuizzes(QuizAttempted quizAttempt, Callback<Void> callback) {
  if (mCurrentUser == null) {
    mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
  }
  mUsersRef.child(mCurrentUser.getUid())
      .child(KEY_USER_ATTEMPTED_QUIZ)
      .child(quizAttempt.getQuizId())
      .setValue(quizAttempt)
      .addOnSuccessListener(aVoid -> callback.onReponse(null))
      .addOnFailureListener(e -> callback.onError());
}

相关文章