Android Google Maps is a mistake in old versions of SDK



  • I'm working with Google Maps.

    There are two devices one on SDK 23, one on SDK 18.

    Order:

    Manifest:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="ru.suite.name.project">
    
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
    &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
    
    &lt;uses-permission android:name="ru.suite.name.project.permission.MAPS_RECEIVE"  android:protectionLevel="signature"/&gt;
    
    &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /&gt;
    
    &lt;!-- Required OpenGL ES 2.0. for Maps V2 --&gt;
    &lt;uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" /&gt;
    
    
    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"&gt;
    
    
        &lt;meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" /&gt;
    
        &lt;!--&lt;meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="@string/google_maps_key" /&gt;--&gt;
    
        &lt;meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" /&gt;
    

    ......

    Note:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    &lt;FrameLayout
        android:id="@+id/map_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"&gt;
    
        &lt;fragment
            android:name="com.google.android.gms.maps.SupportMapFragment"
            xmlns:map="http://schemas.android.com/apk/res-auto"
            android:id="@+id/map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" /&gt;
    
        &lt;ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/searchMy"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="16dp"
            android:layout_marginRight="16dp"
            android:src="@drawable/ic_track_changes_100dp"
            android:background="@drawable/button_circle_selector"
            android:padding="10dp"
            android:onClick="onClickSearchMyLocation" /&gt;
    &lt;/FrameLayout&gt;
    

    </LinearLayout>

    Initialization of the map. I put the map in the fragment.

    public class fragment_new_order_map extends Fragment {

    GoogleMap googleMap;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
    
        View v = inflater.inflate(R.layout.fragment_new_order_map, container, false);
        return v;
    }
    

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setUpMapIfNeeded();
    }

    private void setUpMapIfNeeded() {
        if (googleMap == null) {
            googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
            // Check if we were successful in obtaining the map.
            if (googleMap != null) {
    
    
            }
        }
    }
    

    }

    What's the problem:

    When I start a program on SDK 23, it's okay!
    Not much, it's, even if I change in the manifest:

    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />

    <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="@string/google_maps_key" />

    That's how it works!

    Problem with SDK 18.

    When an attempt is made to initiate the map, it is such a mistake:

    android.view.InflateException: Binary XML file line #17: Error
    inflating class fragment
    at
    android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at
    ru.suite.name.project.fragments.fragment_new_order_map.onCreateView(fragment_new_order_map.java:99)
    at
    android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
    at
    android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
    at
    android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
    at
    android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
    at
    android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
    at
    android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:176)
    at android.app.ActivityThread.main(ActivityThread.java:5419)
    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:1046)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.RuntimeException: API key not found. Check that
    is in the element of
    AndroidManifest.xml

    UPDAt the same time, a standard project in Android Studio works for all devices.
    The only difference between the projects is that I use maps in fragments, and in FragmentActivity.

    UPD2I think the problem is

    googleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map))

    He can't find R.id.map and return NULL for any reason. Maybe the problem is I'm talking through gettingChildFragmentManager, and R.id.map is on a piece that has just been created! But then why does this logic work for SDK 23? ! ?



  • All right! It's about my neglect.

    It's just that the key was for API 21. And I didn't notice that. :




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2