意图选择器无法找到要处理的应用程序

时间:2015-09-11 15:12:38

标签: android android-intent uri actionview

这是一个非常基本的问题,但我无法弄清楚。我想制作一个自定义意图选择器。当我运行选择器意图时它会崩溃。当我使用ACTION_VIEW运行意图时,它可以完美地运行。它向我展示了模拟器中选择器的系统构建,当我选择浏览器时,它会打开Uri。

的ErrorMessage:

09-11 11:06:30.057    6070-6070/? D/dalvikvm﹕ Not late-enabling CheckJNI   (already on)
09-11 11:06:30.088    6070-6070/course.labs.intentslab D/dalvikvm﹕       GC_FOR_ALLOC freed 164K, 18% free 2795K/3404K, paused 1ms, total 3ms
09-11 11:06:30.138    6070-6070/course.labs.intentslab D/libEGL﹕ loaded    /system/lib/egl/libEGL_emulation.so
09-11 11:06:30.138    6070-6070/course.labs.intentslab D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_emulation.so
09-11 11:06:30.138    6070-6070/course.labs.intentslab D/libEGL﹕ loaded /system/lib/egl/libGLESv2_emulation.so
09-11 11:06:30.138    6070-6070/course.labs.intentslab D/﹕ HostConnection::get() New Host Connection established 0xb9579ef0, tid 6070
09-11 11:06:30.189    6070-6070/course.labs.intentslab W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-11 11:06:30.189    6070-6070/course.labs.intentslab D/OpenGLRenderer﹕ Enabling debug mode 0
09-11 11:06:31.807    6070-6070/course.labs.intentslab I/Lab-Intents﹕ Entered startImplicitActivation()
09-11 11:06:31.807    6070-6070/course.labs.intentslab I/Lab-Intents﹕ Chooser Intent Action:android.intent.action.CHOOSER
09-11 11:06:31.988    6070-6070/course.labs.intentslab W/ChooseActivity﹕ Target is not an intent: null
09-11 11:06:31.988    6070-6070/course.labs.intentslab D/AndroidRuntime﹕ Shutting  down VM
09-11 11:06:31.988    6070-6070/course.labs.intentslab W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb181c678)
09-11 11:06:31.988    6070-6070/course.labs.intentslab E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.app.SuperNotCalledException: Activity {android/com.android.internal.app.ChooserActivity} did not call through to super.onCreate()
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2177)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
        at android.app.ActivityThread.access$600(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)

Java功能:

private void startImplicitActivation() {

    Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));

    Intent chooserIntent = new Intent();
    chooserIntent.createChooser(baseIntent, "Open Browser...");

    startActivity(chooserIntent);
}

ChooserActivity.java(这是我在SDK Path中找到的ChooserActivity.java。我无法弄清楚我是如何在Android Studio中找到该文件的。

package com.android.internal.app;

import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;

public class ChooserActivity extends ResolverActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
        Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
        if (!(targetParcelable instanceof Intent)) {
            Log.w("ChooseActivity", "Target is not an intent: " +   targetParcelable);
            finish();
            return;
        }
        Intent target = (Intent)targetParcelable;
        CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
        if (title == null) {
            title = getResources().getText(com.android.internal.R.string.chooseActivity);
        }
        Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
        Intent[] initialIntents = null;
        if (pa != null) {
            initialIntents = new Intent[pa.length];
            for (int i=0; i<pa.length; i++) {
                if (!(pa[i] instanceof Intent)) {
                    Log.w("ChooseActivity", "Initial intent #" + i
                            + " not an Intent: " + pa[i]);
                    finish();
                    return;
                }
                initialIntents[i] = (Intent)pa[i];
            }
        }
        super.onCreate(savedInstanceState, target, title, initialIntents, null, false);
    }
}

更新:再次尝试后,它会向我显示一条不同的错误消息。也许这有帮助。

09-11 13:07:00.900  21068-21068/course.labs.intentslab D/﹕  HostConnection::get() New Host Connection established 0xb8064840, tid 21068
09-11 13:07:00.970  21068-21068/course.labs.intentslab W/EGL_emulation﹕ eglSurfaceAttrib not implemented
09-11 13:07:00.970  21068-21068/course.labs.intentslab D/OpenGLRenderer﹕ Enabling debug mode 0
09-11 13:07:03.120  21068-21068/course.labs.intentslab I/Lab-Intents﹕ Entered startImplicitActivation()
09-11 13:07:03.120  21068-21068/course.labs.intentslab I/Lab-Intents﹕ Chooser Intent Action:null
09-11 13:07:03.120  21068-21068/course.labs.intentslab D/AndroidRuntime﹕ Shutting down VM
09-11 13:07:03.120  21068-21068/course.labs.intentslab W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb17b5678)
09-11 13:07:03.120  21068-21068/course.labs.intentslab E/AndroidRuntime﹕ FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent {  }

1 个答案:

答案 0 :(得分:0)

首先,Intent.createChooser(Intent, CharSequence)是一种静态方法。启动意图就像

一样简单
private void startImplicitActivation() {
    Intent baseIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL));
    startActivity(Intent.createChooser(baseIntent, "Open Browser..."));
}

这就是您更新错误消息的原因。您最有可能通过使用new Intent(Intent.ACTION_CHOOSER)创建选择器来获得第一个。