Google maps in Android - android

I am trying to saw google map in emulator.
I also have obtained googleApi key for that...
but when i run my code it doesn't saw just grid insted of google map.
Any help?
Thanks......

you will have to add the below permissions in your manifest file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
and the below library:
<uses-library android:name="com.google.android.maps" />
inside the application tag.

Do you have the necessary permissions in your manifest? You should add:
<uses-library android:name="com.google.android.maps" />
under the Application tag.
In your layout file, check if you have the correct API key:
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="example_Maps_ApiKey_String"
/>
Also, if you are just debugging, you should use the API key for the debug keystore. For instructions on how to do that, see here.

Well, I shared the same issue long time back,
I am enlisting some of the steps you MUST follow in order to get Maps Running.
You must have an AVD which is configured to target Google APIs(Google Inc) Level 'x', where x can be platform specific API level. e.g. If you are using Android 2.2 Platoform create an AVC with target as Google APIs(Google Inc) Level 8
Well when your emulator is correctly configured, you must create an android project whoes build is targeted to the specified API in step 1 or lower.
When you create your activity which would display your Map, activity class MUST extend com.google.android.maps.MapActivity (this will not be visible until you have specified correct build target) and not normal android.app.Activity. You must also implement MapAcitivities abstract method isRouteDisplayed(). You should also mention MapActivity extending class in your AndroidManifest.xml if you are created a new class(child of ),:<activity android:name="IExtendedMapAcitivity"/>
Another edit which you have to perform in your manifest is, you must mention Google API library being used, againg as you child of<application>
<uses-library android:name="com.google.android.maps" />
You should also mention required permissions in your manifest:
<uses-permission android:name="android.permission.INTERNET" />
Last and the most important step is obtaining your apiKey from google, make sure that you are using default debug keystore when obtaining that, which is present in your C:\Users\.android\debug.keystore [on windows]
using application specific keystore wont work.
Your code should look like
<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="[key]"/>
</LinearLayout>
for more info on this try http://code.google.com/android/add-ons/google-apis/mapkey.html.
I hope this helps to you and all other newbies. Omiting any of the steps will result in not so correct behaviour of MapAcitivity.

Related

App shortcut disappears after every update, what's wrong with my Manifest?

I've no idea why this is happening, I've tried everything. Every time I update the app, the previous shortcut that was on the home screen disappears.
Here is my complete app manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.SpaceMonkey.Boats" android:versionCode="161" android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="21" />
<application android:label="Boats" android:icon="#drawable/playstore"></application>
<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" />
</manifest>
And my main activity:
[Activity (Label = "Boats", Icon = "#drawable/playstore", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
The only thing I change when I update is the versionCode and versionName in the manifest, absolutely nothing else changes.
What am I doing wrong here?
EDIT: I'm starting to think that it's a problem with Xamarin generating a new app manifest in the background, I'm not sure how to check that.
EDIT: I've just tested with an Android (Xamarin) app that doesn't use Xamarin.Forms and it didn't have that problem. My suspicions where confirmed that it's something related to Xamarin.Forms.
In my case the issue was triggered by changing the AssemblyVersion of the AssemblyInfo.cs of my Android app project.
This issue is caused by Xamarin.Android 5.0 and later (not by Xamarin.Forms). As explained in the release documentation here:
With the 5.0 release, the default package names for Android Callable
Wrappers will be based on the MD5SUM of the assembly-qualified
name of the type being exported.
The AssemblyVersion being part of the assembly-qualified name, any version change created a new MD5 hash, creating a new default package name. (Read more about the assembly qualified named here)
App shortcut uses the default package name to launch your app so every update would make the shortcut void and the system would remove it.
Fix: Don't change the AssemblyVersion in your Android project or anything else that changes the assembly qualified name.
The problem was Xamarin Studio. I basically recreated the solution and copied everything, then the problem disappeared...
I don't know what was happening, but it's solved now.

Place Picker Automatically close after launch

I want to show place picker so that user can choose location of his/her own choice. But place picker child activity automatically closes after launch. I've check the API key multiple times and other permissions, everything is correct. Here is all the code. Please help!
task_location.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
Intent intent = intentBuilder.build(NewTaskActivity.this);
// Start the Intent by requesting a result, identified by a request code.
startActivityForResult(intent, 123);
} catch (GooglePlayServicesRepairableException e) {
GooglePlayServicesUtil
.getErrorDialog(e.getConnectionStatusCode(), NewTaskActivity.this, 0);
} catch (GooglePlayServicesNotAvailableException e) {
Toast.makeText(NewTaskActivity.this, "Google Play Services is not available.",
Toast.LENGTH_LONG)
.show();
}
}
});
And here is the menifest file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
tools:replace="android:icon">
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAjM9hWUXm8vlABqFbM_fJfQgIFli8HP1E"/>
Please check the logcat of your app for 'PLACES_API_ACCESS_NOT_CONFIGURED' message. If this is the case, enabling the Google Places API for Android in your Google Developer Console for this project should solve your problem.
After A lot of debugging i solved it myself. The problem was package name..Android studio manage package name by itself on project creation. I change the package name in manifest and it was working perfectly fine. but when i get API key from google developers console for place picker, place picker automatically closes without a single character of error.
Then I change the package name by going into -> Module Settings -> Flavors and change the Application ID and it fix the problem.
Make sure that Google Places API is enabled for the API key that you are using in Google API console. For me, I am using the same API key that I use for maps. I just enabled the same key for places api also. That solved my problem.
Use this link to access the Google console: https://console.developers.google.com/flows/enableapi?apiid=placesandroid&reusekey=true
Solved problem by just changing the API key
You can create a new key from here
Instead of enabling the places API, Enable the places SDK for android. Worked for me.
Good Luck :)
Enable both places API as well as Places sdk

