2017-04-19 162 views
-2

因此,我正在使用Android Studio制作Android移动设备应用程序。该应用程序涉及使用Google Maps API,但每当Google地图活动不是我的启动程序活动时,我遇到问题。下面是manifest.xml的代码,它的工作原理:Android Studio谷歌地图API

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.drexelnavigationapplication_20"> 

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="@string/google_maps_key" /> 

     <activity 
      android:name=".dna_map" 
      android:label="@string/title_activity_dna_map"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".dna_registration"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 


      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

这里是明显的代码,我尝试做不同的活动与一键切换到地图的活动发射器,并且在按压应用程序崩溃按钮。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.drexelnavigationapplication_20"> 

    <!-- 
     The ACCESS_COARSE/FINE_LOCATION permissions are not required to use 
     Google Maps Android API v2, but you must specify either coarse or fine 
     location permissions for the 'MyLocation' functionality. 
    --> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:roundIcon="@mipmap/ic_launcher_round" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 

     <!-- 
      The API key for Google Maps-based APIs is defined as a string resource. 
      (See the file "res/values/google_maps_api.xml"). 
      Note that the API key is linked to the encryption key used to sign the APK. 
      You need a different API key for each encryption key, including the release key that is used to 
      sign the APK for publishing. 
      You can define the keys for the debug and release targets in src/debug/ and src/release/. 
     --> 
     <meta-data 
      android:name="com.google.android.geo.API_KEY" 
      android:value="@string/google_maps_key" /> 

     <activity 
      android:name=".dna_map" 
      android:label="@string/title_activity_dna_map"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

      </intent-filter> 
     </activity> 
     <activity android:name=".dna_registration"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application> 

</manifest> 

下面是完成屏幕开关上的按钮(使用的onClick属性)的意向函数的代码:

package com.example.drexelnavigationapplication_20; 

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 

public class dna_registration extends AppCompatActivity { 

//INTENT FUNCTION IN QUESTION, 
    private void switchScreens_Maps(View view){ 
     Intent i = new Intent(view.getContext(), dna_map.class); 
     startActivityForResult(i, 0); 
    } 

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

我在做什么错了,导致在应用程序崩溃切换屏幕?

+1

您的Android Studio相关问题如何? –

+0

请添加异常堆栈 – Kartoch

+0

@Prakhar - 您可以抓住logcat并粘贴您的显示错误的问题吗? –

回答

0

您的API密钥可能在字符串值中存在错误