I have a problem with sending mms in android. I’ve seen many examples but none of them are sending an image from res/drawable which is what I’m trying to do. Please help me spot the problem.
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri uri = Uri.parse("android.resource://com.mypackage/" + R.drawable.myimage);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra("sms_body", "some text");
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/png");
startActivity(sendIntent);
}
Here are my error messages:
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): FATAL EXCEPTION: main
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.mms/com.android.mms.ui.ComposeMessageActivity}: java.lang.NullPointerException
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.os.Looper.loop(Looper.java:123)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at dalvik.system.NativeStart.main(Native Method)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): Caused by: java.lang.NullPointerException
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.UriImage.(UriImage.java:68)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.model.ImageModel.initModelFromUri(ImageModel.java:82)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.model.ImageModel.(ImageModel.java:64)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.data.WorkingMessage.changeMedia(WorkingMessage.java:461)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.data.WorkingMessage.setAttachment(WorkingMessage.java:362)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.ComposeMessageActivity.addImage(ComposeMessageActivity.java:2640)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.ComposeMessageActivity.addAttachment(ComposeMessageActivity.java:2776)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.ComposeMessageActivity.handleSendIntent(ComposeMessageActivity.java:2705)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.ComposeMessageActivity.initialize(ComposeMessageActivity.java:1743)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at com.android.mms.ui.ComposeMessageActivity.onCreate(ComposeMessageActivity.java:1678)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-23 23:09:55.653: ERROR/AndroidRuntime(2205): … 11 more
you cannot expose application resources directly to the outside world.
you can try implementing a content provider. LINK
using this you can send you own custom uri and when the file is searched you can open the file from your resources and supply it.
you have to check the manifest.xml as well for the relative entry of the content provider.