Android drawable stops being reachable - android

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.

Related

Cache pictures with Picasso and OKHttp

I am trying to cache picture using picasso after doing some home work I figured out picasso doesn't direct cache images. Hence using help from https://gist.github.com/fada21/10655652
This is sucessfully caching image to folders. I can see the files but they don't reload when the phone is offline.
I am loading the images this way:
PicassoBigCache.INSTANCE.getPicassoBigCache(getContext().getApplicationContext()).load(pd.getImage()).placeholder(R.drawable.defaultloading).error(R.drawable.none).resize(238, 250).into(holder.image);
I fixed the loading from cache issue like this:
I used https://gist.github.com/fada21/10655652
And then did the following:
added a variable to check if internet is exists or not...
if (isnetworkavailable.equalsIgnoreCase(mContext.getResources().getString(R.string.yesnetwork)))
{
PicassoBigCache.INSTANCE.getPicassoBigCache(getContext().getApplicationContext()).load(pd.getImage()).placeholder(R.drawable.defaultloading).error(R.drawable.none).resize(238, 250).into(holder.image);
}
else
{
PicassoBigCache.INSTANCE.getPicassoBigCache(getContext().getApplicationContext()).load(pd.getImage()).placeholder(R.drawable.defaultloading).error(R.drawable.none).resize(238, 250).networkPolicy(NetworkPolicy.OFFLINE).into(holder.image);
}
This works fine if I close the app with system.exit or force close.
Not sure if this is right way but I am getting the results. Things are working smoothly. Hope this is useful for somebody!

How to delete an image with phonegap/cordova

For my app, I'm using the Cordova CameraPreview plugin, to take pictures.
Once, a picture is taken, I get a path like this (and a 2nd one for the thumbnail, but not more):
/data/data/com.foo.bar/files/filename.jpg
Including the picture via
<img src="/data/data/...">
it works fine, so the path seems to be valid.
However, if I try to delete pictures, it doesn't work.
My Code:
window.resolveLocalFileSystemURL(the_path, function (result) {
alert("I'm in");
result.remove(function(){
alert("removed image");
});
});
The I'm in alert doesn't appear, in my console (Android Studio) I get the following error:
java.net.MalformedURLException: No installed handlers for this URL
Do I have to modify the URL, or what's wrong?
I found a solution via trial and error.
prepending
file://
to the path, so that it looks like
file:///data/data/com.foo.bar/files/filename.jpg
worked for me. But I've no idea, if this works in iOS, too.

Android Studio; get image in drawable through url

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));

Android: MediaStore.Images.Media.EXTERNAL_CONTENT_URI ... show pictures in full size?

I guess this question has been asked before, but I can't seem to find a proper answer/solution.
Have a note-taking app, which allows to take pictures. For that I start an intent, that starts up the built-in camera-app. So far so good.
But when I show that image in my app, it's in a much smaller format :(
The funny/weird thing is, that the camera-app did take a full-resolution picture! But for some reason I can't get the full version to show in my app???
So, when I use the standard Android Gallery app, and go to that picture, it is very obvious that it's full size (I can zoom in and see details I really can't see when I zoom in, in my own app). Also, the dimensions are really those of the original picture, taken with the 5MP camera.
In my app, they are very small. My phone has Android 2.2, but the same happens on my emulator (Android 2.1).
How should I retrieve the pictures in my app??? Tried a couple of ways, but none works :( Don't need a complete example (allthough that's very welcome), just a few clues are enough to search for myself.
Tx in advance!!
Greetingz,
Koen<
Very weird, I found the solution/answer by looking at the _ID-values that were being inserted in my own database. First I noticed that when I selected an existing image (via the build-in Android Gallery), I did get the full size image.
When I first took a picture, I got a scaled image. So where was the difference. Apparantly at the location where the _ID of the picture got stored in my database. In my case, and probably most cases, this happens in the onActivityResult procedure.
First take a look at what I initially had:
if(requestCode == REQUEST_CAMERA && resultCode == RESULT_OK){
String timestamp = Long.toString(System.currentTimeMillis());
// get the picture
mPicture = (Bitmap)result.getExtras().get("data");
//save image to gallery
String pictureUrl = MediaStore.Images.Media.insertImage(getContentResolver(), mPicture, getResources().getString(R.string.app_name_short), timestamp);
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(Uri.parse(pictureUrl).getLastPathSegment()));
The "insertPictureAttachment"-method does the actual inserting into the database.
Looking backwards, this was a bit weird anyway ... make a picture, so I could make an URI of it, and then get the last path segment (which is the _ID), so I could insert that into my database.
Eventually, it turns out that I can replace the above code with just one line:
insertPictureAttachment(mRowId.intValue(), Integer.parseInt(result.getData().getLastPathSegment()));
Much shorter, and actually makes more sense ... rather than getting the info from result.getExtras().get("data"), I get my info from result.getData(), which gives the _ID of the original, full-size image.
I will do some further research on this though, cause it's not clear to me yet why I actually don't have to call MediaStore.Images.Media.insertImage(...) ... maybe I will have to if I want specific features (like a custom file location or something like that).
Greetingz,
Koen<

phonegap doesn't work

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.

Categories

Resources