Giter Club home page Giter Club logo

beaconcontrol_android_sdk's Introduction

BeaconControl Android SDK

Integration Guide

BeaconControl Android SDK is an Android library providing APIs to manage beacon detection and react to beacon monitoring and ranging actions.

What does this library do?

The library allows the application to start and stop beacon detection. If beacon monitoring is enabled, the application may receive callback about starting and ending of actions. Actions have to be defined earlier by the user. There are three types of actions: url, coupon and custom. Url and coupon actions may be handled automatically by the library, however custom actions must be performed manually by the user.

Documentation

On the project website you will find JavaDoc documentation.

Adding library dependency

If you are using Gradle, include in your dependencies:

dependencies {
	...
    compile 'io.upnext.beaconcontrol:beaconcontrol:1.0.2'
    ...
}

You may also need to add one or more exclusions, as shown below:

android {
	...
    packagingOptions {
      	exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
    ...
 }

Quick Start

At the beginning you have to get the BeaconControl class instance to interact with BeaconControl SDK.

BeaconControl beaconControl = BeaconControl.getInstance(context, clientId, clientSecret, userId);

You may enable logging.

beaconControl.enableLogging(true);

The next step is defining and setting the BeaconDelegate object. If you decide to perform an action automatically, there will be a WebView activity shown for url and coupon actions.

beaconControl.setBeaconDelegate(new BeaconDelegate() {
    @Override
    public boolean shouldPerformActionAutomatically() {
        return true;
    }

    @Override
    public void onActionStart(Action action) {
        // you may do something when action starts
    }

    @Override
    public void onActionEnd(Action action) {
        // you may do something when action ends
    }

    @Override
    public void onBeaconsConfigurationLoaded(List<Beacon> list) {
        // you can save the beacons from the configuration for future use
    }

    @Override
    public void onBeaconProximityChanged(Beacon beacon) {
        // you may do something when beacon proximity changes
    }
});

However, you should handle custom action by your own. Here is an example:

@Override
public void onActionStart(Action action) {
    long actionId = action.id;
    String actionName = action.name;

    switch (action.type) {
        case url:
            onUrlActionStart(actionId, actionName, action.payload);
            break;
        case coupon:
            // do something for coupon action
            break;
        case custom:
            onCustomActionStart(actionId, actionName, action.customAttributes);
            break;
        default:
      		throw new IllegalStateException("Unknown action type.");
 	}
}

private void onUrlActionStart(long actionId, String actionName, Action.Payload payload) {
	if (payload != null) {
		String url = payload.url;
		// you may do something for url action
	}
	...
}

private void onCustomActionStart(long actionId, String actionName, List<Action.CustomAttribute> customAttributes) {
	for (Action.CustomAttribute customAttribute : customAttributes) {
		long attributeId = customAttribute.id;
		String attributeName = customAttribute.name;
		String attributeValue = customAttribute.value;

		// you may do something for custom attribute
	}
	...
}

If you want, you may set callback for errors. Then every time an error occurs, you will be notified.

beaconControl.setBeaconErrorListener(new BeaconErrorListener() {
	@Override
	public void onError(ErrorCode errorCode) {
		Log.e(TAG, "Some error occured in Beacon SDK: " + errorCode.name());
	}
});

BeaconSDK configuring is done now. When needed, you may start beacon monitoring and ranging.

beaconControl.startScan();

When the scanning is started you can request at any given time a reload of configuration - it will be fetched from the backend server. If the fetch was successful, you'll be notified in onBeaconsConfigurationLoaded of BeaconDelegate interface.

beaconControl.reloadConfiguration();

When you do not need monitoring and ranging, you may stop beacon detection.

beaconControl.stopScan();

Advanced configuration

If you want to communicate with your private instance of BeaconControl backend server, you need to overwrite the url by providing it in your application's strings.xml file:

<string name="sdk_config__service_base_url">http://your.server.com/api/v1/</string>

License

You can find license in LICENSE.txt file.

If you have any troubles, please contact us at [email protected].

beaconcontrol_android_sdk's People

Contributors

danielnow avatar roman-upnext avatar

Stargazers

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

Watchers

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

beaconcontrol_android_sdk's Issues

"Cannot add client, conf is null" error

Getting "Cannot add client, conf is null" error after startScan.

I am using the client_id and secret_id from the platforma, and the email I registered with as user_id.

Logs:

D/BeaconParser: Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
D/BeaconSDKBeaconService: Start scan.
D/BeaconSDK
BeaconService: Cannot add client, conf is null.
D/BeaconSDKBeaconService: onBeaconServiceConnect
D/BeaconSDK
BeaconControlManagerImpl: Error in getToken task.
W/BeaconSDKBeaconControlManagerImpl: Token has not been retrieved.
D/BeaconSDK
HttpCallMediator: IO_ERROR
D/BeaconSDK~BeaconServiceHelper: Error in getConfigurations task, IO_ERROR

IO_ERROR

E/TAG: ERROR : IO_ERROR name: IO_ERROR

appears also cant change sdk_config__service_base_url variable at values folder. Im working at Android studio. Can you please tell me how can I replace this field with my own server url?

Getting null object reference after compile

Hi there!
I download the android sdk to change the sdk_config_service_base_url for our server and created a new .aar.

Unfortunately, when I use the library in the project, i get the error while executing the app:

Attempt to read from field 'java.lang.String com.upnext.beaconos.sdk.backend.model.TokenResponse.accessToken' on a null object reference

Here the Android Studio log:

FATAL EXCEPTION: OkHttp Dispatcher
Process: com.cirici.androidbase, PID: 7886
java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.upnext.beaconos.sdk.backend.model.TokenResponse.accessToken' on a null object reference
at com.upnext.beaconos.sdk.backend.storage.SdkTokenStorage.storeToken(SdkTokenStorage.java:33)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.storeToken(BeaconControlManagerImpl.java:146)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.storeTokenAndGetTokenResponse(BeaconControlManagerImpl.java:150)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.checkErrorAndGetTokenResponse(BeaconControlManagerImpl.java:156)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.access$300(BeaconControlManagerImpl.java:39)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl$BeaconControlInterceptor.intercept(BeaconControlManagerImpl.java:112)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:221)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
at com.squareup.okhttp.Call.access$100(Call.java:34)
at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162)
at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

