如何使用片段中的媒体管理器将图像发布到 cloudinary?
I have downloaded an Image Picker Library that displays my gallery and crops images for me etc. When I receive the URI from the ActivityResultLauncher I try to upload the image that I had just chosen to Cloudinary. However, it never even enters the function as I found out by adding log statements. I have no idea why this is. I even tried to do it asynchronously and still nothing. The Uri is being received as when I load it into the Image View it loads for me.
Here is my ActivitResultLauncher
ActivityResultLauncher<Intent> launcher=
registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),(ActivityResult result)->{
if(result.getResultCode()==RESULT_OK){
Uri uri=result.getData().getData();
Picasso.get().load(uri).into(profilePic);
Log.d(TAG, "Before uploading image: ");
new UploadTask(uri).execute();
}else if(result.getResultCode()==ImagePicker.RESULT_ERROR){
ImagePicker.Companion.getError(result.getData());
}
Log.d(TAG, "afterUploading image");
});
Here is my Async class
public class UploadTask extends AsyncTask<Void, Void, Void> {
private Uri uri;
ProgressDialog progressDialog = new ProgressDialog(requireContext());
public UploadTask(Uri uri){
this.uri = uri;
}
@Override
protected void onPreExecute() {
progressDialog.show();
Log.d(TAG, "onPreExecute method: " + uri);
}
@Override
protected Void doInBackground( Void... voids ) {
uploadCloud( uri);
return null;
}
@Override
protected void onPostExecute( Void res ) {
progressDialog.hide();
}
}
And finally here is the upload to Cloudinary function
public void uploadCloud(Uri uri) {
MediaManager.get().upload(uri).callback(new UploadCallback() {
@Override
public void onStart(String requestId) {
Log.d(TAG, "onStart method");
}
@Override
public void onProgress(String requestId, long bytes, long totalBytes) {
Log.d(TAG, "onProgress method");
}
@Override
public void onSuccess(String requestId, Map resultData) {
Log.d(TAG, "onSuccess method");
}
@Override
public void onError(String requestId, ErrorInfo error) {
Log.d(TAG, "onError: ");
}
@Override
public void onReschedule(String requestId, ErrorInfo error) {
Log.d(TAG, "onReschedule method");
}
});
}
If somebody can point me in the right direction it would be greatly appreciated!
I already have the Cloudinary working in other parts of my project so it has nothing to do with Initialising the MediaManager correctly or anything.
- 本文标签: 家庭宠物
- 本文链接: https://www.coder6.net/article/2352
- 版权声明: 本文由蚂蚁原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权
热门推荐
-
浏览(192) 评论(0)