Android中的自定义隐式意图不起作用

时间:2012-12-12 14:34:54

标签: android android-intent implicit

我正在测试隐含的意图。我有两个小测试应用程序: 第一个AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sudipta.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name="com.sudipta.example.Intent1Activity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter >
                <action  android:name="com.sudipta.personal.TEST" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

第二个AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sudipta.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="14" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".Intent2Activity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter >
                <action  android:name="com.sudipta.personal.TEST" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/plain"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

现在我调用以下代码:

btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                //Call the Implicit Intent
                Intent intent = new Intent();
                intent.setAction("com.sudipta.personal.TEST");
                startActivity(intent);                      
            }
        });

以下是我得到的错误代码:

12-12 15:20:42.963: E/AndroidRuntime(824): FATAL EXCEPTION: main
12-12 15:20:42.963: E/AndroidRuntime(824): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.sudipta.personal.TEST }
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.app.Activity.startActivityForResult(Activity.java:3190)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.app.Activity.startActivity(Activity.java:3297)
12-12 15:20:42.963: E/AndroidRuntime(824):  at com.sudipta.example.ImplicitIntentActivity$1.onClick(ImplicitIntentActivity.java:28)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.view.View.performClick(View.java:3460)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.view.View$PerformClick.run(View.java:13955)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.os.Handler.handleCallback(Handler.java:605)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.os.Looper.loop(Looper.java:137)
12-12 15:20:42.963: E/AndroidRuntime(824):  at android.app.ActivityThread.main(ActivityThread.java:4340)
12-12 15:20:42.963: E/AndroidRuntime(824):  at java.lang.reflect.Method.invokeNative(Native Method)
12-12 15:20:42.963: E/AndroidRuntime(824):  at java.lang.reflect.Method.invoke(Method.java:511)
12-12 15:20:42.963: E/AndroidRuntime(824):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
12-12 15:20:42.963: E/AndroidRuntime(824):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
12-12 15:20:42.963: E/AndroidRuntime(824):  at dalvik.system.NativeStart.main(Native Method)

请您告诉我这里的问题是什么?感谢。

Sudipta。

1 个答案:

答案 0 :(得分:0)

尝试从您尝试启动的活动中删除android:label。也许它无法访问app_name字符串