Android google map not loaded after inserting API key - android

I am trying to load google map in mapview. I have inserted google API key in main.xml.
This is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="My.google.mao"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".GmapActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
This is main.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Api key"/>
//Api key has been inserted
Only boxes are being loaded in mapview, can anyone solve my problem?

Most likely reason is mixing up debug key and release key, as the signitures are different the keys are different, you need to get both. There is a post on programaticaly selecting the right key

This problem comes in 2 situations
Give these uses permissons also Acces core location, access fine location
and one more thing is you ar enot given correct API key so generate properly tryagain,
That api key will work only in your system
If you have any problem with generating api key i will help you

Related

Multiple root tags /top level element is not completed

I'm tring to build a basic chat app in android , is my first app and i'm trying to learn
Right now i'm getting stuck at the Sign in and Sign Up interface because i have some errors in AndroidManifest.xml
here is the code :
`
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools"
package="com.example.icom"/>
<application
android:allowBackup="true"
android:fullBackupContent="false"
android:icon="#mipmap/ic_launcher"
android:label="Icom Chat"
android:icon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Icom"
tools:ignore="DataExtractionRules"
android:name=".activities.SignUpActivity"
android:windowSoftInputMode="adjustResize"
tools:ignore="MissingClass,WrongManifestParent" />
<activity
android:name=".activities.SignInActivity"
android:exported="true"
android:windowSoftInputMode="adjustResize"
tools:ignore="MissingClass,WrongManifestParent"
android:name=".MainActivity"
tools:ignore=".MissingClass,WrongManifestParent" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</manifest>
`
I receive the following errors :
Multiple root tags
Top level element is not completed
Can someone explain to me how i can fix this ?
Thank you very much .
Run the Sign In and SignUp interface for aan Chat app
It may sound stupid but i've tried a video tutorial from yt

Grids are displayed instead of maps when using mapview

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.

Cannot see my custom IME in Android

I am trying to create a very simple QR input method in Android. Far from being actually runnable in "production", I am trying to run my custom QR keyboard application on my Nexus 6 device, at least to see where it will crash.
However, after deploying the APK to the device I cannot choose my custom input.
Following is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.zighinetto.qrkey" >
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<service
android:name=".services.QrInputService"
android:enabled="true"
android:permission="android.permissions.BIND_INPUT_METHOD" >
<intent-filter>
<action android:name="android.view.InputMethod" />
</intent-filter>
<meta-data
android:name="android.view.im"
android:resource="#xml/ime" />
</service>
<activity
android:name=".ui.SettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
</application>
</manifest>
And... ime.xml
<?xml version="1.0" encoding="utf-8"?>
<input-method
android:isDefault="true"
xmlns:android="http://schemas.android.com/apk/res/android">
</input-method>
So far I have:
- Enabled CAMERA permission because I need to use the camera
- Created the IME service and linked it to the BIND_INPUT_METHOD permission, so that only the system can bind to it
- NOT declared the BIND_INPUT_METHOD as permission used by my application, because only the system needs that permission.
I expect the new QR input service to be visible in Android's "Language and input" screen, however I cannot see it.
What is wrong in my manifest?

Google Map API v2 grey tiles, everything worked fine (code inside)

Everything was working fine, the only problem I had is when I change the city to some place south in my country and I get the common "app stopped working problem" but that's fine, I also think what messed this thing up is when I tried to export the application and filled the keystore fields etc.
I searched everywhere on Google and didn't find anything useful, all the solutions I've tried failed so far. Including:
- Creating a whole new project from the beginning with the map only. I still get only grey tiles and no map. (I also tried using MapFragment and not SupportMapFragment)
- I deleted debug.keystore and even default.keyset and generated the API key a few times, still nothing worked.
Here's the code though I don't think there's anything wrong with it:
The Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pfetest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Maps API needs OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/icon_pfe"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyDMsGnxt0GrU7Se5arkExJ96uLKqJWmjcQ"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.pfe.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.example.pfe.Couverture"
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>
I retrieve the map using this on MainActivity in the onCreate() method
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fm.getMap();
</code>
Still need a little try catch for this but it was working.
the layout is like this.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/m1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="1"
android:orientation="horizontal"
tools:ignore="NewApi" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="458dp"
android:layout_column="0"
android:layout_gravity="left|fill_vertical"
android:layout_row="2"
class="com.google.android.gms.maps.SupportMapFragment" />
</GridLayout>
I just want to press the compile button and get the map working, so if anyone could help with anything, I'll be very grateful!
Problem solved.
Here's what I did for those who encountered such an issue: I first removed the project and re-imported it onto eclipse, renamed the package completely, deleted the debug.keystore file and rebuilt the project to get a new one then regenerated a new API key and put it into my manifest using the new SHA1 fingerprint.
The thing is that I did all of the above several times without success and decided to leave it for a while and retried to run it every now and then (without touching the source code) and today it just worked so maybe the API key needs some time to function correctly.
Feel free to ask me about any detail if you get the same problem!

Google Map Displaying Grey Squares

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

Categories

Resources