Android Question Restricting Google API Keys to Specific App

mangojack

Expert
Licensed User
Longtime User
I have read a few threads covering this , but none seem to show any solutions.

I am attempting to Restrict a Google API key to a specific app.

In Google Developers Console I have added the following type of restriction , package name & SHA1 Release Certificate fingerprint / Hash

Application Restrictions - Android Apps

Capture.PNG


This resulted in all http api requests failing : Error: REQUEST_DENIED

I then found I was to also include / add package name and fingerprint to all the api requests
B4X:
Sub GetLocationNameByLatLon(lat As String, lon As String) As ResumableSub 'ignore

    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("latlng", lat & "," & lon,"key",GoogleApiKey))
    
    j.GetRequest.SetHeader("X-Android-Package", "MyAppPackage")
    j.GetRequest.SetHeader("X-Android-Cert", "92:F0:43:4D:3F:xx:xx:xx:xx:xx")

    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then .....

The Request are still failing : Error: REQUEST_DENIED

I have checked that the Console package name / hash exactly matches the .SetHeader Parameters

If I remove the API Restriction , all works perfectly. This is A Non Playstore App signed with a Private Sign Key in release mode)

Any suggestions ? Thanks
 
Top