Coder Social home page Coder Social logo

choicesdk's Introduction

A SDK that aims to wrap similar functionalities from HMS and GMS services to one common interface. This is the launchpad for app providers expanding from GMS (Google Mobile Services) to HMS (Huawei Mobile Services) without having another codebranch to be setup, published and maintained. Choice SDK is already in use in multiple commercial, public and private operated apps. The goal is to save development, maintainance and security issues now and in future.

Contents

Features

The SDK currently supports the following kits/APIs:

  • Analytics
  • Location
  • Maps
  • Messaging
  • Sign-In

Installation

HMS / GMS specific

To use HMS services in the first place, integration of the HMS core SDK is needed. Follow the steps mentioned in How to set up the HMS core sdk.
As for the firebase integration just follow the official guide: https://firebase.google.com/docs/android/setup

The following plugins are required by the core of the SDK and need to be declared in your app.

Project gradle:

buildscript{
    repositories {
        maven { url 'http://developer.huawei.com/repo/' }
    }

    dependencies {
        // GMS
        classpath 'com.google.gms:google-services:4.3.8'

        // HMS
        classpath 'com.huawei.agconnect:agcp:1.5.2.300'
    }
}

allprojects {
    repositories {
            maven {url 'http://developer.huawei.com/repo/'}
    }
}

App gradle:

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.huawei.agconnect'

Choice SDK

Add the following dependencies as required to your app. GMS, Firebase and HMS dependencies are included, so they do not need to be declared in your app.

dependencies {
    def choicesdk_version = '0.3.0'
    implementation "at.bluesource.choicesdk:choicesdk-analytics:$choicesdk_version"
    implementation "at.bluesource.choicesdk:choicesdk-location:$choicesdk_version"
    implementation "at.bluesource.choicesdk:choicesdk-maps:$choicesdk_version"
    implementation "at.bluesource.choicesdk:choicesdk-messaging:$choicesdk_version"
    implementation "at.bluesource.choicesdk:choicesdk-signin:$choicesdk_version"
}

Initialization

The Choice SDK needs the application context at start. You can provide the needed context by calling ChoiceSdk.init(this) in your application class:

class YourApp : Application() {
    override fun onCreate() {
        super.onCreate()

        ChoiceSdk.init(this)
    }
}

By default the SDK checks for GMS availability first. It is also possible to set the priority in which order the service availability is checked (for example if you prefer HMS services over GMS services on devices where both are available):

ChoiceSdk.init(this, listOf(MobileService.HMS, MobileService.GMS))

Usage

Usually instances of SDK classes can be created by using their corresponding factory, for example AnalyticsFactory.getAnalytics(this). These calls can throw an UnsupportedOperationException if neither GMS nor HMS services are available, so make sure to check beforehand.

The SDK might need some additional permissions, so add them if you see any Lint errors in your IDE.

Important note: The provided examples do not check for permissions! Add permission checks where needed.

Examples for each part are described in the documentation below.

HMS Setup

How to set up the HMS core SDK

Analytics

Analytics documentation

Location

Location documentation

Maps

Maps documentation

Messaging (Push Kit)

Messaging documentation

Sign-In

Sign-In documentation

Demo app setup

If you would like to use our demo app, you have to follow some steps to be able to build and run the project:

  • Create a GMS and HMS project and download google-services.json and agconnect-services.json files into ChoiceSDK/choicesdk-app.
  • In the app's build.gradle file replace hmsProperties['HMS_APP_ID'] with your HMS app id, or create a ChoiceSDK/choicesdk-app/hms.properties file in with the following content and your HMS app id: HMS_APP_ID=xxx
  • Change the applicationId of the app to the ID which you used to create the GMS/HMS projects.
  • To build a release version replace our release signing config with your keystore properties.

Links

choicesdk's People

Contributors

bluesource avatar minkiapps avatar radoyankov avatar simonmoser-bluesource avatar winren9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

choicesdk's Issues

Not a issue but a Question

I'm fairly new to all this. I'm using cordova and have a webapp. How do I implement this into cordova to create my webbapp for the new huawei devices? Have anyone tried it before? I'm not using Android Studio to create my app.

Map is no longer initialized correctly on HMS devices

Manually adding this in Application.onCreate() fixes the problem:

import com.huawei.hms.maps.MapsInitializer

