My application attempts to find the orientation of the device by using:
int orientation = getResources().getConfiguration.orientation;
This appears to work perfectly on my Samsung Galaxy S2 but when testing it on a HTC Desire HD and then trying to reference my integer in a Toast to check its finding the right orientation, it throws a Resources$NotFoundException.
Am I correct in thinking that this method of finding the phones orientation doesn’t always work, if so why does it not just throw a NullPointerException when I attempt to reference the integer?
My application captures a photo, I therefore need to find the phones orientation in order to set the dimensions for the SurfaceView and rotate the image as required. Is there any other way of finding the phones orientation?
Thanks in advance for any replies.
When you call
Toast.makeText(), note that there are two methods:makeText(Context context, int resId, int duration)andmakeText(Context context, CharSequence text, int duration). When you use an integer, the first method is called, and Android tries to find a resource associated with the integer, which is not what you want.The simplest thing you can do instead is to convert your integer to string:
This way Android won’t search for any resources and will show you the needed text.