Exception when invoking MMS's Attach Image activity

957 Views Asked by At

I try to invoke MMS's Attach Image Activity, this is my code:

          Intent intent2 = new Intent("com.android.mms.action.ATTACH_IMAGE");

          intent2.setType("image/*");
          intent2.putExtra(Intent.EXTRA_STREAM, mUri);

          try {
              startActivity(intent);

          } catch (ActivityNotFoundException e) {

             e.printStackTrace(System.err);
          }

But I get this exception:

m.android.mms/com.android.mms.AttachImage}: java.lang.IllegalAccessException: access to class not allowed
E/AndroidRuntime(  673):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2219)
E/AndroidRuntime(  673):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2332)
E/AndroidRuntime(  673):        at android.app.ActivityThread.access$1800(ActivityThread.java:110)
E/AndroidRuntime(  673):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1717)
E/AndroidRuntime(  673):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  673):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  673):        at android.app.ActivityThread.main(ActivityThread.java:4021)
E/AndroidRuntime(  673):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  673):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  673):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime(  673):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
E/AndroidRuntime(  673):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  673): Caused by: java.lang.IllegalAccessException: access to class not allowed
E/AndroidRuntime(  673):        at java.lang.Class.newInstanceImpl(Native Method)
E/AndroidRuntime(  673):        at java.lang.Class.newInstance(Class.java:1472)
E/AndroidRuntime(  673):        at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
E/AndroidRuntime(  673):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)

Can you please tell me why? Thank you.

1

There are 1 best solutions below

0
On

This is probably more what you're trying to accomplish:

startActivity(
    new Intent(Intent.ACTION_SEND)
        .setType("image/*")
        .putExtra("sms_body", "hello there")
        .putExtra(Intent.EXTRA_STREAM, Uri.parse("content://media/external/images/media/1")
    )
);

As long as you've snapped at least one photo with you camera, you should be able to send that photo using this code. Note that this code won't work with the emulator.