Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

How to deal with native features like Google Play Services and DependencyService ?

$
0
0

Hello guys,

I'm requesting your help one more time.

I was working with Xamarin.Forms.Maps until i noticed that it's still too young to do some things that i would like to do, for example, drawing routes between two points. Then, i figured out that i could use an interface and DependencyService to have all the features offered by Android and iOS.

So i learned how to use DependencyService and implementations with the Xamarin's tutorial, i tested the sample with the speaker and it worked.

However, when i tried to adapt the tutorial to fit the Google Play Services and its Map system, i had some bugs that i can't explain.
I want to focus first on Android platform : I added the permissions requested to use the maps, here is my AndroidManifest.xml :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="PapayeMobile.Android">
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="17" />
    <application android:label="PapayeMobile.Android">
        <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="THE_API_KEY_THAT_WORKED_FOR_XAMARINFORMSMAPS" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    </application>

    <!-- Google Maps for Android v2 requires OpenGL ES v2 -->
    <uses-feature android:glEsVersion="0x00020000" android:required="true" />

    <!-- We need to be able to download map tiles and access Google Play Services-->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Allow the application to access Google web-based services. -->
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <!-- Google Maps for Android v2 will cache map tiles on external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <!-- Google Maps for Android v2 needs this permission so that it may check the connection state as it must download data -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Permission to receive remote notifications from Google Play Services -->
    <!-- Notice here that we have the package name of our application as a prefix on the permissions. -->
    <uses-permission android:name="android.permission.MAPS_RECEIVE" />
    <permission android:name="android.permission.MAPS_RECEIVE" android:protectionLevel="signature" />

    <!-- These are optional, but recommended. They will allow Maps to use the My Location provider. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>

When i construct the project, it works, no error. So i added the Google Play Services component (Google Play Services is installed in Android SDK Manager). Still no problem. But when i wanted to create the interface and its implementations for Android and iOS, it started to bug and i think it brokes the project because even if i remove the interface and the implementations, i still got the same errors.

So, here is the interface:

using System;
using Xamarin.Forms;

namespace PapayeMobile
{
    public interface IMap
    {
        ContentView Show();
    }
}

The Android implementation :

using System;
using Xamarin.Forms;
using System.Collections.Generic;
using PapayeMobile.Android;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Gms.Maps;

[assembly: Xamarin.Forms.Dependency (typeof (Map_Android))]
namespace PapayeMobile.Android
{
    public class Map_Android : Java.Lang.Object, IMap
    {
        public Map_Android () {}

        public ContentView Show ()
        {
            ContentView fragment = new ContentView ();

            var myMapFragment = MapFragment.NewInstance();
            FragmentTransaction tx = FragmentManager.BeginTransaction();
            tx.Add(fragment, myMapFragment);
            tx.Commit();

            return fragment;
        }
    }
}

The iOS implementation :

using System;
using Xamarin.Forms;

[assembly: Xamarin.Forms.Dependency (typeof (Map_iOS))]
namespace PapayeMobile.iOS
{
    public class Map_iOS : IMap
    {
        public Map_iOS () {}

        public ContentView Show ()
        {
            ContentView fragment = new ContentView {
                Content = new Label { Text = "iOS implementation of IMap" }
            };

            return fragment;
        }
    }
}

And here is the errors i get :

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Tool exited with code: 1. Output: max res 19, skipping values-v21
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-mdpi/abc_ab_share_pack_holo_dark.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-hdpi/abc_ab_share_pack_holo_dark.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-xhdpi/abc_ab_share_pack_holo_dark.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-hdpi/abc_ab_share_pack_holo_light.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-xhdpi/abc_ab_share_pack_holo_light.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/drawable-hdpi/abc_spinner_mtrl_am_alpha.9.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v11/values.xml:50: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v14/values.xml:9: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v11/values.xml:57: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v14/values.xml:17: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v11/values.xml:64: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v14/values.xml:25: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v11/values.xml:71: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

/Users/williamz/.local/share/Xamarin/Android.Support.v7.AppCompat/21.0.3/embedded/./res/values-v14/values.xml:33: error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

(PapayeMobile.Android)

Can anyone helps me to figure out the issue and a solution ?

Thank you.

William.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>