Android:resolveActivity(getPackageManager()) 在调用 Maps 时返回 null

问题描述 投票:0回答:3

我正在尝试制作一个在当前设备上调用地图的天气应用程序,但似乎intent.resolveActivity(getPackageManager())返回null。有什么建议吗?

MainActivity.java

    package com.example.urvashirohilla.sunshine.app;


import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

public  class MainActivity extends AppCompatActivity implements ForecastFragment.OnFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.settings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }

        if (id == R.id.Maps_id)
        {
            callmap();
        }

        return super.onOptionsItemSelected(item);
    }
    public void callmap()
    {
        SharedPreferences pref_2 = PreferenceManager.getDefaultSharedPreferences(this);
        String location = pref_2.getString(getString(R.string.key), getString(R.string.pref_default_display_name));
        Uri geoLocation = Uri.parse("geo :0,0?").buildUpon().appendQueryParameter("q",location).build();
        Intent map = new Intent(Intent.ACTION_VIEW);
        map.setData(geoLocation);
        if (map.resolveActivity(getPackageManager()) != null) {
            startActivity(map);
        }
        else
        {
            Log.d("Error calling:",location);
        }
    }



    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}

这是 Logcat:

12-05 17:28:27.193 2307-2445/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: Enabling debug mode 0
12-05 17:28:27.201 2307-2445/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:28:27.201 2307-2445/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xaec35500, error=EGL_SUCCESS
12-05 17:28:38.672 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:28:38.672 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3bc00, error=EGL_SUCCESS
12-05 17:28:40.357 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:28:40.357 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3fcec20, error=EGL_SUCCESS
12-05 17:28:40.465 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d36480 (RippleDrawable) with handle 0xb3f9a050
12-05 17:28:41.460 2632-2632/com.example.urvashirohilla.sunshine.app W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
12-05 17:28:41.543 2632-2649/com.example.urvashirohilla.sunshine.app I/art: Background sticky concurrent mark sweep GC freed 6129(509KB) AllocSpace objects, 1(16KB) LOS objects, 25% free, 1844KB/2MB, paused 9.687ms total 53.250ms
12-05 17:28:41.614 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:28:41.614 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3f1da00, error=EGL_SUCCESS
12-05 17:28:42.754 2632-2632/com.example.urvashirohilla.sunshine.app D/Error calling:: 7500
12-05 17:31:26.094 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:31:26.094 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3b420, error=EGL_SUCCESS
12-05 17:31:27.514 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:31:27.514 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3b420, error=EGL_SUCCESS
12-05 17:31:28.496 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:31:28.499 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3bce0, error=EGL_SUCCESS
12-05 17:32:36.979 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:32:36.979 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3ee7de0, error=EGL_SUCCESS
12-05 17:32:55.660 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:32:55.660 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3b400, error=EGL_SUCCESS
12-05 17:32:56.694 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:32:56.694 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3b400, error=EGL_SUCCESS
12-05 17:32:57.633 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:32:57.633 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d07420, error=EGL_SUCCESS
12-05 17:32:58.841 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:32:58.841 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d48b60, error=EGL_SUCCESS
12-05 17:33:00.934 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d31080 (RippleDrawable) with handle 0xa3e79240
12-05 17:33:03.684 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:33:03.684 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d07280, error=EGL_SUCCESS
12-05 17:33:57.388 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:33:57.388 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3fce180, error=EGL_SUCCESS
12-05 17:33:57.486 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d97280 (ListView) with handle 0xb3e61910
12-05 17:34:13.043 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:13.043 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d88780, error=EGL_SUCCESS
12-05 17:34:13.143 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d36480 (RippleDrawable) with handle 0xb3e61900
12-05 17:34:14.770 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:14.770 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d07ee0, error=EGL_SUCCESS
12-05 17:34:15.587 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=261.77002, y[0]=143.13281, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=506145, downTime=506044, deviceId=0, source=0x1002 }
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=261.77002, y[0]=143.13281, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=506145, downTime=506044, deviceId=0, source=0x1002 }
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_MOVE, id[0]=0, x[0]=261.77002, y[0]=143.13281, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=506145, downTime=506044, deviceId=0, source=0x1002 }
12-05 17:34:15.588 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:15.641 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:15.641 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d07ee0, error=EGL_SUCCESS
12-05 17:34:16.533 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:16.533 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d48b60, error=EGL_SUCCESS
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=195.28857, y[0]=315.4922, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=509107, downTime=508972, deviceId=0, source=0x1002 }
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=195.28857, y[0]=315.4922, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=509107, downTime=508972, deviceId=0, source=0x1002 }
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_MOVE, id[0]=0, x[0]=195.28857, y[0]=315.4922, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=509107, downTime=508972, deviceId=0, source=0x1002 }
12-05 17:34:18.571 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:19.605 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:19.605 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3c3b360, error=EGL_SUCCESS
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=208.29639, y[0]=290.45313, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=511993, downTime=511890, deviceId=0, source=0x1002 }
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_ENTER, id[0]=0, x[0]=208.29639, y[0]=290.45313, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=511993, downTime=511890, deviceId=0, source=0x1002 }
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_HOVER_MOVE, id[0]=0, x[0]=208.29639, y[0]=290.45313, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=511993, downTime=511890, deviceId=0, source=0x1002 }
12-05 17:34:21.430 2632-2632/com.example.urvashirohilla.sunshine.app W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
12-05 17:34:22.572 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:22.572 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3f13180, error=EGL_SUCCESS
12-05 17:34:34.658 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:34.659 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3f133a0, error=EGL_SUCCESS
12-05 17:34:34.754 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d9f080 (ListView) with handle 0xa3e79600
12-05 17:34:35.882 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:34:35.883 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3e01880, error=EGL_SUCCESS
12-05 17:34:36.018 2632-2658/com.example.urvashirohilla.sunshine.app D/OpenGLRenderer: endAllStagingAnimators on 0xa3d9aa80 (RippleDrawable) with handle 0xa3e790a0
12-05 17:36:21.809 2632-2658/com.example.urvashirohilla.sunshine.app W/EGL_emulation: eglSurfaceAttrib not implemented
12-05 17:36:21.810 2632-2658/com.example.urvashirohilla.sunshine.app W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa3d88ca0, error=EGL_SUCCESS
12-05 17:36:34.028 2632-2632/com.example.urvashirohilla.sunshine.app D/Error calling:: 110055
android android-studio
3个回答
1
投票

使用 https://stackoverflow.com/a/22704594/2482947 创建意图。

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));

0
投票

好吧,看来我只是搞乱了格式。 该代码有一个“额外的空格”。

上一篇: 地理:0,0?q=

更正: 地理:0,0?q=

因此系统无法解析意图。现在就像魅力一样!!


0
投票

将此添加到清单中

<queries>
        <package android:name="com.google.android.apps.maps" />
    </queries>
© www.soinside.com 2019 - 2024. All rights reserved.