2017-04-19 179 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密鑰可能在字符串值中存在錯誤