0

當我嘗試在運行時爲特定的android風格獲取gcm_defaultSenderId時,它不提供正確的值。來自google-services.json的值返回錯誤

例如:我得到的味道TST和谷歌,services.json看起來像這樣

{ 
    "project_info": { 
    "project_number": "12345678910", 12345678910 
    "project_id": "api-project-12345678910" 
    }, 
    "client": [ 
    { 
     "client_info": { 
     "mobilesdk_app_id": "1:12345678910:android:xxxxxxxxxxxxx", 
     "android_client_info": { 
      "package_name": "do.something.app" 
     } 
     }, 
     "oauth_client": [], 
     "api_key": [ 
     { 
      "current_key": "XXXxxxx-XXXXxxxXXXXXxxxxXXXx" 
     } 
     ], 
     "services": { 
     "analytics_service": { 
      "status": 1 
     }, 
     "appinvite_service": { 
      "status": 1, 
      "other_platform_oauth_client": [] 
     }, 
     "ads_service": { 
      "status": 1 
     } 
     } 
    } 
    ], 
    "configuration_version": "1" 
} 

的JSON文件被放置在尖沙咀/谷歌services.json。當我嘗試在運行時使用R.string.gcm_defaultSenderId訪問gcm_defaultSenderId時,返回值爲:9876543。我期望返回值是構建到gcm_defaultSenderId時所設置的project_number,如其寫入:https://developers.google.com/android/guides/google-services-plugin。有沒有人知道爲什麼這個值與google-service.json中的值不一樣?

+0

您的構建變體的名稱和目錄名稱應完全匹配 –

+0

它們完全相同 – elpatricko

+0

http://imgur.com/AsjllwM它們看起來像這樣嗎? –

回答

0

我修好了。我試圖讓這樣的gcm_defaultSenderId:(?)

R.string.gcm_defaultSenderId 

值有像0X23923912一個十六進制值,這似乎對我來說是一個指針,它被設置在構建時正確的值。現在看來,像Java是此值轉換成int和返回我通過使用當前上下文解決了這個數9876543.(?):

context.getResources().getString(R.string.gcm_defaultSenderId 

現在返回正確的SenderId。