找不到处理 Intent { act=android.settings.}

我正在创建一个检查当前位置的代码,但是,当我检查当前位置时,它崩溃了。我查看了堆栈跟踪并看到了这一点。我阅读了其他论坛,但我不熟悉他们的解决方案。我也是Java的初学者。我使用 Amazon Fire 平板电脑下载此应用程序。当我尝试在模拟器上测试它时,应用程序没有崩溃。


 android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.LOCALE_SETTINGS }

        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1797)

        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)

        at android.app.Activity.startActivityForResult(Activity.java:3761)

        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)

        at android.app.Activity.startActivityForResult(Activity.java:3722)

        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)

        at android.app.Activity.startActivity(Activity.java:4032)

        at android.app.Activity.startActivity(Activity.java:4000)

        at com.example.calculatorandlocationfinderfinal.MainActivity$7.onClick(MainActivity.java:181)

        at androidx.appcompat.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)

        at android.os.Handler.dispatchMessage(Handler.java:102)

        at android.os.Looper.loop(Looper.java:135)

        at android.app.ActivityThread.main(ActivityThread.java:5491)

        at java.lang.reflect.Method.invoke(Native Method)

        at java.lang.reflect.Method.invoke(Method.java:372)

        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)

        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

下面是发生这种情况的代码。



慕运维8079593
浏览 211回答 3
3回答

尚方宝剑之说

始终使用此方法来启动除应用程序之外的意图 -Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);if(intent.resolveActivity(context.getPackageManager()) != null){    startActivity(intent);}else{    //handle activity not found}这样你就不会得到 ActivityNotFoundException。您还可以使用 try catch 作为 -try {       startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));    } catch (e: ActivityNotFoundException) {       //handle activity not found    }

哆啦的时光机

Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //This line solve my issuestartActivity(i);

九州编程

我想您想导航到 GPS 设置屏幕。尝试这个。startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));手机/设备可能完全缺少区域设置屏幕,从而导致崩溃。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java