I want to image in run time through url in android studio..
For example in eclipse find the image through url in that way..
in that case eclipse has provide that code. I have pass image name in imagename and then get image in drawable.
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
how to find that case in android studio.. this code has not accepted in android studio. how to find image in run time
try this code:
check the getIdentifier(...) method signature.
String uri="#drawable/" + imageName;
ivImage.setImageResource(getResources().getIdentifier(uri, null, getPackageName()));
Java is Java.. it doesn't matter whether it is compiled by Android Studio or Eclipse. In your case, I think you have getResource.getIdentifier but you should use getResources().getIdentifier(...)
This work Perfect but when you call drawable image then you Conform the package name should be correct. It work Perfect.
companyLogo.setImageResource(getResourse.getIdentifier
("com.example.moneymanagement:drawable/"+imagename,null,null));
Related
I just install dev-labs-bg /fullscreen-video-view from GitHub and I want to set thumbnail, but the library method use only images from drawable.
val thumbnailResId = R.drawable.video_thumbnail
fullscreenVideoView.videoUrl(videoUrl)
.thumbnail(thumbnailResId)
How I can use image from URL to load into that method.Any clue or this is not postible
It's not supported. I've checked the newest API by myself and can confirm that no method that supports Bitmap or Drawable exists. Here is the snippet from the documentation as a confirmation:
This feature supports loading only drawables from the Android project. Source: https://github.com/dev-labs-bg/fullscreen-video-view#add-thumbnail
A very strange behaviour, while writing code for showing GIF image in image-view.
what i am doing is
InputStream is = this.getResources().openRawResource(R.drawable.logo);
logo is gif image that is in the drawable folder.
when I write that line of code in Eclipse , image loads successfully but when I import that code on Android Studio What I am seeing is an error on R.drawable.logo
and the error is
Expected Resource of type raw
supplying the wrong type of resource identifier. For Example when calling Resources.getString(int id), You should be passing R.string.something not R.drawable.something
one code runs on Eclipse not on Android Studio
I am sure that no problem with the imports.
After doing some R&D i have found a work-around for that
and that is instead of creating drawable folder and put that image into it
create assets folder in main/src/assests and paste that image and then open Input steam.
InputStream is = context.getAssets().open("logo.gif");
that worked for me but sill dont know the answer why
InputStream is = this.getResources().openRawResource(R.drawable.logo);
was not working.
you can try using ion https://github.com/koush/ion#load-an-image-into-an-imageview is a nice library for load images and support gif from local store , resorces or from Url.
Simple solution is using Glide library
compile 'com.github.bumptech.glide:glide:4.3.1'
And Load your ImageView
Glide.with(YourActivity.this).load(R.drawable.your_gif).into(yourImageView);
The is a weird one:
Ref
Drawable image = getResources().getDrawable(R.drawable.mypic);
At first everything was running fine, except the image (which I draw) was missing some shade. So I edit my image away from eclipse and then replace the old mypic.png with the new one. But eclipse refused to see the new image, as if it had already cached the old one and was using that. So I change from mypic.png to mypic1.png, then the line of code kept returning image as null. So I gave up and changed the image name back to mypic.png (I figure I'd let it use the cached one), but eclipse kept on returning image = null.
Any help with this is greatly appreciated.
after modifying png images do F5 on res folder so that eclipse see the the new image
What finally worked for me is this: instead of doing a hot replace and then F5, I removed the images manually first. Only then, I add the new edited version of the images. For some reason eclipse saw the image then. I am still baffled at the problem and doubt it is reproducible. I am including this here in case someone else somehow gets the same problem. F5 didn't work; cleaning didn't work; restarting eclipse and the emulator didn't work. It's all magic to me.
I am very new to Android development.
I am trying to add an image to my Android application by code. I found this, but it is showing some drag and drop way to do it.
I want to do it by coding in my onCreate method.
I managed to do this:
ImageView iv = new ImageView(this);
But could not figure out how to set the image-uri.
I tried the following:
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
with and without # but I think I need to pass an URI.
I tried to create an object of android.net.Uri, but it seems it can not be instantiated.
See the uri you have tried is wrong it is located on your local file system.. Instead try to push the image on the device's sdcard with the help of DDMS of eclipse..
Suppose you have pushed it on /sdcard/your_image.jpg. then in your code set your image path as
imageView.setImageUri (Uri.parse("/sdcard/your_image.jpg"));
I m sure you will get it...
ImageView iv = (ImageView)findViewById(v);
iv.setImageResource(R.drawable.image);
iv.setImageURI(#"C:\Users\SONY\Downloads\slide.butcher.home.jpg");
You are trying pass Uri of image which is stored on your Computer!!!!
Copy that file on your device SD Card.
Suppose you copied it under /sdcard/home.jpg
Then use below code to display it in ImageView.
imageView.setImageUri(Uri.parse("/sdcard/home.jpg"));
i have downloaded the phonegap example from its website.but it doesn't run.i can't find the reason.help me to get the solution please.when i run it shows
"The Web page at file:///andriod_asset/www/index.html could not be loaded as:
The requested file was not found.www/index.html"
I tried with three "///" instead of four, it worked for me. Give a try
super.loadUrl("file:///android_asset/www/index.html");
You've spelt android wrong here:
HERE!!!
file://>>>>>>andriod<<<<<<_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Try out:
file:///android_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Best of luck!
Just a quick comment for other's getting to this same problem, who doesn't have the spelling error. My new app using PhoneGap 0.9.4 was giving this same error box. The solution was to rename phonegap.0.9.4.js and phonegap.0.9.4.jar to just phonegap.jar and phonegap.js. After that it loads up.
You and I did the exact same thing -- flipped the i and the o in android.
Change "andriod" to "android" and it should work :)
I was using capitals for the folder WWW which was causing the same error to be thrown. I have now changed it to lowercase which works well now.