if (HuaweiApiAvailability.getInstance().isHuaweiMobileServicesAvailable(this) == ConnectionResult.SUCCESS) {
    MapsInitializer.initialize(this)
}

Side note: Is Huawei still maintaining this library?

Action Required: Your app is not compliant with Google Play Policies

I recently received the message:

Issue with your app

Your app contains content that doesn’t comply with the Device and Network Abuse policy. We found your app is using a non-compliant version of Huawei Mobile Services SDK which contains code to download or install applications from unknown sources outside of Google Play.Given the nature of the SDK, please remove it from the version of your app submitted to the Play Store.

from Google Play, which seems caused by outdated versions of Huawei SDK Libraries. Can you check e solve the problem upgrading used libraries in the projects.

For reference see this:
https://forums.developer.huawei.com/forumPortal/en/topic/0202931731760590092

and this:
https://forums.developer.huawei.com/forumPortal/en/topic/0202930818103450086

Many thanks.

Add Circle.remove()

Polygon shape has remove() method but Circle is missing it (in version 0.1.5). This should be added for full compatibility.

I have question in function SignInService

I develop function sign in google and huawei, In section google, I config require id token in cloud and when use in old function config with

 GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken([IdToken])
            .build()

But I can't set id token to library and when I look in library (GmsSignInService) I find that library doesn't have a set token part . Or is there any other way to set id token for google login?

at.bluesource.choicesdk.location.factory: Missing underlying GMS/HMS API.

Hi, guys I've got a problem with my App published in Huawei Gallery: Pixel 3 XL / Android 9

Unable to start activity ComponentInfo{co.nubee.android/co.nubee.android.MapsActivity}: java.lang.UnsupportedOperationException: Missing underlying GMS/HMS API.

at.bluesource.choicesdk.location.factory.FusedLocationProviderFactory$Companion.getFusedLocationProviderClient (FusedLocationProviderFactory.kt:67)
co.nubee.android.MapsActivity.onCreate (MapsActivity.kt:514)

// MapsActivity.kt: 
override fun onCreate(savedInstanceState: Bundle?) {
// Line 514
       client = FusedLocationProviderFactory.getFusedLocationProviderClient(this)
// ...
}

HMS or GMS priority selection

For testing in devices with both services availables (ex. P30 Pro), can be defined which services be loaded? I need to test the map example and haven't available a device HMS-only

Fatal Exception : com.huawei.hms.common.ApiException

Hi,

I have this crash on my FirebaseCrashlytics console, appearing only for a few Huawei devices (CDY-NX9A and PPA-LX2)

Fatal Exception: com.huawei.hms.common.ApiException
907135004: execute timeout

com.huawei.hms.aaid.constant.ErrorEnum.toApiException (ErrorEnum.java:1)
com.huawei.hms.opendevice.l.a (GetTokenTask.java:5)
com.huawei.hms.opendevice.l.doExecute (GetTokenTask.java:1)
com.huawei.hms.common.internal.TaskApiCall.onResponse (TaskApiCall.java:5)
com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager$1.onCallback (HuaweiApiManager.java:18)
com.huawei.hms.common.internal.HmsClient$BaseAdapterCallBack.doCallback (HmsClient.java:5)
com.huawei.hms.common.internal.HmsClient$BaseAdapterCallBack.onComplete (HmsClient.java:1)
com.huawei.hms.adapter.BaseAdapter$BaseRequestResultCallback.handleSolutionIntent (BaseAdapter.java:16)
com.huawei.hms.adapter.BaseAdapter$BaseRequestResultCallback.onResult (BaseAdapter.java:98)
com.huawei.hms.adapter.BaseAdapter$BaseRequestResultCallback.onResult (BaseAdapter.java:1)
com.huawei.hms.support.api.PendingResultImpl$d.b (PendingResultImpl.java:1)
com.huawei.hms.support.api.PendingResultImpl$d.handleMessage (PendingResultImpl.java:4)

I guess it is because you don't catch this exception when you try to get the Huawei Token, as it can throw an API exception :

override suspend fun requestToken(context: Context): String {
        val appId = getAppId(context)
        return HmsInstanceId.getInstance(context).getToken(appId, DEFAULT_TOKEN_SCOPE)
    }

Thanks for your help.

