use of com.google.firebase.storage.StorageMetadata in project Tapad by berict.
the class PresetStoreActivity method isFirebaseMetadataUpdated.
private boolean isFirebaseMetadataUpdated(Context context) {
isFMUpdated = false;
if (isConnected(context)) {
Log.d(TAG, "Connected to the internet");
StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {
@Override
public void onSuccess(StorageMetadata storageMetadata) {
Log.d(TAG, "Successful getting metadata");
if (storageMetadata.getUpdatedTimeMillis() > new File(metadataLocation).lastModified()) {
// firebase metadata is updated since last download
// get the new updated metadata
Log.d(TAG, "File updated");
isFMUpdated = true;
} else {
Log.d(TAG, "File not updated");
isFMUpdated = false;
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Failed to get metadata");
isFMUpdated = false;
}
});
return isFMUpdated;
} else {
Log.d(TAG, "Disconnected from the internet");
return isFMUpdated;
}
}
use of com.google.firebase.storage.StorageMetadata in project BORED by invent2017.
the class MultiSquawk method uploadImage.
private void uploadImage(Uri file) {
// String fileUri = file.toString();
// File imageFile = new File(fileUri);
StorageMetadata metadata = new StorageMetadata.Builder().setContentType("image/jpg").build();
String imageFileName = file.getLastPathSegment();
// TODO: check if image with same name already exists
UploadTask uploadTask = mStorageRef.child(imageFileName).putFile(file, metadata);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setMessage("Upload failed. Please try again later.").setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent i = new Intent(MultiSquawk.this, MapsActivityCurrentPlace.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
});
builder.create().show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
uploadImageData(taskSnapshot);
}
});
}
Aggregations