當前位置: 首頁>>代碼示例>>Java>>正文


Java OnSuccessListener類代碼示例

本文整理匯總了Java中com.google.android.gms.tasks.OnSuccessListener的典型用法代碼示例。如果您正苦於以下問題:Java OnSuccessListener類的具體用法?Java OnSuccessListener怎麽用?Java OnSuccessListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OnSuccessListener類屬於com.google.android.gms.tasks包,在下文中一共展示了OnSuccessListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onActivityResult

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == RC_SIGN_IN){
        if (resultCode == RESULT_OK){
            Toast.makeText(this, "Sign in successful", Toast.LENGTH_SHORT).show();
        } else if (requestCode == RESULT_CANCELED){
            Toast.makeText(this, "Sign in cancelled", Toast.LENGTH_SHORT).show();
            finish();
        }
    } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
        Uri selectedImageUri = data.getData();
        StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment());
        photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Uri downloadUrl = taskSnapshot.getDownloadUrl();
                FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
                mMessagesDatabaseReference.push().setValue(friendlyMessage);
            }
        });
    }
}
 
開發者ID:roy09,項目名稱:AyyMate-Android-RealtimeChat,代碼行數:24,代碼來源:PersonalChat.java

示例2: taskChaining

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
private void taskChaining() {
    // [START task_chaining]
    Task<AuthResult> signInTask = FirebaseAuth.getInstance().signInAnonymously();

    signInTask.continueWithTask(new Continuation<AuthResult, Task<String>>() {
        @Override
        public Task<String> then(@NonNull Task<AuthResult> task) throws Exception {
            // Take the result from the first task and start the second one
            AuthResult result = task.getResult();
            return doSomething(result);
        }
    }).addOnSuccessListener(new OnSuccessListener<String>() {
        @Override
        public void onSuccess(String s) {
            // Chain of tasks completed successfully, got result from last task.
            // ...
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            // One of the tasks in the chain failed with an exception.
            // ...
        }
    });
    // [END task_chaining]
}
 
開發者ID:firebase,項目名稱:snippets-android,代碼行數:27,代碼來源:MainActivity.java

示例3: fetchConfig

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void fetchConfig() {
    long cacheExpiration = 3600; // 1 hour in seconds
    // If developer mode is enabled reduce cacheExpiration to 0 so that each fetch goes to the
    // server. This should not be used in release builds.
    if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
        cacheExpiration = 0;
    }
    mFirebaseRemoteConfig.fetch(cacheExpiration)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    // Make the fetched config available via FirebaseRemoteConfig get<type> calls.
                    mFirebaseRemoteConfig.activateFetched();
                    applyRetrievedLengthLimit();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    // There has been an error fetching the config
                    Log.w(TAG, "Error fetching config", e);
                    applyRetrievedLengthLimit();
                }
            });
}
 
開發者ID:firebase,項目名稱:friendlychat-android,代碼行數:26,代碼來源:MainActivity.java

示例4: onActivityResult

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
        Uri uri = data.getData();
        StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment());
        filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                downloadURL = taskSnapshot.getDownloadUrl().toString();
                Picasso.with(getApplicationContext()).load(downloadURL).into(imageItem);
                Toast.makeText(AddItemActivity.this, "Upload Done", Toast.LENGTH_LONG).show();
            }
        });
    }
}
 
開發者ID:ppdesai434,項目名稱:MavsSnapUp,代碼行數:17,代碼來源:AddItemActivity.java

