Android 没有找到处理意图的活动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11073832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:54:26  来源:igfitidea点击:

No Activity found to handle Intent

androidandroid-intent

提问by clayton33

i am attempting to launch an intent to open a link to the android market.

我试图启动一个意图打开一个指向 android 市场的链接。

android manifest portion looks like this:

android 清单部分如下所示:

<activity android:name="com.surreall.sixdice.Start" android:label="Six Dice" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />                               
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />  
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

launching the intent looks like:

启动意图看起来像:

public void onClick(View v) {
    String PublisherID = "pub:surreallgames";
    Uri marketUri = Uri.parse("market://search?q="+PublisherID);
    Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);                    
    startActivity(marketIntent);
}

logcat output:

logcat 输出:

06-17 17:38:47.393: E/AndroidRuntime(476): FATAL EXCEPTION: main
06-17 17:38:47.393: E/AndroidRuntime(476): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=market://search?q=pub:surreallgames }
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.app.Activity.startActivityForResult(Activity.java:2827)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.app.Activity.startActivity(Activity.java:2933)
06-17 17:38:47.393: E/AndroidRuntime(476):  at com.surreall.sixdice.Start.onClick(Start.java:265)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.view.View.performClick(View.java:2485)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.view.View$PerformClick.run(View.java:9080)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.os.Handler.handleCallback(Handler.java:587)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.os.Looper.loop(Looper.java:123)
06-17 17:38:47.393: E/AndroidRuntime(476):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-17 17:38:47.393: E/AndroidRuntime(476):  at java.lang.reflect.Method.invokeNative(Native Method)
06-17 17:38:47.393: E/AndroidRuntime(476):  at java.lang.reflect.Method.invoke(Method.java:507)
06-17 17:38:47.393: E/AndroidRuntime(476):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-17 17:38:47.393: E/AndroidRuntime(476):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-17 17:38:47.393: E/AndroidRuntime(476):  at dalvik.system.NativeStart.main(Native Method)

回答by CommonsWare

You are running this code on an Android environment that lacks the Google Play Store, such as an emulator, Kindle Fire, etc.

您在缺少 Google Play 商店的 Android 环境(例如模拟器、Kindle Fire 等)上运行此代码。

If you are encountering this on an emulator, test this code path on a device that has the Play Store.

如果您在模拟器上遇到此问题,请在具有 Play 商店的设备上测试此代码路径。

If you are encountering this on some piece of hardware that lacks the Play Store, or if you are planning on distributing your app to devices that lack the Play Store, either handle the exception or use PackageManagerand resolveActivity()to determine if your Intentwill succeed before calling startActivity().

如果你是在一些硬件的缺乏Play商店,或者如果您对您的应用分发给缺乏Play商店设备的规划,无论是处理异常或使用遇到此PackageManagerresolveActivity()以确定您Intent将之前调用成功startActivity()

if(intent.resolveActivity(getPackageManager()) != null)
    startActivityForResult(intent, 0);
else
    ...

回答by Ole

You can use Intent.createChooser() method to safely launch the Intent. If no application exists that can handle your intent, a dialog will be displayed telling the user just that. If however Google Play Store is installed, the user can that choose to "open" the intent in Play Store.

您可以使用 Intent.createChooser() 方法安全地启动 Intent。如果不存在可以处理您的意图的应用程序,则会显示一个对话框告诉用户。但是,如果安装了 Google Play 商店,则用户可以选择在 Play 商店中“打开”意图。

startActivity(Intent.createChooser(marketIntent, "dialogTitle"));

回答by localhost

Better solution would be to try to open uri in Google Play app, but if there is no such app (no Activity to handle this intent) - you can just try to open uri in browser like in this example:

更好的解决方案是尝试在 Google Play 应用程序中打开 uri,但如果没有这样的应用程序(没有 Activity 来处理此意图) - 您可以尝试在浏览器中打开 uri,如下例所示:

public static void rateApp(Context context) {
    try {
        context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())));
    } catch (android.content.ActivityNotFoundException anfe) {
        viewInBrowser(context, "https://play.google.com/store/apps/details?id=" + context.getPackageName());
    }
}

public static void viewInBrowser(Context context, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    if (null != intent.resolveActivity(context.getPackageManager())) {
        context.startActivity(intent);
    }
}

回答by Naren

Try adding

尝试添加

<category android:name="android.intent.category.DEFAULT" />

to the calling Activity.

到调用活动。

回答by Mucahid Uslu

private void OpenStoreIntent(){
        String url="";
        Intent storeintent=null;
        try {
            url = "market://details?id=com.myapp.packagename";
            storeintent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            storeintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            context.startActivity(storeintent);
        } catch ( final Exception e ) {
            url = "https://play.google.com/store/apps/details?id=com.myapp.packagename";
            storeintent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            storeintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            context.startActivity(storeintent);
        }

    }

回答by Aleksandar

I got the same error because I wrote:

我遇到了同样的错误,因为我写道:

Linking.openURL('www.somewebsite.com');

Changing the URL to http://somewebsite.com(or https://somewebsite.com, depending on the website You are targeting) fixed the problem :)

将 URL 更改为http://somewebsite.com(或https://somewebsite.com,取决于您定位的网站)解决了问题:)