I am creating an app like Instagram and I am having a very hard time right now. When the users select an image they click the next button and they go to the next scene to write a caption. But what is happening is that users just upload the pictures and they don't go to the scene to add a caption. They go straight to the scene that is suppose to show AFTER they add a caption.
These are the errors that show up on my LogCat:
07-10 15:23:21.150 30970-31309/tabian.com.hash E/ImageLoader: UIL doesn't support scheme(protocol) by default [com.google.android.gms.tasks.zzu@f488c6e]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
java.lang.UnsupportedOperationException: UIL doesn't support scheme(protocol) by default [com.google.android.gms.tasks.zzu@f488c6e]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromOtherSource(BaseImageDownloader.java:280)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:99)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.downloadImage(LoadAndDisplayImageTask.java:291)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryCacheImageOnDisk(LoadAndDisplayImageTask.java:274)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:230)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
This is the code I believe is failing:
GalleryFragment:
TextView nextScreen = view.findViewById(R.id.tvNext);
nextScreen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: Navigating to the final share screen.");
if(isTaskRoot ()){
Intent intent = new Intent(GalleryFragment.this.getActivity(), NextActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
GalleryFragment.this.startActivity(intent);
}else{
Intent intent = new Intent(GalleryFragment.this.getActivity(), AccountSettingsActivity.class);
intent.putExtra(getString(R.string.selected_image), mSelectedImage);
intent.putExtra(getString(R.string.return_to_fragment), getString(R.string.edit_profile_fragment));
GalleryFragment.this.startActivity(intent);
Objects.requireNonNull(GalleryFragment.this.getActivity()).finish();
}
}
});
UniversalImageLoader:
public static void setImage(String imgURL, ImageView image, final ProgressBar mProgressBar, String append){
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(append + imgURL, image, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
if(mProgressBar != null){
mProgressBar.setVisibility(View.VISIBLE);
}
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
if(mProgressBar != null){
mProgressBar.setVisibility(View.GONE);
}
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if(mProgressBar != null){
mProgressBar.setVisibility(View.GONE);
}
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
if(mProgressBar != null){
mProgressBar.setVisibility(View.GONE);
}
}
});
}
}
EDIT:
private String mAppend = "file:/";
//use the grid adapter to adapter the images to gridview
GridImageAdapter adapter = new
GridImageAdapter(GalleryFragment.this.getActivity(),
R.layout.layout_grid_imageview, mAppend, imgURLs);
gridView.setAdapter(adapter);
if (imgURLs.isEmpty()) {
// Array list is empty, handle accordingly
} else {
//set the first image to be displayed when the activity fragment view is inflated
try {
setImage(imgURLs.get(0), galleryImage, mAppend);
mSelectedImage = imgURLs.get(0);
} catch (ArrayIndexOutOfBoundsException e) {
Log.e(TAG, "setupGridView: ArrayIndexOutOfBoundsException: " + e.getMessage());
}
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: Selected an image: " + imgURLs.get(position));
setImage(imgURLs.get(position), galleryImage, mAppend);
mSelectedImage = imgURLs.get(position);
}
});
}
}
private void setImage(String imgURL, ImageView image, String append){
Log.d(TAG, "setImage: Setting image");
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(append + imgURL, image, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
mProgressBar.setVisibility(View.INVISIBLE);
}
});
}
}
EDIT 2 !!
public static void setImage(String imgURL, ImageView image, final ProgressBar mProgressBar, String append){
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl("Url to storage");
storageRef.child("users/me/profile.png").getDownloadUrl().
addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// HERE will be your proper URI to load by Universal Image Loader
Log.e("uri1", uri.toString());
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle any errors
}
});
Library universalimageloader has a problem with load image that you want to load, because you provide wrong URL to the image.
There is specified URIs in documentation that you need to use to load image. Print your
String imgUrlbefore you load it and tell me what is there?Acceptable URIs examples from library documentation
So... You want to show your photo with this url:
"file:/" + "gs://hash-a921f.appspot.com/photos/users/YqwhCwkBm8WM6Vd3PjcHHPl2suZ2/profile_photo"
This is wrong composed URI. You must to retrieve real URI for your "profile_photo" from firebase.
I think you can do it following this link: https://firebase.google.com/docs/storage/android/download-files#download_data_via_url
You must execute it BEFORE you execute setImage() method.