I've made a very simple app that just displays a Google map. However, it only seems to be displaying gray squares.
I've troubleshooted and have done virtually everything I could. I checked my code 5+ times over, I've compared it even to other tutorials. I've re-made my API key 3 times - none of them work.
The phone I'm using is connected to wireless. Even the emulator won't work. I have the library and permission established in the manifest. I think I've done just about everything, but it still doesn't work... any suggestions?
Here's my code:
MapsActivity.java:
package net.learn2develop.GoogleMaps;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.os.Bundle;
public class MapsActivity extends MapActivity
{
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0duU2_tgS67qkUZIpmLVIo0IDvJDh4Ew1Mzh9Pg"
/>
</RelativeLayout>
GoogleMapsManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.GoogleMaps"
android:versionCode="1"
android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="7" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
You need to add
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
into you manifest
Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.)
The problem was that Mike was using an API key generated with the release keystore instead of the debug keystore that eclipse uses when compiling the apk.
I had the same error ! I tried everything, so a try this tutorial below and it worked!!!!
TUTORIAL
Related
I know there are a many questions on this topic. I have went to all of those questions and tried a lot of suggestions given in stack overflow and at other sites. But unfortunately, none has solved my problem.
When I am using MapView and MapsActivity, grid is displayed instead of maps. As suggested, I have regenerated API key and I have made sure that I have given the same package name as of my application, SHA1 key and I have enabled the Google Maps ApI for Android in the Credentials. I have given all the permissions, that are needed for maps, in Manifestfile.xml, my manifest file is as shown below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.samplemaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<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"/>
<permission
android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<uses-library android:name="com.google.android.maps"/>
<activity
android:name=".MapsActivity"
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.maps.v2.API_KEY" android:value="AIzaSyClOHCG7SBYxg1o6YdUWhn03VSqWwE1y_g"/>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
My layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
and my activity that extends MapActivity:
package com.example.mapsample;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class GoogleMaps_Sample extends MapActivity{
public void onCreate(Bundle b){
super.onCreate(b);
setContentView(R.layout.googlemapssample);
}
#Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
When I use the above activity, grids are displayed. When I extends FragmentActivity instead of MapAcitivity and fragment instead of mapview, I have been getting an error saying unfortunately stopped and some times it says some fragment class error.
I have also installed Google API system image for the emulator I am using. I have downloaded Google Play Services too. But still, maps is not displayed to me. I have done almost everything as suggested in other questions.
What is the error or mistake in my application that is preventing maps to get displayed and that displays grid instead.
Thanks in advance.
I am running sample code that is provided on Google Map Documentation for Google Map Api v2 (https://developers.google.com/maps/documentation/android/start#specify_settings_in_the_application_manifest).
The code run successfully but Map is not loaded on the device. Only white screen is shown on the device. I am using 4.0.3 version Android device.
1) I enabled service for the project.
2) Generated key:
3) "google-play-services_lib" as Library in project:
4) Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mapdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.mapdemo.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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" />
<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="AIzaSyCvZrhQ8YBfyYBvTic3DSdu2O06nAmhpg4" />
<activity
android:name="com.example.mapdemo.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>
</application>
</manifest>
5) Activity:
package com.example.mapdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
6) Layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
Use Fragment activity
eg:
public class Maps extends FragmentActivity {
GoogleMap map;
double lat;
double lan;
boolean flag = false;
// private LocationManager lm;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapptry);
map = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
}
}
Change ur map.xml to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
EDIT
Got to do this also
import android.support.v4.app.FragmentActivity;
Before you do this Right click project->properties->buildpath->java build path -> libraries .. then click on add external jars
the go to
user\android-sdks\extras\android\support\v4
and select android-support-v4.jar
PS: Do all this provided your API key is correct . If you API key is wrong then also it shows only a white screen
try to add
GoogleMap googleMap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
and replace your xml with
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
/>
you have added the following code outside application tag instead put it inside the tag
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
hope this might help someone who is facing the same problem
May be this problem with API key or you just check your SHA1 fingerprint in your project api console(https://console.developers.google.com/project) and your eclipse Windows -> Preferences -> Android -> Build are same, other wise just update the SHA1 from console to build path or vice versa.
Most probably your problem will be solved when you make sure below mentioned things:
Activate Google Map API
Use correct package name while generating API Key (in my case this was the mistake) .. and this seems problem to your case also as package name appears to be wrong (com.example.mapdemo)
Make Sure you are using the correct keystore file for generating the SHA1
Hope this will be helpful.
To maintain security for the system and users, Android requires apps to request permission before the apps can use certain system data and features. Depending on how sensitive the area is, the system may grant the permission automatically, or it may ask the user to approve the request.
https://developer.android.com/guide/topics/permissions/index.html
In case anyone else is as dumb as me... make sure the device you are testing on is connected to WiFi...
When I load my MapView application, the MapView only displays the grey grid lines.
Here is my Code:
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="0aOphT3vlZFVSL1HZ2Vg-RmIDhH0nPlp8e7gJrg"/>
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.andoid.googlemaps"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="com.google.android.maps"></uses-library>
<activity android:name=".GMapsActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="1" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
Activity:
package com.andoid.googlemaps;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class GMapsActivity extends MapActivity {
private MapView mapView;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* Proxy Settings*/
System.setProperty("http.proxySet", "true");
System.setProperty("http.proxyHost", "proxy.example.com");
System.setProperty("http.proxyPort", "8080");
setContentView(R.layout.main);
mapView=(MapView)findViewById(R.id.map_view);
mapView.setBuiltInZoomControls(true);
}
#Override
protected boolean isRouteDisplayed() {
return false;
}
}
Thanks in advance for any help...
See the following link on displaying google map. This may help you
Tutorial on How to use Google map
The API key used for the map depends on the certificate used to sign your application.
You must follow the following instructions to get a valid API key.
The Android Maps API lets you embed Google Maps in your own Android applications. A single Maps API key is valid for all applications signed by a single certificate. See this documentation page for more information about application signing. To get a Maps API key for your certificate, you will need to provide its the certificate's fingerprint. This can be obtained using Keytool. For example, on Linux or Mac OSX, you would examine your debug keystore like this:
See Sign Up for the Android Maps API.
This often means that you need a key for debug-builds and another for release-builds (signed application package for Android market for example).
After a long time its worked. But still not got where was the problem actually,nothing i changed just i shared debug.keystore with my friend and its worked. Any way thanks for the reply...
Thanks in advance for your efforts.
I have an Application that revolves around a ListActivity extended class. Before the app starts, I want to check whether the user is registered, and if not tell him to and get some info from him. So, I tried to call StartActivity in the OnCreate() method. When that loaded, I got a big black screen.
I thought that it may be related to being run in the OnCreate so I let the Activity start as usual, and I tried to run it in an OnClick event, and I got the same result.
In both cases, if I press escape, that Window goes away and the main app window comes back.
Here are the lines from where I call the new Activity
Intent emailIntent = new Intent(this, EmailAddressGetter.class);
this.startActivity(emailIntent);
Here is the code of the class
/**
*
*/
package com.kosherapp;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
/**
* #author Josh
*
*/
public class EmailAddressGetter extends Activity {
public void OnCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emailinput);
}
}
Here is the emailinput xml contents
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff"
android:textColor="#000000"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:text="hello"
>
</TextView>
And, here is the manifest contents
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kosherapp"
android:versionCode="1"
android:versionName="1.0"
>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.CALL_PHONE" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
>
<activity
android:name=".KosherApp"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
>
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".EmailAddressGetter"
android:label="email Address Getter"
>
</activity>
<activity
android:name=".GoogleMaps"
android:label="Google Maps"
>
</activity>
<uses-library
android:name="com.google.android.maps" />
</application>
</manifest>
Let me know if there's any other info you may need. Oh, I'm running this with the Google API 2.1-update
Thanks
Change OnCreate to onCreate in EmailAddressGetter.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.emailinput);
}
You need to use EditText instead. TextView is for static text which is why nothing is displaying. You should also include the EditText in another layout like Linear or Relative so it looks cleaner.
You are using an intent to call EmailAddressGetter but it doesn't have an intent filter in the manifest. Throw in something like Log.e("EmailAddressGetter", "It worked") in your onCreate and use ddms to see if it is actually opening that activity.
Also, in the updated code in your comment to Robby Pond, remove the xmlns line from EditText
I'm trying to create an app that will change a setting when the user holds the search button. It seems that the combination of the WRITE_SETTINGS permission and the fact that the activity is launched from another application using the long press makes the parent task crash. For example, if I'm looking at Google Maps and hold the search button, the SearchButtonPopup does not appear and Google Maps crashes.
I tried taking the Theme.Dialog out, but it didn't make any difference. Removing the permission makes it robust again, no crashes, but I need the permission! Any fixes or workarounds?
These are my manifest and java files:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.stathissideris.searchbuttonpopup" android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application android:icon="#drawable/logo" android:label="#string/app_name"
android:debuggable="true" android:permission="android.permission.WRITE_SETTINGS">
<activity android:name=".SearchButton" android:theme="#android:style/Theme.Dialog">
<intent-filter>
<action android:name="android.intent.action.SEARCH_LONG_PRESS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
SearchButton.java
package org.stathissideris.searchbuttonpopup;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class SearchButton extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("SearchButtonPopup", "search held");
}
}