google map does not show up - java

I'm trying to display the google map for an android project. I followed all the steps without any problems, but when i launch my application, the map simply doesn't show up, i just have a white screen.
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.map"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.map.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.map.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MyKeyXXXXXXX" />
<activity
android:name="com.map.HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.map.MapActivity"
android:label="#string/title_activity_map" >
</activity>
</application>
</manifest>
Does anyone see something wrong ?
thanks in advance

Here are the steps you should follow:
Grab the Google Play services SDK (It's where the Maps API is)
Get the API key
Set the key in the Application Manifest
Last but not least, don't forget that Google Maps will only show if your app is signed with the key you provided to get the Maps key.
For example, if you've used a production certificate and you're testing the app with the debug key, you won't be able to see the maps.

I had this problem too. Your API key is not the giant series of two characters. On the Google Maps API console, after you have created your project and enabled Google Maps, you need to go to the API Access page, and click on "Create a new Android Key" if you don't have one already.
Your API Key that you use in your app is the ~40 character string that appears on the new key. Paste that into the Manifest and it should work.

Related

"Default activity not found"

I keep getting the "Default activity is not found" error whenever I want to try and run my app. I have tried 'clean project', 'invalidate caches/restart' and restarted my computer.
UPDATE: I tried running different projects, but they all give the same error too. This makes me think there must be something wrong with settings.
It works perfectly for my friend, but I get the error that the "Default activity is not found". If I try to launch a specific activity it also says the activity is not found. This is the code in the androidmanifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ek97.fhict.theapp">
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<!--
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" />
<uses-permission android:name="android.permission. ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/loqate_logo"
android:label="#string/app_name"
android:roundIcon="#drawable/loqate_logo"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".bottomnavigationfinal"
android:label="#string/title_activity_bottomnavigationfinal"/>
<activity android:name="Settings" />
<activity
android:name=".Login"
android:label="#string/title_activity_login" />
<activity
android:name=".Registration"
android:exported="true"
android:label="#string/title_activity_registration" />
<activity android:name=".Navigation" />
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
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/.
-->
<activity
android:name=".GoogleMaps"
android:label="#string/title_activity_google_maps" >
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
</activity>
<activity android:name=".Profile" />
</application>
</manifest>
If it works for your friend and it is the same code it could be that all you need to do is to refresh the cache of your IDE:
File -> Invalidate Caches / Restart
Try this::
Your manifest is missing default activity
Add to any activity as you consider a default activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
I finally solved it by making sure all implementation versions were the same, there were some in a 28.0.0 version and others in a 26.1.0. version. Now the app works fine on the emulator. Thanks for your suggestions though

Google Play Services - Google login yields a network error

I am trying to integrate Google Play Services into my application in order to enable achievements. Upon application launch, a login attempt is being made which results in one of the following errors:
There was a problem communicating with Google servers.
Failed to log in. Please check your network connection and try again later.
A̶p̶p̶l̶i̶c̶a̶t̶i̶o̶n̶ ̶c̶r̶a̶s̶h̶e̶s̶
The application is incorrectly configured. Check that the package name and signing certificate match the cliend ID created in Developer console. Also, if the application is not yer published, check that the account you are trying to sign in with is listed as a tester account. See logs for more information.
Logcat displays absolutely no data related to this problem so I don't even have a clue what could be wrong. The app is authenticated correctly, with the correct SHA1 certificate fingerprint and app id copied to manifest. Does anyone have any could what this could be?
Thanks.
EDIT: Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.*****.xxx"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.app.Main"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.app.GameAct"
android:label="#string/title_activity_game"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="#string/app_id" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I resolved the issue I had by deleting Google+ data related to my previous game login and logging in again. I do not know what caused this error in the first place but it may be due to wrong settings in my Developer Console. I did change some things, like re-authenticated the app but the changes took effect only after deleting old data.

Android: Google Maps not showing

I got the SHA1 from Eclipse Windows\Preferences\Android\Build, entered it in the API console in the form of key com.mypackage, got the API key entered it in the manifest and the map is still not showing.
I tried with the cmd and still not working, it shows the same SHA1 as Eclipse.
Am I missing something?
In my case google map was not rendering.
Only Goolge was displayed below left corner
I have Followed below steps
created again new project in Google api console.
Passed my SHA1 key then semicolon then your application package name
Your_SHA1_Key;Your_APP_PACKAGE_NAME
You will get one API_KEY
Then mention below things in your manifest
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="YOUR_API_KEY" />
It may help you.
All the best.
Add this line in manifest file before your activity and inside application tag
<uses-library android:name="com.google.android.maps" />
That should solve your problem.
Its good to add errors and related xml snippets in the question for better understanding of your problem.
perhaps this link show you steps one by one.
for more clarity checkout this link.
There are so many things you should maintain, if you add your Manifest file, then it will be easy for us to give answer. Though I give you my manifest file please follow this and change the package.name only
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="package.name.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="package.name.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="package.name.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="***Your API Key***"/>
</application>
In your XML layout file paste this:
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tv_location"
class="com.google.android.gms.maps.SupportMapFragment"
/>
Try this and let me know.
Add Google play service as a library.
Put
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-library android:name="com.google.android.maps"/>
in Manifest.xml
Follow the instructions given here. After creating your project in Google Developers Console, select APIs, you will be prompted with a section of Popular APIs, select Google Maps Android API. Press enable API.(the image below is showing the steps in the new version of the console)
If you're still using the old console, enable the API, by selecting Services, then switch the button ON:
Note:
You don't need to enable the API for the debug version!
Here is nice blog that will be helpful.
You may be signing your app with a different certificate other than the one in your debug.keystore file located in your .android folder.
Make sure the SHA1 certificates match i.e the certificate in your credentials are the same with the one you're using to sign your app

Android Exception NameNotFoundException

I don't understand why happens this exception.
In my Main activity, in the method onCreate I have this code at first:
try {
PackageInfo info = this.getPackageManager().getPackageInfo("com.mypacket", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.e("Hash", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (NameNotFoundException e) {
Log.e("Hash", "Error: NameNotFoundException");
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
Log.e("Hash", "Error: NoSuchAlgorithmException");
}
The exception is NameNotFoundException, I want to solve it because I think it causes problem with the Facebook SDK.
Thank you all.
If helps, this is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myPackageName.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<supports-screens android:anyDensity="true"
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<permission android:name="com.myPackageName.app.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.myPackageName.app.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.myPackageName.app.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.myPackageName.app.permission.C2D_MESSAGE" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:name="#string/app_name"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.myPackageName.app" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
<activity
android:name="com.myPackageName.app.SplashScreen"
android:screenOrientation="portrait"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Google Maps V2 API KEY -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="apy key" />
</application>
</manifest>
You got your package name wrong. For safety, always use Context.getPackageName().
PackageInfo info = this.getPackageManager().getPackageInfo(this.getPackageName(), PackageManager.GET_SIGNATURES);
Your package name is com.myPackageName.app not com.mypacket.
BTW you can obtain package name by Context#getPackageName()
This issue occurs when you have generate hash key project and the application for which you are creating hash key are not on the some workspace / directory, so exception arises NameNotFoundException.
Cheers :)
It means that either you are giving wrong package name or maybe you are not sure about the package name.
Case 1. if you know about your package name, just cross check it.
Case 2. if you are not sure about the package name ( this situation may also arise when you did some code refactoring i.e. Rename Package )
There are multiple approaches to fix it
package name is mentioned in the top of the AndroidManifest.xml
If it is still not resolved to get package name by
Context.getPackageName();
or
Log.d();
In Logcat check the application column package name should be mentioned there.
This can also happen if you have the app already installed. If for example you were to debug your app and then test the release .apk on the same device without uninstalling the debug version. If that is the case, just uninstall and then the install should work.
Uninstall your app from your device then run it again through the android studio. It helps me

What's wrong with google map API v2?

This issue is common BUT I didn't find a solution on google, or stackoverflow (4days of research...)
Here is the thing :
I need to display a full screen google map, which i ve already done several times in other application i've developped.
BUT here i can't get it to work for an unknow reason !
The warning and the error i get when i open the SherlockFragmentActivity which contains the map :
The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
Here i'll explain how i did things in detail and post some code :
LIBRARY IMPORT :
Last version of Google play services imported in eclipse as library (checked)
In the project the google play services are imported as library in properties (like ABS)
MANIFEST :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pck name"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.company.pckgname.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- LOCATION -->
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name="app variable name"
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:theme="#style/Theme.Styleapp" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key" />
<activity
android:name=".ActivityLauncher"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/Theme.Sherlock.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... activities...
</application>
</manifest>
MAP LAYOUT :
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.company.pckgname.TransparentSupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
ACTIVITY :
public class ActivityGoogleMap extends SherlockFragmentActivity implements OnInfoWindowClickListener {
GoogleMap _googleMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// ABS
ActionBar bar = getSupportActionBar();
bar.setTitle(R.string.tle_map);
bar.setDisplayHomeAsUpEnabled(true);
// MAP
_googleMap = ((TransparentSupportMapFragment) getSupportFragmentManager().findFragmentById((R.id.map))).getMap();
//the map should still display at this point
}
}
And so that's it, the main code is here
The map was working up until now, i didn't do nything with the code map related...
I tried to regenerate a debug key on the google console, change the permissions .. etc i am out of idea !!!!
After changing the API key in AndroidManifest.xml you must clear application data.
To clear application data do one of the following:
Go to Settings > Application Manager > Select Your Application > Clear Data
Uninstall the application before re-installing it.
<uses-feature android:glEsVersion="131072" android:required="true" />
Put this under your permissions in your manifest.

Categories

Resources