示例5: onActivityResult

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
        showProgressDialog();
        Uri uri = data.getData();
        StorageReference filePath = mStorage.child("fotos").child(uri.getLastPathSegment());

        filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                hideProgressDialog();
                Uri downloadUri = taskSnapshot.getDownloadUrl();
                imageUrl = downloadUri;
                Picasso.with(NewPostActivity.this).load(downloadUri).fit().centerCrop().into(mCriminalPicture);
                Toast.makeText(NewPostActivity.this, R.string.upload__success, Toast.LENGTH_SHORT).show();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                hideProgressDialog();
                Toast.makeText(NewPostActivity.this, R.string.upload_failure, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
 
開發者ID:braulio94,項目名稱:Quadro,代碼行數:27,代碼來源:NewPostActivity.java

示例6: achievement_show_list

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void achievement_show_list() {
	connect();

	if (isConnected()) {
		mAchievementsClient.getAchievementsIntent()
		.addOnSuccessListener(new OnSuccessListener<Intent>() {
			@Override
			public void onSuccess(Intent intent) {
				activity.startActivityForResult(intent, REQUEST_ACHIEVEMENTS);
			}
		})
		.addOnFailureListener(new OnFailureListener() {
			@Override
			public void onFailure(@NonNull Exception e) {
				Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString());
			}
		});

	} else { Log.i(TAG, "PlayGameServices: Google calling connect"); }
}
 
開發者ID:FrogSquare,項目名稱:GodotGoogleService,代碼行數:21,代碼來源:PlayService.java

示例7: leaderboard_show

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void leaderboard_show(final String l_id) {
	connect();

	if (isConnected()) {
		mLeaderboardsClient.getLeaderboardIntent(l_id)
		.addOnSuccessListener(new OnSuccessListener<Intent>() {
			@Override
			public void onSuccess (Intent intent) {
				Log.d(TAG, "Showing::Loaderboard::" + l_id);
				activity.startActivityForResult(intent, REQUEST_LEADERBOARD);
			}
		})
		.addOnFailureListener(new OnFailureListener() {
			@Override
			public void onFailure(@NonNull Exception e) {
				Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString());
			}
		});

	} else { Log.i(TAG, "PlayGameServices: Google not connected calling connect"); }
}
 
開發者ID:FrogSquare,項目名稱:GodotGoogleService,代碼行數:22,代碼來源:PlayService.java

示例8: leaderboard_show_list

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void leaderboard_show_list() {
	connect();

	if (isConnected()) {
		mLeaderboardsClient.getAllLeaderboardsIntent()
		.addOnSuccessListener(new OnSuccessListener<Intent>() {
			@Override
			public void onSuccess (Intent intent) {
				Log.d(TAG, "Showing::Loaderboard::List");
				activity.startActivityForResult(intent, REQUEST_LEADERBOARD);
			}
		})
		.addOnFailureListener(new OnFailureListener() {
			@Override
			public void onFailure(@NonNull Exception e) {
				Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString());
			}
		});

	} else { Log.i(TAG, "PlayGameServices: Google not connected calling connect"); }
}
 
開發者ID:FrogSquare,項目名稱:GodotGoogleService,代碼行數:22,代碼來源:PlayService.java

示例9: requestLastKnownLocation

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@SuppressLint("MissingPermission")
public static void requestLastKnownLocation() {
    final AndroidLocationProvider instance = getInstance();
    if (!instance.hasLocationPermission()) {
        return;
    }
    Log.d(TAG, "Requesting last known location");
    instance.fusedLocationClient.getLastLocation()
            .addOnSuccessListener(getInstance().activity, new OnSuccessListener<android.location.Location>() {
                @Override
                public void onSuccess(android.location.Location androidLocation) {
                    if (androidLocation != null) {
                        instance.onLocationUpdateReceived(androidLocation);
                    } else {
                        Log.w(TAG, "Unable to get last known location");
                    }
                }
            });
}
 
開發者ID:neXenio,項目名稱:BLE-Indoor-Positioning,代碼行數:20,代碼來源:AndroidLocationProvider.java

示例10: updateComment

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void updateComment(String commentId, String commentText, String postId, final OnTaskCompleteListener onTaskCompleteListener) {
    DatabaseReference mCommentReference = database.getReference().child("post-comments").child(postId).child(commentId).child("text");
    mCommentReference.setValue(commentText).addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            if (onTaskCompleteListener != null) {
                onTaskCompleteListener.onTaskComplete(true);
            }
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            if (onTaskCompleteListener != null) {
                onTaskCompleteListener.onTaskComplete(false);
            }
            LogUtil.logError(TAG, "updateComment", e);
        }
    });
}
 
開發者ID:rozdoum,項目名稱:social-app-android,代碼行數:20,代碼來源:DatabaseHelper.java