Add an empty constructor on MapFragment

When adding a fragment though xml

<fragment xmlns:android="http://schemas.android.com/apk/res/android" android:name="at.bluesource.choicesdk.maps.common.MapFragment" />

We receive the following error

This class should provide a default constructor (a public constructor with no arguments)

Can the empty constructor be added to the MapFragment class?

If not, is there any workaround for this?

Need to update HMS dependencies

I wasn't able to track down exactly what one, but some of the HMS dependencies i.e. com.huawei.hms:maps are throwing an error when targeting Android 12. 6.2.0.301 seems to be working for maps, but it could've been another dependency, too.

MapFragment should have an empty constructor

Version Choicesdk-maps 0.2

at.bluesource.choicesdk.maps.common.MapFragment should have an empty constructor, which is required by Android Fragment framework, else wise this could lead to crashes from onRestoreInstanceState etc.

I propose to add a JvmOverloads annotation to constructor like this: @JvmOverloads constructor(options: MapOptions? = null)

Initialising the Choice SDK

When I try to initiate the SDK (with ChoiceSdk.init(this)), it asks me to create a class called ChoiceSdk? How do I import the ChoiceSdk class into my app so I can call it?
Screenshot 2021-06-22 at 01 10 23

Function addTileOverlay(options: TileOverlayOptions) doesn't work with tile provider

Version Choicesdk-maps 0.2

I realise that the method does not work
addTileOverlay(TileOverlayOptions.create().tileProvider(customProviderImpl))

By deeper dive, I see in the function

override fun tileProvider(tileProvider: TileProvider?): TileOverlayOptions {
     tileProvider?.toGmsTileProvider()?.let { tileOverlayOptions.tileProvider(it) }
     return this
}

fun TileProvider.toGmsTileProvider(): com.google.android.gms.maps.model.TileProvider? {
            return when (this) {
                is GmsTileProvider -> {
                    this.getTileProvider()
                }
                else -> null
            }
        }

that it would just check if the implementation of TileProvider is instance of GmsTileProvider or HmsTileProvider. Library user would never have these instances of at.bluesource.choicesdk.maps.common.TileProvider.

Basically what happens at the moment is that null set to corresponding Mapkit and an error is thrown because no tileProvider has been set.

Unable to use IDE Layout Inspector when MapFragment is in play

Version Choicesdk-maps 0.2

I realised that as soon as the at.bluesource.choicesdk.maps.common.MapFragment is used, the layout inspector of Android Studio would cause app to crash. It makes the user impossible to inspect the layout hierarchy while using Choicemap library.

Just try to use the layout inspector in your demo MapActivity to reproduce the crash.

Fatal Exception: java.lang.IllegalArgumentException

I have this error on Android 12
Fatal Exception: java.lang.IllegalArgumentException
com.teamsystem.peopleapp.store: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.

android.app.PendingIntent.checkFlags (PendingIntent.java:382)
android.app.PendingIntent.getActivityAsUser (PendingIntent.java:465)
android.app.PendingIntent.getActivity (PendingIntent.java:451)
android.app.PendingIntent.getActivity (PendingIntent.java:415)
com.huawei.hms.api.b.getErrPendingIntent (HuaweiApiAvailabilityImpl.java:10)
com.huawei.hms.common.internal.BaseHmsClient.resolution (BaseHmsClient.java:3)
com.huawei.hms.common.internal.BaseHmsClient.checkAvailabilityAndConnect (BaseHmsClient.java:34)
com.huawei.hms.common.internal.BaseHmsClient.connect (BaseHmsClient.java:1)
com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.connect (HuaweiApiManager.java:21)
com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.sendRequest (HuaweiApiManager.java:22)
com.huawei.hms.common.internal.HuaweiApiManager.connectAndSendRequest (HuaweiApiManager.java:7)
com.huawei.hms.common.internal.HuaweiApiManager.handleMessage (HuaweiApiManager.java:7)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loopOnce (Looper.java:226)
android.os.Looper.loop (Looper.java:313)
android.os.HandlerThread.run (HandlerThread.java:67)

Graceful fallback of mapyType for Huawei

I was setting my mapType to Map.MAP_TYPE_HYBRID which was causing my map not to render on HMS devices. It'd be cool if it would gracefully fallback to supported types in the event that a mapType isn't supported on a device.