Thank you in advance!

Retrofit 1.9 support

Currently this SDK does not support Retrofit 1.9 as its using 2.0.0 beta 1.

Can we create a backwards compatible branch?

Page not found: port gets deleted.

Hi there, I had the same problem as #9 but im trying to work on my own network.. written to config file IP:PORT on coupon url but when the actions gets fired.. only the IP comes on the payload, event trying to modify it on debug deletes it.

Getting JacksonConverterFactory error

Getting java.lang.IncompatibleClassChangeError: com.upnext.beaconos.sdk.backend.JacksonConverterFactory when BeaconSDK.getInstance().

Logs:

05-02 17:10:32.761 I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<com.upnext.beaconos.sdk.backend.JacksonConverterFactory>
05-02 17:10:32.761 I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<com.upnext.beaconos.sdk.backend.JacksonConverterFactory>
05-02 17:10:32.785 I/art﹕ Rejecting re-init on previously-failed class java.lang.Class<com.upnext.beaconos.sdk.backend.JacksonConverterFactory>
05-02 17:10:32.785 D/AndroidRuntime﹕ Shutting down VM
--------- beginning of crash
05-02 17:10:32.802 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.cirici.androidbase, PID: 3875
java.lang.IncompatibleClassChangeError: com.upnext.beaconos.sdk.backend.JacksonConverterFactory
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.getRetrofitInstance(BeaconControlManagerImpl.java:93)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.(BeaconControlManagerImpl.java:68)
at com.upnext.beaconos.sdk.backend.BeaconControlManagerImpl.getInstance(BeaconControlManagerImpl.java:49)
at com.upnext.beaconos.sdk.BeaconSDK.getBeaconSDKInstance(BeaconSDK.java:80)
at com.upnext.beaconos.sdk.BeaconSDK.getInstance(BeaconSDK.java:70)
at com.cirici.beacons.MainActivity.onCreate(MainActivity.java:182)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

IO ERROR in getConfigurations task

Getting below error in test android app. I have verified that the client id and secret are valid

D/BeaconSDK~: IO_ERROR
D/BeaconSDK~BeaconServiceHelper: Error in getConfigurations task, IO_ERROR
E/Main Activity: Some error occurred in Beacon SDK: IO_ERROR

I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@f3386e7 time:48553005
D/BeaconSDK~HttpCallMediator: IO_ERROR
D/BeaconSDK~BeaconServiceHelper: Error in getConfigurations task, IO_ERROR
E/Main Activity: Some error occurred in Beacon SDK: IO_ERROR

