本文整理汇总了Java中com.google.firebase.storage.StorageReference类的典型用法代码示例。如果您正苦于以下问题:Java StorageReference类的具体用法?Java StorageReference怎么用?Java StorageReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StorageReference类属于com.google.firebase.storage包,在下文中一共展示了StorageReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addImage
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
public void addImage(StorageReference storageRef, String filePath, String storyId) {
storyId += "-photo";
removeStuffWithThisKey(storyId);
final ImageView imageThing = new ImageView(myContext);
int gridThingPixels = (int) myContext.getResources().getDimension(R.dimen.grid_thing);
imageThing.setMaxHeight(gridThingPixels);
imageThing.setMaxWidth(gridThingPixels);
gridContents.add(new TaggedView(imageThing, storyId));
this.notifyDataSetChanged();
// and a photo (up to 10mb)
Task<byte[]> imageDownloadTask = storageRef.child(filePath).getBytes(100 * 1024 * 1024);
imageDownloadTask.addOnCompleteListener(new OnCompleteListener<byte[]>() {
@Override
public void onComplete(@NonNull Task<byte[]> task) {
byte[] imageBytes = task.getResult();
Bitmap imageBitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
imageThing.setImageBitmap(imageBitmap);
StoryAdapter.this.notifyDataSetChanged();
}
});
}
示例2: putImageInStorage
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
/**
* Guardo la imagen en la base de datos de FCM
* @param storageReference
* @param uri
*/
private void putImageInStorage(StorageReference storageReference, Uri uri) {
storageReference.putFile(uri).addOnCompleteListener(MensajesActivity.this,
new OnCompleteListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
Mensaje friendlyMessage = new Mensaje(null, mUsername, mPhotoUrl, task.getResult().getDownloadUrl().toString());
friendlyMessage.setSenderUid(usuarioSesion.getUid());
friendlyMessage.setReceiverUid(usuarioChat.getUid());
friendlyMessage.setTimestamp(System.currentTimeMillis());
friendlyMessage.setReceiver(usuarioChat.getUser());
sendMessageToFirebaseUser(friendlyMessage,usuarioChat.getFirebaseToken());
} else {
Log.w("Mensajes", "Image upload task was not successful.",
task.getException());
}
}
});
}
示例3: onActivityResult
import com.google.firebase.storage.StorageReference; //导入依赖的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();
}
});
}
}
示例4: onActivityResult
import com.google.firebase.storage.StorageReference; //导入依赖的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();
}
});
}
}
示例5: uploadImageToFirebase
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
private void uploadImageToFirebase(Uri file) {
imageFilename = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
currentUser = mAuth.getCurrentUser();
StorageReference postedImagesRef = mStorageRef.child(currentUser.getUid()).child(imageFilename);
postedImagesRef.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
imageDownloadUrl = taskSnapshot.getDownloadUrl().toString();
Log.d(TAG, "success: Image upload");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "failed: Image upload");
}
});
}
示例6: onActivityResult
import com.google.firebase.storage.StorageReference; //导入依赖的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);
}
});
}
}
示例7: onActivityResult
import com.google.firebase.storage.StorageReference; //导入依赖的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);
}
});
}
}
示例8: sendFileFirebase
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
private void sendFileFirebase(StorageReference storageReference, final Uri file) {
if (storageReference != null) {
final String name = DateFormat.format("yyyy-MM-dd_hhmmss", new Date()).toString();
StorageReference imageGalleryRef = storageReference.child(name + "_gallery");
UploadTask uploadTask = imageGalleryRef.putFile(file);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "onFailure sendFileFirebase " + e.getMessage());
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i(TAG, "onSuccess sendFileFirebase");
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FileModel fileModel = new FileModel("img", downloadUrl.toString(), name, "");
ChatModel chatModel = new ChatModel(userModel, "", Calendar.getInstance().getTime().getTime() + "", fileModel);
mFirebaseDatabaseReference.child(Constants.events).child(evekey).child(Constants.chatmodel).push().setValue(chatModel);
}
});
} else {
//IS NULL
}
}
示例9: onActivityResult
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
StorageReference storageRef = storage.getReferenceFromUrl( Util.URL_STORAGE_REFERENCE ).child( Util.FOLDER_STORAGE_IMG );
if (requestCode == IMAGE_GALLERY_REQUEST) {
if (resultCode == RESULT_OK) {
Uri selectedImageUri = data.getData();
if (selectedImageUri != null) {
sendFileFirebase( storageRef, selectedImageUri );
} else {
//URI IS NULL
}
}
}
}
示例10: sendFileFirebase
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
/**
* Envia o arvquivo para o firebase
*/
private void sendFileFirebase(StorageReference storageReference, final Uri file) {
if (storageReference != null) {
final String name = DateFormat.format("yyyy-MM-dd_hhmmss", new Date()).toString();
StorageReference imageGalleryRef = storageReference.child(name + "_gallery");
UploadTask uploadTask = imageGalleryRef.putFile(file);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "onFailure sendFileFirebase " + e.getMessage());
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i(TAG, "onSuccess sendFileFirebase");
Uri downloadUrl = taskSnapshot.getDownloadUrl();
assert downloadUrl != null;
FileModel fileModel = new FileModel(downloadUrl.toString());
ChatModel chatModel = new ChatModel(userModel, "", Calendar.getInstance().getTime().getTime() + "", fileModel);
mFirebaseDatabaseReference.child(room).push().setValue(chatModel);
}
});
}
}
示例11: uploadImage
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
private void uploadImage(final Item item) {
if (item.getImageUrl() != null) {
Uri uri = Uri.fromFile(new File(item.getImageUrl()));
StorageReference photoRef = mFirebaseStorage.getReference("users")
.child(mFirebaseUser.getUid())
.child("item_photos")
.child(uri.getLastPathSegment());
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("image/webp")
.build();
UploadTask uploadTask = photoRef.putFile(uri, metadata);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests")
Uri downloadUrl = taskSnapshot.getDownloadUrl();
if (downloadUrl != null) {
deleteItemFile(item);
item.setImageUrl(downloadUrl.toString());
mRepository.saveItem(mFirebaseUser.getUid(), item);
mSharedPreferencesHelper.removeImageUploading(item.getId());
}
}
});
}
}
示例12: removeImage
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
private void removeImage(Item item) {
if (item.getImageUrl() != null) {
if (item.getImageUrl().startsWith("https://firebasestorage")) {
StorageReference photoRef = mFirebaseStorage.getReferenceFromUrl(
item.getImageUrl());
photoRef.delete();
item.setImageUrl(null);
mRepository.saveItem(mFirebaseUser.getUid(), item);
} else {
deleteItemFile(item);
item.setImageUrl(null);
if (mFirebaseUser != null) {
mRepository.saveItem(mFirebaseUser.getUid(), item);
}
}
}
}
示例13: download
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void download(String path, long bytesLimit, @NonNull final DownloadCallback<byte[]> callback)
{
StorageReference pathRef = firebaseStorage().getReference().child(path);
pathRef.getBytes(bytesLimit).addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
callback.onFail(e);
}
}).addOnSuccessListener(new OnSuccessListener<byte[]>()
{
@Override
public void onSuccess(byte[] bytes)
{
callback.onSuccess(bytes);
}
});
}
示例14: delete
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void delete(String path, @NonNull final DeleteCallback callback)
{
StorageReference pathRef = firebaseStorage().getReference().child(path);
pathRef.delete().addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
callback.onFail(e);
}
}).addOnSuccessListener(new OnSuccessListener<Void>()
{
@Override
public void onSuccess(Void aVoid)
{
callback.onSuccess();
}
});
}
示例15: addChangeProfilePicListener
import com.google.firebase.storage.StorageReference; //导入依赖的package包/类
private void addChangeProfilePicListener( final DBHelper dbHelper, final String uid ) {
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
pos = position;
new AlertDialog.Builder(PictureGridActivity.this)
.setTitle("Use as profile picture?")
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
StorageReference storageRef = dbHelper.getStorage().getReference("Photo/" + uid + "/" + hashList.get(pos));
storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri downloadUrl) {
dbHelper.getDb().getReference(dbHelper.getUserPath()).child(uid).child("profile_pic").setValue(downloadUrl.toString());
finish();
}
});
}
})
.setNegativeButton(android.R.string.no, null).show();
}
});
}