Hi, The code for starting the intent is correct. But I am not sure about the data, i.e the Uri that you have passed. Normally, other application cannot access your application specific files, unless you expose them through a content provider. One option would be to save your file to the sdcard, and pass the uri of that location.
Uri uri = Uri.fromFile(new File("/sdcard/filename"); This should work. Instead of specifying the exact file type, you can set the type as "image/*", and the picture viewer should take care of the rest. Regards, Dexter. On Sep 1, 3:36 pm, Umesh <javaumesh-andr...@yahoo.co.in> wrote: > Hi all, > > I have been working on building an Uri to an image present at the APK, > in the following way. > Uri path = Uri.parse("android.resource://" + <package> + "/" + "ImageId"); > but when I pass this Uri to the Intent, I'm always getting > ActivityNotFoundException. > can someone help me in figuring out what is going wrong. I'm really > struggling hard to make this work, but always ending with fruitless efforts. > But interestingly same code works if i provide Uri of an image present at the > SDCARD. But for the following , app always crashes with the runtime exception. > > Thanks in advance. > > Code: > > public void displayImage(){ > > String uriStr = "android.resource://"+ "com.example.myapp"+ "/" + > R.drawable.photo_h01; > Uri uri = Uri.parse(uriStr); > Intent intent = new Intent(Intent.ACTION_VIEW); > intent.setDataAndType(uri, "image/png"); //intent.setData(uri); > mContext.startActivity(intent); > > } > > and the exception is: > > Stack trace: > I/ActivityManager( 917): Starting activity: Intent { > action=android.intent.action.VIEW > data=android.resource://com.onskreen.coverflow.homes.media/2130837509 > type=image/png } > D/AndroidRuntime( 1152): Shutting down VM > W/dalvikvm( 1152): threadid=3: thread exiting with uncaughtexception > (group=0x4000fe70) > E/AndroidRuntime( 1152): Uncaught handler: thread main exiting due to > uncaught exception > E/AndroidRuntime( 1152): android.content.ActivityNotFoundException: No > Activity found to handle Intent { action=android. > intent.action.VIEW data=android.resource://com.example.myapp/2130837509 > type=image/png } > E/AndroidRuntime( 1152): at > android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1484) > E/AndroidRuntime( 1152): at > android.app.Instrumentation.execStartActivity(Instrumentation.java:1454) > E/AndroidRuntime( 1152): at > android.app.Activity.startActivityForResult(Activity.java:2656) > E/AndroidRuntime( 1152): at > android.app.Activity.startActivity(Activity.java:2700) > E/AndroidRuntime( 1152): at > com.example.myapp.CoverFlowView.launchAndroidApplication(CoverFlowView.java:434) > E/AndroidRuntime( 1152): at > com.example.myapp.MediaHome$4.onSelectionChanged(MediaHome.java:108) > E/AndroidRuntime( 1152): at > com.example.myapp.CoverFlowView.onSingleTapUp(CoverFlowView.java:184) > E/AndroidRuntime( 1152): at > android.view.GestureDetector.onTouchEvent(GestureDetector.java:503) > E/AndroidRuntime( 1152): at > com.example.myapp.CoverFlowView$1.onTouch(CoverFlowView.java:60) > E/AndroidRuntime( 1152): at > android.view.View.dispatchTouchEvent(View.java:3364) > E/AndroidRuntime( 1152): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 1152): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 1152): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 1152): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 1152): at > com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1707) > E/AndroidRuntime( 1152): at > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1197) > E/AndroidRuntime( 1152): at > android.app.Activity.dispatchTouchEvent(Activity.java:1993) > E/AndroidRuntime( 1152): at > com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1691) > E/AndroidRuntime( 1152): at > android.view.ViewRoot.handleMessage(ViewRoot.java:1525) > E/AndroidRuntime( 1152): at > android.os.Handler.dispatchMessage(Handler.java:99) > E/AndroidRuntime( 1152): at android.os.Looper.loop(Looper.java:123) > E/AndroidRuntime( 1152): at > android.app.ActivityThread.main(ActivityThread.java:3948) > E/AndroidRuntime( 1152): at > java.lang.reflect.Method.invokeNative(Native Method) > E/AndroidRuntime( 1152): at > java.lang.reflect.Method.invoke(Method.java:521) > E/AndroidRuntime( 1152): at > com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) > E/AndroidRuntime( 1152): at > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) > E/AndroidRuntime( 1152): at dalvik.system.NativeStart.main(Native > Method) > I/Process ( 917): Sending signal. PID: 1152 SIG: 3 > I/dalvikvm( 1152): threadid=7: reacting to signal 3 > I/dalvikvm( 1152): Wrote stack trace to '/data/anr/traces.txt' > > See the Web's breaking stories, chosen by people like you. Check > out Yahoo! Buzz.http://in.buzz.yahoo.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---