I'm working on a Monodroid android app. I've added Google maps with a fragment but the map will not show up and I'm not getting any errors thrown.
My Axml code :
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
Activity Code :
protected async override void OnResume()
{
base.OnResume();
tblLocations location = Nav.GetAndRemoveParameter<tblLocations>(Intent);
LatLng latLng = new LatLng(location.Latitude, location.Longitude);
CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
builder.Target(latLng);
builder.Zoom(5);
CameraPosition cameraPosition = builder.Build();
CameraUpdate cUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);
mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
map = mapFrag.Map;
if (map != null)
{
map.MoveCamera(cUpdate);
}
}
I realize it's something with the API key but what am I missing here?
LOG CAT OUTPUT
04-01 16:40:24.662 D/ChimeraFileApk(20730): Classloading successful. Optimized code found.
04-01 16:40:24.730 E/NEW_BHD (20811): Battery Power Supply logging Daemon start!!!!!
04-01 16:40:24.730 E/NEW_BHD (20811): Cannot run on production devices!
04-01 16:40:24.755 I/Google Maps Android API(20730): Google Play services client version: 848700004-01 16:40:24.755 I/Google Maps Android API(20730): Google Play services client version: 8487000
04-01 16:40:24.764 I/Google Maps Android API(20730): Google Play services package version: 8703436
04-01 16:40:24.804 I/art (20530): CollectorTransition marksweep + semispace GC freed 471(-32KB) AllocSpace objects, 0(0B) LOS objects, 24% free, 7MB/9MB, paused 16.348ms total 16.348ms
04-01 16:40:25.088 D/VoldConnector( 2225): SND -> {10 volume mkdirs /storage/emulated/0/Android/data/asked.askeduniversalremote/cache/}
04-01 16:40:25.220 D/Mono (20730): Assembly Ref addref Xamarin.GooglePlayServices.Maps[0xb9b18688] -> Xamarin.GooglePlayServices.Basement[0xb9b148d0]: 2
04-01 16:40:25.283 I/b (20730): Sending API token request.
04-01 16:40:25.316 I/Keyboard.Facilitator( 3831): onFinishInput()
04-01 16:40:25.357 I/LaunchCheckinHandler( 2225): Displayed asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity,wp,ca,947
04-01 16:40:25.357 I/ActivityManager( 2225): Displayed asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity: +947ms
04-01 16:40:25.372 E/NetlinkEvent( 299): NetlinkEvent::FindParam(): Parameter 'UID' not found
04-01 16:40:25.612 I/b (20730): Received API Token: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
04-01 16:40:25.612 I/c (20730): Scheduling next attempt in 431700 seconds.
04-01 16:40:25.615 I/d (20730): Saved auth token
04-01 16:40:25.719 I/SFPerfTracer( 258): triggers: (rate: 7:437) (compose: 1:20) (post: 0:21) (render: 2:51) (6:7515 frames) (7:10501)
04-01 16:40:25.719 D/SFPerfTracer( 258): layers: (3:12) (FocusedStackFrame (0xb782cb78): 0:383)* (DimLayer (0xb786b8f0): 0:2)* (StrictModeFlash (0xb7804b60): 0:50)* (StatusBar (0xb780a350): 0:2953) (com.android.systemui.ImageWallpaper (0xb781e148): 0:163)* (NavigationBar (0xb78a5528): 0:402) (DimLayer (0xb7892338): 1:14)* (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.WaitTimeActivity (0xb789fa28): 0:51)- (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherSitesActivity (0xb78aef90): 0:108)- (asked.askeduniversalremote/md5d1d3b2ca018abe66d5a9f8b4db614c6f.ViewOtherLocationOnMapActivity (0xb789f9e0): 7:25)
04-01 16:40:27.516 D/audio_hw_primary( 303): out_standby: enter: stream (0xb7690308) usecase(1: low-latency-playback)04-01 16:40:27.516 D/audio_hw_primary( 303): out_standby: enter: stream (0xb7690308) usecase(1: low-latency-playback)
04-01 16:40:27.616 D/hardware_info( 303): hw_info_append_hw_type : device_name = speaker04-01 16:40:27.616 D/hardware_info( 303): hw_info_append_hw_type : device_name = speaker
04-01 16:40:29.766 E/NEW_BHD (20866): Cannot run on production devices!
04-01 16:40:31.127 D/Mono (20730): [0x9e1ff930] worker finishing
04-01 16:40:31.167 D/WifiStateMachine( 2225): starting scan for
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_loop(): handled 1
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_handle_event(): transition
04-01 16:40:34.778 D/SLPC ( 3416): slpc_poll_loop(): about to poll...
04-01 16:40:34.778 D/sensorhub( 3416): sensorhub_poll() polling...
04-01 16:40:34.796 E/NEW_BHD (20867): Battery Power Supply logging Daemon start!!!!!
04-01 16:40:34.797 E/NEW_BHD (20867): Cannot run on production devices!
04-01 16:40:35.292 D/NetlinkSocketObserver( 2225): NeighborEvent{elapsedMs=6311820, 192.168.105.1, [C86C870B13EB], RTM_NEWNEIGH, NUD_STALE}
04-01 16:40:35.783 V/AlarmManager( 2225): sending alarm {58361af type 2 *walarm*:com.motorola.slpc.ALARM_STOWED}
04-01 16:40:35.786 D/ModalityService( 3416): StowedListener(): callback onStowedChange() -> 2
04-01 16:40:35.787 V/AlarmManager( 2225): done {58361af, *walarm*:com.motorola.slpc.ALARM_STOWED} [4ms]
04-01 16:40:35.787 D/ModalityManager( 5416): onStowedChange() -> 2, package: com.motorola.actions
UPDATE Logcat is now showing the following warning
04-04 09:30:07.355 W/ctxmgr ( 4204): [AclManager]checkPermissionTypeStatus: no inject permission for { uid=10019, packageName=com.google.android.gms }. Returned permission was: PACKAGE_NOT_WHITELISTED for context name=POWER_CONNECTION, account=account#-517948760#
04-04 09:30:07.358 W/ctxmgr ( 4204): [AclManager]checkPermissionTypeStatus: no inject permission for { uid=10019, packageName=com.google.android.gms }. Returned permission was: PACKAGE_NOT_WHITELISTED for context name=POWER_CONNECTION, account=account#-517948760#
Make sure that the hash provided to your Google API console is the correct one, you can provide two hashes, one for your debug.keystore and one for the production keystore.
to check if the hash is correct, run your app with the debug/production keystore check the log output of this snippet (It's in Java but I believe there are similar APIs in Xamarin) and compare it to the one in the API console:
PackageInfo info;
try {
info = getPackageManager().getPackageInfo("com.you.name", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md;
md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String something = new String(Base64.encode(md.digest(), 0));
//String something = new String(Base64.encodeBytes(md.digest()));
Log.e("hash key", something);
}
} catch (NameNotFoundException e1) {
Log.e("name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("no such an algorithm", e.toString());
} catch (Exception e) {
Log.e("exception", e.toString());
}
Here is the c# Implementation
private void CheckSignatureHash()
{
try
{
PackageInfo info = PackageManager.GetPackageInfo("com.package.name", PackageInfoFlags.Signatures);
string hash = "";
foreach (var sign in info.Signatures)
{
MessageDigest md = MessageDigest.GetInstance("SHA");
md.Update(sign.ToByteArray());
hash += Base64.EncodeToString(md.Digest(), Base64Flags.Default);
Console.WriteLine("***********************************");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("KeyHash:" + hash);
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("***********************************");
}
//Toast.MakeText(this, hash, ToastLength.Short).Show();
}
catch (PackageManager.NameNotFoundException e)
{
}
catch (NoSuchAlgorithmException e)
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With