发送短信时没有活动发现异常

时间:2013-12-14 17:10:41

标签: android

我正在开发Android应用程序,我需要使用intent发送带有图像的短信,但我得到异常ActivityNotFoundException。我正在尝试android 4.2

的AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shareviamms"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Java代码:

Intent sendIntent = new Intent(Intent.ACTION_SEND);     sendIntent.setClassName("com.android.mms","com.android.mms.ui.ComposeMessageActivity");
        sendIntent.putExtra("sms_body", "some text");
        sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/32X32.png"));
        sendIntent.setType("image/png");
        startActivity(sendIntent);

栈跟踪

12-14 23:07:55.332: E/AndroidRuntime(11322): FATAL EXCEPTION: main
12-14 23:07:55.332: E/AndroidRuntime(11322): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.shareviamms/com.example.shareviamms.MainActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.mms/com.android.mms.ui.ComposeMessageActivity}; have you declared this activity in your AndroidManifest.xml?
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2187)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread.access$600(ActivityThread.java:146)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1239)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.os.Looper.loop(Looper.java:137)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread.main(ActivityThread.java:5085)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at java.lang.reflect.Method.invokeNative(Native Method)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at java.lang.reflect.Method.invoke(Method.java:511)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at dalvik.system.NativeStart.main(Native Method)
12-14 23:07:55.332: E/AndroidRuntime(11322): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.mms/com.android.mms.ui.ComposeMessageActivity}; have you declared this activity in your AndroidManifest.xml?
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Activity.startActivityForResult(Activity.java:3370)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Activity.startActivityForResult(Activity.java:3331)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Activity.startActivity(Activity.java:3566)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Activity.startActivity(Activity.java:3534)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at com.example.shareviamms.MainActivity.onCreate(MainActivity.java:20)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Activity.performCreate(Activity.java:5104)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
12-14 23:07:55.332: E/AndroidRuntime(11322):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
12-14 23:07:55.332: E/AndroidRuntime(11322):  ... 11 more

1 个答案:

答案 0 :(得分:0)

关于评论,我正在更新答案。 有三种方法可以处理AcitivityNotFOund:

1)继续尝试该方法,但捕获ActivityNotFoundException。

2)如果您收到ActivityNotFoundException,请尝试启动用户可能已安装的其他应用程序(VZMessages,Zlango Messaging,Handcent,ChompSMS等)。

3)如果所有这些都失败了,请让您的用户知道您要发送彩信,然后启动意图而不指定课程。这样,用户可以选择实际发送彩信的应用