android彩信发送错误

时间:2011-08-23 23:17:00

标签: android android-intent uri drawable mms

我在android中发送mms有问题。我见过很多例子,但没有一个是从res / drawable发送图像,这正是我想要做的。请帮我发现问题。

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);
}

以下是我的错误消息:

08-23 23:09:55.653:ERROR / AndroidRuntime(2205):致命异常:主要 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):java.lang.RuntimeException:无法启动活动ComponentInfo {com.android.mms / com.android.mms.ui.ComposeMessageActivity}:java.lang.NullPointerException 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.os.Handler.dispatchMessage(Handler.java:99) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.os.Looper.loop(Looper.java:123) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在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):引起: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):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 08-23 23:09:55.653:ERROR / AndroidRuntime(2205):... 11更多

1 个答案:

答案 0 :(得分:1)

您不能直接向外界公开应用程序资源。

您可以尝试实施content providerLINK

使用此功能,您可以发送自己的自定义uri,搜索文件时,您可以从资源中打开文件并提供。

您还必须检查manifest.xml以及内容提供商的相对条目。