示例11: onActivityResult

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_SIGN_IN) {
        if (resultCode == RESULT_OK) {
            Toast.makeText(this, "Signed in , Oh yeah", Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(this, "Signed In canceled", Toast.LENGTH_SHORT).show();
            finish();
        }
    }else if (requestCode==RC_PHOTO_PICKER && resultCode == RESULT_OK){
        Uri selectedImageUri = data.getData();
        StorageReference photoRef = photoStorageReference.child(selectedImageUri.getLastPathSegment());

        photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Uri downloadURI = taskSnapshot.getDownloadUrl();

                Message friendlyMessage = new Message(null,mUsername,downloadURI.toString());
                messageDatabaseReference.push().setValue(friendlyMessage);
            }
        });
    }
}
 
開發者ID:Gr8manish,項目名稱:Mchat,代碼行數:26,代碼來源:MainActivity.java

示例12: firebaseAuthWithGoogle

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId());
    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    showProgressDialog(getString(R.string.profile_progress_message));
    mAuth.signInWithCredential(credential)
            .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult result) {
                    handleFirebaseAuthResult(result);
                }
            })
            .addOnFailureListener(this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    FirebaseCrash.logcat(Log.ERROR, TAG, "auth:onFailure:" + e.getMessage());
                    handleFirebaseAuthResult(null);
                }
            });
}
 
開發者ID:firebase,項目名稱:friendlypix-android,代碼行數:20,代碼來源:ProfileActivity.java

示例13: onClick

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
@Override
public void onClick(View v) {
    int id = v.getId();
    switch (id) {
        case R.id.explore_button:
            mAuth.signInAnonymously().addOnSuccessListener(new OnSuccessListener<AuthResult>() {
                @Override
                public void onSuccess(AuthResult authResult) {
                    Intent feedsIntent = new Intent(WelcomeActivity.this, FeedsActivity.class);
                    startActivity(feedsIntent);
                }
            }).addOnFailureListener( new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Toast.makeText(WelcomeActivity.this, "Unable to sign in anonymously.",
                            Toast.LENGTH_SHORT).show();
                        Log.e(TAG, e.getMessage());
                }
            });
            break;
        case R.id.sign_in_button:
            Intent signInIntent = new Intent(this, ProfileActivity.class);
            startActivity(signInIntent);
            break;
    }
}
 
開發者ID:firebase,項目名稱:friendlypix-android,代碼行數:27,代碼來源:WelcomeActivity.java

示例14: fetchConfig

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
public void fetchConfig(){
    long catchExpiration = 3600;

    if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()){
        catchExpiration = 0;
    }
    mFirebaseRemoteConfig.fetch(catchExpiration)
            .addOnSuccessListener(new OnSuccessListener<Void>() {
                @Override
                public void onSuccess(Void aVoid) {
                    mFirebaseRemoteConfig.activateFetched();
                    applyRetrievedLengthLimit();
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.w(TAG, "Error fetching config", e);
                    applyRetrievedLengthLimit();
                }
            });
}
 
開發者ID:rajatdb,項目名稱:FirebaseChatApp,代碼行數:23,代碼來源:MainActivity.java

示例15: processUpload

import com.google.android.gms.tasks.OnSuccessListener; //導入依賴的package包/類
/**
 * Add onFailure and onSuccess listeners to uploadTask.
 *
 * @param uploadTask Upload task which we want to deal with.
 * @param callback   Callback which will be call from {@link UploadTask#addOnFailureListener(OnFailureListener)} and {@link UploadTask#addOnSuccessListener(OnSuccessListener)}
 */
private void processUpload(UploadTask uploadTask, final UploadCallback callback)
{
    uploadTask.addOnFailureListener(new OnFailureListener()
    {
        @Override
        public void onFailure(@NonNull Exception e)
        {
            callback.onFail(e);
        }
    }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
    {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
        {
            FileMetadata fileMetadata = buildMetadata(taskSnapshot);
            callback.onSuccess(fileMetadata);
        }
    });
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:26,代碼來源:Storage.java


注:本文中的com.google.android.gms.tasks.OnSuccessListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。