Adding Permissions in AndroidManifest.xml in Android Studio?

In Eclipse we were able to add permissions in AndroidManifest.xml by going to AndroidManifest.xml->Permission-> Adding permissions.
How to add permissions in Android Studio? How can we get a list of all the permissions that we can add to an Activity ?
You can only type them manually, but the content assist helps you there, so it is pretty easy.
Add this line
<uses-permission android:name="android.permission."/>
and hit ctrl + space after the dot (or cmd + space on Mac). If you need an explanation for the permission, you can hit ctrl + q.
You can type them manually but the editor will assist you.
http://developer.android.com/reference/android/Manifest.permission.html
You can see the snap sot below.
As soon as you type "a" inside the quotes you get a list of permissions and also hint to move caret up and down to select the same.
Go to Android Manifest.xml
and be sure to add the <uses-permission tag > inside the manifest tag but Outside of all other tags..
<manifest xlmns:android...>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
This is an example of the permission of using Internet.
You can add manually in the manifest file within manifest tag by:
<uses-permission android:name="android.permission.CAMERA"/>
This permission is required to be able to access the camera device.
It's quite simple.
All you need to do is:
Right click above application tag and click on Generate
Click on XML tag
Click on user-permission
Enter the name of your permission.
Put these two line in your AndroidMainfest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

How to run map application with out using "com.google.android.maps" in manifest

I have developed map application.
In manifest XML i have added <uses-library android:name="com.google.android.maps" />
With this it is working fine in mobile devices and emulator.
But in kindle fire device it is not working, when i remove <uses-library android:name="com.google.android.maps" /> from manifest it is working fine in kindle fire.
Is there any way to use google maps by removing <uses-library android:name="com.google.android.maps" /> from manifest file.
How to use this library reference with out writing in manifest XML.
uses-library has an under-used required attribute on it.
uses-library documentation
Thus:
<uses-library
android:name="com.google.android.maps"
android:required="false" />
If you set this to false, your app will install fine on the Kindle Fire, but the maps API calls will still fail, since the maps library is, in fact, not present. To get around this, you'll need to guard your code to not call the API when it isn't present. I use code like this, myself:
protected boolean mapsAvailable() {
try {
Class.forName("com.google.android.maps.MapView");
return true;
} catch (ClassNotFoundException exception) {
return false;
}
}
If mapsAvailable returns false, don't go to any activities using the MapView, don't call any Maps API classes, etc.
just put this code
String geoAddress = "geo:" + ll[0] + ","+ ll[1] + "?z=15";
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(geoAddress));
context.startActivity(intent);
and add the permission in the manifest
In order to use Maps API, you must have to provide reference to its library, otherwise NoClassDefFoundError exception will be thrown. Read this.

How to build Different Android Apps using ant scripts

Hello i'm building a custom application.
PRE:
The app will be restricted to a limited amount of user. ( let's say 20 people )
The app should be unique per each user so each apk will refer to a user only.
Each app should have a different package name
So i was starting to think a building script that takes the user list and creates 20 apks ( one for each user ) and updates the strings.xml file with the custom modification needed per-user.
But i really don't know where to start. Is there a good way or a tutorial where i can refer to ?
Just to be clear i'd like to have a manifest like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="$pname"
android:versionCode="1"
android:versionName="1.0">
<application>...</application>
</manifest>
And then replace the $pname using ant.
Perhaps you are looking for the aapt command. It has an additional flag --rename-manifest-package. The help says
Rewrite the manifest so that its package name is the package name
given here. Relative class names (for example .Foo) will be
changed to absolute names with the old package so that the code
does not need to change.
I would be using 20 different semi-empty default activities (one per each of users) located in 20 different packages extending 1 real activity, like:
mypackage.user01.MyMainActivity extends mypackage.MyMainActivity;
mypackage.user02.MyMainActivity extends mypackage.MyMainActivity;
mypackage.user03.MyMainActivity extends mypackage.MyMainActivity;
...
mypackage.user20.MyMainActivity extends mypackage.MyMainActivity;
And then 20 different androidmanifests.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage.userXX">
<application
android:icon="#drawable/MyIcon"
android:label="#string/MyApplication"
>
<activity android:name=".MyActivity"
android:label="#string/MyActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="mypackage.MyActivity"
android:label="#string/MyActivity"/>
<activity
android:name="mypackage.user01.MyActivity"
android:label="#string/MyActivity"/>
<!-- etc. till user20 -->
</application>
</manifest>
which will be copied using simple Ant copy tasks to real one - it's easy to implement, though a bit boring :)
It might be simpler if you store 20 codes in your app, and give one code to each customer. Then just give each customer the same application. The application changes its properties depending on what code was entered.
If this sounds like the right approach, I'll see if I can code some specific aspects. If it isn't the approach you're after, please could you give me a bit more information on how these 20 people would be identified?
You could also use some unique device-identifier. There was an intersting article about that on the Android Developers Blog.
If you want to create a build-script, you can use Ant.

Categories

Resources