I use the following to query the image of a contact:
Uri phUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI,String.valueOf(contactId));
As a result I get something like:
content://com.android.contacts/contacts/3699
Then I try to set it to an image view:
Uri IMAGE_URI = Uri.parse(image);
IMAGE_URI= Uri.withAppendedPath(IMAGE_URI, Contacts.Photo.CONTENT_DIRECTORY);
try{
((ImageView) view.getTag(R.id.imageView1)).setImageURI(IMAGE_URI);
}catch (Exception e){
System.out.println(e);
}
It raises an exception of file not found, however the System.out.println() in the catch block prints a bad bitmap uri. The above code was working properly some days ago, wonder whats going wrong.
The Log cat: (Check the first and the last line)
01-14 09:25:19.271: W/ImageView(3674): Unable to open content: content://com.android.contacts/contacts/3699/photo
01-14 09:25:19.271: W/ImageView(3674): java.io.FileNotFoundException: content://com.android.contacts/contacts/3699/photo
01-14 09:25:19.271: W/ImageView(3674): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:149)
01-14 09:25:19.271: W/ImageView(3674): at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:617)
01-14 09:25:19.271: W/ImageView(3674): at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:739)
01-14 09:25:19.271: W/ImageView(3674): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:636)
01-14 09:25:19.271: W/ImageView(3674): at android.content.ContentResolver.openInputStream(ContentResolver.java:471)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ImageView.resolveUri(ImageView.java:631)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ImageView.setImageURI(ImageView.java:379)
01-14 09:25:19.271: W/ImageView(3674): at com.exa.birthdayrem.FragmentTab3$CurAdapter.bindView(FragmentTab3.java:157)
01-14 09:25:19.271: W/ImageView(3674): at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.AbsListView.obtainView(AbsListView.java:2319)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ListView.makeAndAddView(ListView.java:1793)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ListView.fillDown(ListView.java:678)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ListView.fillSpecific(ListView.java:1336)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.ListView.layoutChildren(ListView.java:1628)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.AbsListView.onLayout(AbsListView.java:2170)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-14 09:25:19.271: W/ImageView(3674): at android.view.View.layout(View.java:13846)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewGroup.layout(ViewGroup.java:4466)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2168)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1926)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1140)
01-14 09:25:19.271: W/ImageView(3674): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4726)
01-14 09:25:19.271: W/ImageView(3674): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:747)
01-14 09:25:19.271: W/ImageView(3674): at android.view.Choreographer.doCallbacks(Choreographer.java:567)
01-14 09:25:19.271: W/ImageView(3674): at android.view.Choreographer.doFrame(Choreographer.java:536)
01-14 09:25:19.271: W/ImageView(3674): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:733)
01-14 09:25:19.271: W/ImageView(3674): at android.os.Handler.handleCallback(Handler.java:615)
01-14 09:25:19.271: W/ImageView(3674): at android.os.Handler.dispatchMessage(Handler.java:92)
01-14 09:25:19.271: W/ImageView(3674): at android.os.Looper.loop(Looper.java:153)
01-14 09:25:19.271: W/ImageView(3674): at android.app.ActivityThread.main(ActivityThread.java:5000)
01-14 09:25:19.271: W/ImageView(3674): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 09:25:19.271: W/ImageView(3674): at java.lang.reflect.Method.invoke(Method.java:511)
01-14 09:25:19.271: W/ImageView(3674): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
01-14 09:25:19.271: W/ImageView(3674): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
01-14 09:25:19.271: W/ImageView(3674): at dalvik.system.NativeStart.main(Native Method)
01-14 09:25:19.271: I/System.out(3674): resolveUri failed on bad bitmap uri: content://com.android.contacts/contacts/3699/photo