D/BeaconSDK~HttpCallMediator: IO_ERROR
D/BeaconSDK~BeaconServiceHelper: Error in getConfigurations task, IO_ERROR
E/Main Activity: Some error occurred in Beacon SDK: IO_ERROR

I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@f3386e7 time:48574751
D/BeaconSDK~HttpCallMediator: IO_ERROR
D/BeaconSDK~BeaconServiceHelper: Error in getConfigurations task, IO_ERROR
E/Main Activity: Some error occurred in Beacon SDK: IO_ERROR
D/ViewRootImpl: #1 mView = android.widget.LinearLayout{1d2ea0a V.E.

Incorrect constant lint check

Running lint checks on an app that uses the SDK yields the following error:

Must be one or more of: PackageManager.GET_META_DATA, PackageManager.GET_RESOLVED_FILTER, PackageManager.GET_SHARED_LIBRARY_FILES, PackageManager.MATCH_ALL, PackageManager.MATCH_DISABLED_COMPONENTS, PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS, PackageManager.MATCH_DEFAULT_ONLY, PackageManager.MATCH_DIRECT_BOOT_AWARE, PackageManager.MATCH_DIRECT_BOOT_UNAWARE, PackageManager.MATCH_SYSTEM_ONLY, PackageManager.MATCH_UNINSTALLED_PACKAGES, PackageManager.GET_DISABLED_COMPONENTS, PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, PackageManager.GET_UNINSTALLED_PACKAGES

This happens in ApplicationUtils.java#L52:

49       return cn;
50   }
51 
52   List<ResolveInfo> infos = context.getPackageManager().queryIntentServices(i, Context.BIND_AUTO_CREATE);
53 
54   if (infos.isEmpty()) return null;

The Context.BIND_AUTO_CREATE is the constant lint is complaining about.

I'm guessing the desired constant is PackageManager.COMPONENT_ENABLED_STATE_DEFAULT since it has the same constant value as Context.BIND_AUTO_CREATE (0).

To set custom URL in the project

I am struggling to know how do we set our own server URL in the Android SDK, there is no clear instruction on how to do so in the integration guide. Here is the part of my logcat, any help would be great!

D/BeaconSDKBeaconService: Start scan.
D/BeaconSDK
BeaconService: Cannot add client, conf is null.
E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.apps.echnotech.beaconcontrolandroid, PID: 21542 java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.upnext.beaconos.sdk.backend.model.TokenResponse.accessToken' on a null object reference at com.upnext.beaconos.sdk.backend.storage.SdkTokenStorage.storeToken(SdkTokenStorage.java:33)

Getting styles error while build

Hi again,
I updated the .aar file, but now I am getting an error while building the application:

AGPBI: {"kind":"error","text":"Error retrieving parent for item: No resource found that matches the given name \u0027Theme.AppCompat.Light.DarkActionBar\u0027.","sources":[{"file":"/Users/lrivera/Documents/Projectes_Android/BeaconControl/app/src/main/res/values/styles.xml","position":{"startLine":1}}],"original":""}
AGPBI: {"kind":"error","text":"No resource found that matches the given name: attr \u0027colorAccent\u0027.","sources":[{"file":"/Users/lrivera/Documents/Projectes_Android/BeaconControl/app/src/main/res/values/styles.xml","position":{"startLine":7,"startColumn":20,"startOffset":317,"endColumn":31,"endOffset":328}}],"original":""}
AGPBI: {"kind":"error","text":"No resource found that matches the given name: attr \u0027colorPrimary\u0027.","sources":[{"file":"/Users/lrivera/Documents/Projectes_Android/BeaconControl/app/src/main/res/values/styles.xml","position":{"startLine":5,"startColumn":20,"startOffset":187,"endColumn":32,"endOffset":199}}],"original":""}
AGPBI: {"kind":"error","text":"No resource found that matches the given name: attr \u0027colorPrimaryDark\u0027.","sources":[{"file":"/Users/lrivera/Documents/Projectes_Android/BeaconControl/app/src/main/res/values/styles.xml","position":{"startLine":6,"startColumn":20,"startOffset":248,"endColumn":36,"endOffset":264}}],"original":""}

Has something to do with the compile sdk?

Thank you in advance.

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.