android - Intent 中的地理在 Android 应用程序中不起作用

标签 android google-maps android-intent android-virtual-device geo

我只是想在我的应用程序中加载 map 应用程序,但它总是关闭并显示一条消息,Unfortunately, the app has stopped.

我也搜索了其他 stackoverflow 答案,但不明白为什么每次单击 Show Map 时都会强制关闭它。按钮。

我的代码是:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.himanshu.intents.MainActivity" >

<Button
    android:id="@+id/button3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button2"
    android:layout_below="@+id/button2"
    android:layout_marginTop="14dp"
    android:onClick="onClickSM"
    android:text="Show Map" />

</RelativeLayout>

主 Activity 文件:

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
 }
 public void onClickSM(View v) {
    Intent i = new Intent (android.content.Intent.ACTION_VIEW);
    i.setData(Uri.parse("geo:<28.629404>,<77.086824>?q=<28.629404>,<77.086824>"));
    startActivity(i);
 }
}

LogCat 消息:

08-09 14:31:58.142: D/dalvikvm(2001): Not late-enabling CheckJNI (already on) 08-09 14:31:58.372: D/(2001): HostConnection::get() New Host Connection established 0xb7f424f0, tid 2001 08-09 14:31:58.422: W/EGL_emulation(2001): eglSurfaceAttrib not implemented 08-09 14:31:58.432: D/OpenGLRenderer(2001): Enabling debug mode 0 08-09 14:32:02.632: D/AndroidRuntime(2001): Shutting down VM 08-09 14:32:02.632: W/dalvikvm(2001): threadid=1: thread exiting with uncaught exception (group=0xb2d72b20) 08-09 14:32:02.632: E/AndroidRuntime(2001): FATAL EXCEPTION: main 08-09 14:32:02.632: E/AndroidRuntime(2001): Process: com.himanshu.intents, PID: 2001 08-09 14:32:02.632: E/AndroidRuntime(2001): java.lang.IllegalStateException: Could not execute method of the activity 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$1.onClick(View.java:3823) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View.performClick(View.java:4438) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$PerformClick.run(View.java:18422) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Handler.handleCallback(Handler.java:733) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Handler.dispatchMessage(Handler.java:95) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.os.Looper.loop(Looper.java:136) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.ActivityThread.main(ActivityThread.java:5017) 08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invokeNative(Native Method) 08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invoke(Method.java:515) 08-09 14:32:02.632: E/AndroidRuntime(2001): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 08-09 14:32:02.632: E/AndroidRuntime(2001): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 08-09 14:32:02.632: E/AndroidRuntime(2001): at dalvik.system.NativeStart.main(Native Method) 08-09 14:32:02.632: E/AndroidRuntime(2001): Caused by: java.lang.reflect.InvocationTargetException 08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invokeNative(Native Method) 08-09 14:32:02.632: E/AndroidRuntime(2001): at java.lang.reflect.Method.invoke(Method.java:515) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.view.View$1.onClick(View.java:3818) 08-09 14:32:02.632: E/AndroidRuntime(2001): ... 11 more 08-09 14:32:02.632: E/AndroidRuntime(2001): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=geo:<28.629404>,<77.086824>?q=<28.629404>,<77.086824> } 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivityForResult(Activity.java:3424) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivityForResult(Activity.java:3385) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivity(Activity.java:3627) 08-09 14:32:02.632: E/AndroidRuntime(2001): at android.app.Activity.startActivity(Activity.java:3595) 08-09 14:32:02.632: E/AndroidRuntime(2001): at com.himanshu.intents.MainActivity.onClickSM(MainActivity.java:32) 08-09 14:32:02.632: E/AndroidRuntime(2001): ... 14 more

最佳答案

首先,geo:您尝试解析的 URL 不是 the documented and supported structures 之一, 超出无效 <>在 cygery 的回答中指出。

其次,您的设备或模拟器上可能没有支持 geo: 的 map 应用程序Intent

关于android - Intent 中的地理在 Android 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25221870/

相关文章:

java - 检测 Android 应用升级并设置应用程序类 boolean 值以显示/隐藏 EULA

Android,构建 openssl-fips-2.0

javascript - Google Place API - 请求的资源上不存在 'Access-Control-Allow-Origin' header 。因此不允许访问 Origin 'null'

java - 获得多功能服务的最佳方式?

android - 在新方法中创建 Intent

android - 在某些 Android 版本中,当弹出窗口不可聚焦时,PopupWindow 中的 ListView 不会接收到触摸事件?

java - 改造队列多个RecyclerViews

ios - GMSCoordinateBounds 角值 - Google Maps SDK

javascript - 谷歌地图 Javascript 用多边形制作路径

java - 在 Intent 中传递 ArrayList<int[]>[] 的正确方法是什么?