use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.
the class FirebaseHelper method saveFirebaseMetadata.
public FirebaseMetadata saveFirebaseMetadata(StorageReference storageReference, final String fileLocation, Activity activity) {
// permission check
boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (!hasPermission) {
// no permission
Log.e(TAG, "No permission acquired");
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
} else {
if (isConnected(activity)) {
File file = new File(fileLocation);
storageReference.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successful download at " + fileLocation);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Failed to download");
}
});
} else {
Log.e(TAG, "Not connected to the internet");
}
}
return getFirebaseMetadata(activity);
}
use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.
the class PresetStoreActivity method downloadMetadata.
private void downloadMetadata() {
// loading start
setLoadingFinished(false);
Log.d(TAG, "downloadMetaData");
boolean hasPermission = ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (!hasPermission) {
ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_WRITE_STORAGE);
}
// Make sdcard/Tapad folder
File folder = new File(tapadFolderPath);
if (folder.mkdirs()) {
Log.i(TAG, "folder successfully created");
} else {
// folder exists
Log.e(TAG, "folder already exists");
}
// Make sdcard/Tapad/presets folder
File presets = new File(tapadFolderPath + "/presets");
if (presets.mkdirs()) {
Log.i(TAG, "folder successfully created");
} else {
// folder exists
Log.e(TAG, "folder already exists");
}
final File metadata = new File(tapadFolderPath + "/presets/metadata.txt");
StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets").child("metadata.txt");
metadataReference.getFile(metadata).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successful download at " + metadata.toString());
setAdapter();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "Failed to download");
}
});
}
use of com.google.android.gms.tasks.OnSuccessListener in project duckFood by sanjaytharagesh31.
the class Main2Activity method uploadFile.
// this method is uploading the file
// the code is same as the previous tutorial
// so we are not explaining it
private void uploadFile(Uri data, int r) {
if (r == PICK_PDF_CODE) {
progressBar.setVisibility(View.VISIBLE);
StorageReference sRef = mStorageReference.child("/PDF Uploads/" + editTextFilename.getText().toString() + ".pdf");
sRef.putFile(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
textViewStatus.setText("PDF File Uploaded Successfully");
Upload upload = new Upload(editTextFilename.getText().toString(), taskSnapshot.getDownloadUrl().toString());
mDatabaseReference.child(mDatabaseReference.push().getKey()).setValue(upload);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
textViewStatus.setText((int) progress + "% Uploading...");
}
});
} else if (r == PICK_VIDEO_CODE) {
progressBar.setVisibility(View.VISIBLE);
StorageReference mp4ref = videoStorageRefernce.child("/MP4 Uploads/" + editTextFilename.getText().toString() + ".mp4");
mp4ref.putFile(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
textViewStatus.setText("Video File Uploaded Successfully");
Upload upload = new Upload(editTextFilename.getText().toString(), taskSnapshot.getDownloadUrl().toString());
videoDatabaseRefernce.child(videoDatabaseRefernce.push().getKey()).setValue(upload);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
// Important Code to be added
@SuppressWarnings("VisibleForTests")
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
textViewStatus.setText((int) progress + "% Uploading...");
}
});
} else if (r == PICK_TEXT_CODE) {
progressBar.setVisibility(View.VISIBLE);
StorageReference txtref = textStorageReference.child("/Text Uploads/" + editTextFilename.getText().toString() + ".txt");
txtref.putFile(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
textViewStatus.setText("Text File Uploaded Successfully");
Upload upload = new Upload(editTextFilename.getText().toString(), taskSnapshot.getDownloadUrl().toString());
textDatabaseReference.child(textDatabaseReference.push().getKey()).setValue(upload);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
// Important Code to be added
@SuppressWarnings("VisibleForTests")
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
textViewStatus.setText((int) progress + "% Uploading...");
}
});
} else if (r == PICK_AUDIO_CODE) {
progressBar.setVisibility(View.VISIBLE);
StorageReference audioref = textStorageReference.child("/Audio Uploads/" + editTextFilename.getText().toString() + ".txt");
audioref.putFile(data).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressBar.setVisibility(View.GONE);
textViewStatus.setText("Audio File Uploaded Successfully");
Upload upload = new Upload(editTextFilename.getText().toString(), taskSnapshot.getDownloadUrl().toString());
audioDatabaseReference.child(audioDatabaseReference.push().getKey()).setValue(upload);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
}
}).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
// Important Code to be added
@SuppressWarnings("VisibleForTests")
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
textViewStatus.setText((int) progress + "% Uploading...");
}
});
}
}
use of com.google.android.gms.tasks.OnSuccessListener in project OnlineCanteen by josephgunawan97.
the class RegisterProductActivity method uploadImage.
// To upload image
private void uploadImage() {
Log.d(TAG, "Uploading...");
final StorageReference profileImageRef = FirebaseStorage.getInstance().getReference("product/" + System.currentTimeMillis() + ".jpg");
if (imageUri != null) {
profileImageRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests") Uri downloadUrl = taskSnapshot.getDownloadUrl();
profPicUrl = downloadUrl.toString();
Product productInfo = new Product(user.getUid(), productnameET.getText().toString(), Integer.parseInt(quantityET.getText().toString()), Integer.parseInt(priceET.getText().toString()), profPicUrl);
databaseProducts.push().setValue(productInfo);
// profPicUrl = profileImageRef.toString();
// Toast.makeText(getApplicationContext(),profPicUrl,Toast.LENGTH_LONG).show();
Log.d(TAG, "Success in uploading");
// backToScreen();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getApplicationContext(), "Image failed to upload", Toast.LENGTH_LONG).show();
// backToScreen();
}
});
}
}
use of com.google.android.gms.tasks.OnSuccessListener in project kijenzi-mobile by kijenzi.
the class FirebaseFiles method getFile.
public File getFile(String path, String suffix) {
File file = null;
StorageReference model = ref.child(path);
try {
file = File.createTempFile("design-", suffix);
model.getFile(file).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
System.out.println(taskSnapshot.getTotalByteCount() + " HERE IS THE TOTAL BYTE COUNT");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
System.out.println("FAILED");
}
});
} catch (IOException e) {
e.printStackTrace();
file = null;
System.out.println("FAILED");
}
return file;
}
Aggregations