当前位置: 首页>>代码示例>>Java>>正文


Java StorageReference类代码示例

本文整理汇总了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();
        }
    });
}
 
开发者ID:mimming,项目名称:zero-to-app-emojistories,代码行数:31,代码来源:StoryAdapter.java

示例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());
                    }
                }
            });
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:26,代码来源:MensajesActivity.java

示例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();
            }
        });
    }
}
 
开发者ID:ppdesai434,项目名称:MavsSnapUp,代码行数:17,代码来源:AddItemActivity.java

示例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();
            }
        });
    }
}
 
开发者ID:braulio94,项目名称:Quadro,代码行数:27,代码来源:NewPostActivity.java

示例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");
                }
            });
    }
 
开发者ID:sindhu732,项目名称:instagram_clone,代码行数:23,代码来源:UploadActivity.java

示例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);
            }
        });
    }
}
 
开发者ID:Gr8manish,项目名称:Mchat,代码行数:26,代码来源:MainActivity.java

示例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);
            }
        });
    }
}
 
开发者ID:roy09,项目名称:AyyMate-Android-RealtimeChat,代码行数:24,代码来源:MainActivity.java

示例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
    }
}
 
开发者ID:picopalette,项目名称:event-me,代码行数:25,代码来源:MessagingActivity.java

示例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
            }
        }
    }


}
 
开发者ID:picopalette,项目名称:event-me,代码行数:19,代码来源:MessagingActivity.java

示例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);
            }
        });
    }

}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:28,代码来源:ChatActivity.java

示例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());
                }
            }
        });
    }
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:27,代码来源:ImageUploadService.java

示例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);
            }
        }
    }
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:18,代码来源:ImageUploadService.java

示例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);
        }
    });
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:24,代码来源:Storage.java

示例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();
        }
    });
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:24,代码来源:Storage.java

示例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();
        }
    });
}
 
开发者ID:chrisqz95,项目名称:couch-potatoes,代码行数:26,代码来源:PictureGridActivity.java


注:本文中的com.google.firebase.storage.StorageReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。