Avoid commonly used layout name

Version Choicesdk-maps 0.2

I realise that an internal layout named fragment_map is used. Generally it is bad practise if an library internal layout is named in a very common way. Library caller can easily have to same layout name and this would cause runtime conflict, where the library would use the layout of the consumer instead of it's own.

I recommend to add at least a prefix to avoid naming conflicts, like choice_fragment_map.
See also this SO post.

Notifications in closed app

On GMS push notifications are not delivered when the app isn't in execution. On HMS they arrive even when the app is not running. How is it possible to have the same behavior on GMS?

Exception "907135003: client api invalid" on Google device

Hi,
When starting my application on a standard Google Pixel 4a (Android 11), I always have this exception at startup.
I am using ChoiceSDK for Push management.
I have this exception even if doing nothing with ChoiceSDK. I mean even if I don't initialize it ...
I don't have this exception on Huawei device supporting HMS.

2021-06-17 11:38:54.879 31399-31399/com.chacon.dioone I/HMSSDK_PackageNameManager: CheckUpdateCallBack status is 3
2021-06-17 11:38:54.880 31399-31399/com.chacon.dioone I/HMSSDK_HuaweiApiAvailabilityImpl: Enter getResolveErrorPendingIntent, errorCode: 1 requestCode: 0
2021-06-17 11:38:54.881 31399-31399/com.chacon.dioone I/HMSSDK_HuaweiApiAvailabilityImpl: Enter getResolveErrorIntent, errorCode: 1
2021-06-17 11:38:54.884 31399-31399/com.chacon.dioone E/HMSSDK_SystemUtils: isSystemApp Exception: android.content.pm.PackageManager$NameNotFoundException: com.huawei.appmarket
2021-06-17 11:38:54.886 31399-31399/com.chacon.dioone I/HMSSDK_UpdateManager: app is: com.huawei.appmarket;status is:NOT_INSTALLED
2021-06-17 11:38:54.888 31399-31399/com.chacon.dioone I/HMSSDK_UpdateManager: In getAndroidMarketSetting, configuration not found for android channel market setting.
2021-06-17 11:38:54.889 31399-31399/com.chacon.dioone I/HMSSDK_UpdateManager: typeList is empty, no upgrade solution
2021-06-17 11:38:54.897 31399-31399/com.chacon.dioone I/HMSSDK_BaseHmsClient: notifyFailed result: 26
2021-06-17 11:38:54.898 31399-31399/com.chacon.dioone I/HMSSDK_HuaweiApiManager: onConnectionFailed
2021-06-17 11:38:54.900 31399-31460/com.chacon.dioone I/HMSSDK_Util: available exist: true
2021-06-17 11:38:54.903 31399-31460/com.chacon.dioone I/HMSSDK_Util: available exist: true
2021-06-17 11:38:54.905 31399-31460/com.chacon.dioone E/HMSSDK_HmsInstanceIdEx: TokenTask failed, ErrorCode: 907135003
2021-06-17 11:38:54.908 31399-31460/com.chacon.dioone E/HMSSDK_HMSPackageManager: Failed to find HMS apk
2021-06-17 11:38:54.909 31399-31471/com.chacon.dioone E/HMSSDK_HMSPackageManager: Failed to find HMS apk
2021-06-17 11:38:54.915 31399-31460/com.chacon.dioone I/HMSSDK_BaseHmsClient: Enter disconnect, Connection Status: 5
2021-06-17 11:38:54.917 31399-31471/com.chacon.dioone E/HMSSDK_AutoInit: Push init failed
    com.huawei.hms.common.ApiException: 907135003: client api invalid
        at com.huawei.hms.opendevice.a.a(ErrorEnum.java:272)
        at com.huawei.hms.opendevice.i.doExecute(GetTokenTask.java:58)
        at com.huawei.hms.opendevice.i.doExecute(GetTokenTask.java:34)
        at com.huawei.hms.common.internal.TaskApiCall.onResponse(TaskApiCall.java:5)
        at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.innerConnectionFailed(HuaweiApiManager.java:23)
        at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager.access$500(HuaweiApiManager.java:1)
        at com.huawei.hms.common.internal.HuaweiApiManager$ConnectionManager$2.run(HuaweiApiManager.java:1)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Thanks for your help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.