Skip to content

Commit

Permalink
sample updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxihai committed May 13, 2020
1 parent 90b4af9 commit e36cc87
Show file tree
Hide file tree
Showing 44 changed files with 2,668 additions and 583 deletions.
14 changes: 0 additions & 14 deletions Codelabs/AwarenessKit/.gitignore

This file was deleted.

48 changes: 22 additions & 26 deletions Codelabs/AwarenessKit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,46 @@

## Overview

```
The sample code shows how to use the Capture API and Barrier API of HUAWEI Awareness Kit for quick integration.
```

## Getting Started

1. Register as a developer.
Register a [HUAWEI account](https://developer.huawei.com/consumer/en/).
2. Create an app.
Create an app and enable APIs.
3. Build the demo.
To build this demo, please first import the demo to Android Studio (3.X or later). Then download the agconnect-services.json file of the app from AppGallery Connect, and add the file to the app directory (\app) of the demo. For details, please refer to [Preparations for Integrating HUAWEI HMS Core](https://developer.huawei.com/consumer/en/codelab/HMSPreparation/index.html)
For more development details, please refer to the following link:

Development Guide:https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/awareness-introduction

API References:https://developer.huawei.com/consumer/en/doc/development/HMS-References/awareness

We also provide an example to demonstrate the use of Awareness SDK for Android.

This sample uses the Gradle build system.

First download the demo by cloning this repository or downloading an archived snapshot.

In Android Studio, use the "Open an existing Android Studio project", and select the directory of "awareness-sample".

You should create an app in AppGallery Connect, and obtain the file of agconnect-services.json and add to the project. You should also generate a signing certificate fingerprint and add the certificate file to the project, and add configuration to build.gradle. See the [Configuring App Information in AppGallery Connect guide](https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/awareness-preparation) to configure app in AppGallery Connect.

## Running Environment

```
Android Studio and JDK 1.8 are used for coding.

To run the app generated by the sample code on a mobile phone, you need to use a mobile phone meeting the following requirements: the EMUI version is 9.1 or later or the Magic UI version is 2.1 or later; the chip version is Kirin 810, Kirin 980, Kirin 990, or later.
```

## Sample Code

```
The HUAWEI Awareness Kit sample code includes Capture and Barrier API sample code.

Capabilities called by the Capture API are as follows:
1. getTimeCategories(): The getTimeCategories() API requires the ACCESS_FINE_LOCATION permission. This API can be used to obtain the semantic information about the current time of the user location.
2. getHeadsetStatus(): The getHeadsetStatus() API is used to obtain the headset connection status.
Capture APIs can be called to obtain the time, headset, location, activity, ambient light, weather, bluetooth car stereo, and beacon status.
Capture APIs allow your app to request the status of a user. For example, the getHeadsetStatus() API can be used to obtain connection status of the headset.

Capabilities called by the Barrier API are as follows:
For details about Capture APIs, please visit https://developer.huawei.com/consumer/en/doc/development/HMS-References/awareness-captureclient.

1. HeadsetBarrier.connecting(): The HeadsetBarrier.connecting() API is used to create a headset barrier. When a headset is connected, the barrier status changes to true for about 5 seconds.
Barrier APIs can be called to implement awareness of the time, headset, location, activity, ambient light, Bluetooth car stereo, and beacon status.
Barrier APIs allow your app to set a series of awareness states. When a user enters a set state, Awareness Kit triggers the corresponding callback to notify the app. For example, the LocationBarrier.enter() API can be used to create a geo-fence.When the user enters the area specified by the geo-fence, Awareness Kit triggers the corresponding callback to notify the app.

2. BehaviorBarrier.keeping(): The BehaviorBarrier.keeping() API requires the activity recognition permission ACTIVITY_RECOGNITION. This API is used to create an activity recognition barrier. When a user is in a specified activity state, the barrier status changes to true.
3. AwarenessBarrier.and(): The AwarenessBarrier.and() API is used to combine multiple barriers and perform the AND logic operation on barrier status to obtain the status of the combination barrier.
```
For details about Barrier APIs, please visit https://developer.huawei.com/consumer/en/doc/development/HMS-References/awareness-barrier.

## License

```
HUAWEI Awareness Kit sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
```

HUAWEI Awareness Kit sample is licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
1 change: 0 additions & 1 deletion Codelabs/AwarenessKit/app/.gitignore

This file was deleted.

57 changes: 33 additions & 24 deletions Codelabs/AwarenessKit/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -90,35 +90,44 @@
</content>
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.0.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.0.2@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-ui:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-utils:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.0.1@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.coordinatorlayout:coordinatorlayout:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.1.0@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:1.1.3@jar" level="project" />
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:awareness:1.0.4.301@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat-resources:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.slidingpanelayout:slidingpanelayout:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.activity:activity:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.customview:customview:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.core:core:1.0.1@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.core:core:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.cursoradapter:cursoradapter:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.documentfile:documentfile:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.localbroadcastmanager:localbroadcastmanager:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.print:print:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:awareness-common:1.0.4.301@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.savedstate:savedstate:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata-core:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.interpolator:interpolator:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:1.1.3@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:base:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:availableupdate:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:ui:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:stats:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:device:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:log:4.0.3.301@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:network-grs:4.0.2.300@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:network-common:4.0.2.300@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.agconnect:agconnect-core:1.0.0.300@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hmf:tasks:1.3.3.300@aar" level="project" />
<orderEntry type="library" name="Gradle: com.huawei.hms:update:2.0.6.300@aar" level="project" />
</component>
</module>
21 changes: 11 additions & 10 deletions Codelabs/AwarenessKit/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.huawei.hmsawarenesssample"
applicationId "com.huawei.hms.awareness.codelab"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionCode 2
versionName "2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
storeFile file('xxx.xxx')
keyAlias 'xxx'
keyPassword 'xxx'
storePassword 'xxx'
storeFile file('xxxx.jks')
keyAlias 'xxxxxx'
keyPassword 'xxxxxxx'
storePassword 'xxxxxxx'
v1SigningEnabled true
v2SigningEnabled true
}
Expand All @@ -40,7 +40,8 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.huawei.hms:awareness:1.0.3.300'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.huawei.hms:awareness:1.0.4.301'
}
apply plugin: 'com.huawei.agconnect'
Empty file.
9 changes: 0 additions & 9 deletions Codelabs/AwarenessKit/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,3 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-ignorewarning
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
32 changes: 18 additions & 14 deletions Codelabs/AwarenessKit/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.hmsawarenesssample">
package="com.huawei.hms.awareness.codelab">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.huawei.hms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.huawei.hmsawarenesssample.awareness.BarrierActivity" />
<activity android:name="com.huawei.hmsawarenesssample.awareness.CaptureActivity" />
<activity android:name="com.huawei.hmsawarenesssample.MainActivity">
<activity android:name=".awareness.barrier.BarrierCombinationActivity" />
<activity android:name=".awareness.barrier.BluetoothBarrierActivity" />
<activity android:name=".awareness.barrier.BeaconBarrierActivity" />
<activity android:name=".awareness.barrier.AmbientLightBarrierActivity" />
<activity android:name=".awareness.barrier.TimeBarrierActivity" />
<activity android:name=".awareness.barrier.BehaviorBarrierActivity" />
<activity android:name=".awareness.barrier.LocationBarrierActivity" />
<activity android:name=".awareness.barrier.HeadsetBarrierActivity" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="com.huawei.hms.update.provider.UpdateProvider"
android:authorities="com.huawei.hmsawarenesssample.hms.update.provider"
android:exported="false"
android:grantUriPermissions="true" />
<activity android:name=".awareness.BarrierActivity" />
<activity android:name=".awareness.CaptureActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2020. Huawei Technologies Co., Ltd. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.huawei.hms.awareness.codelab;

import android.app.PendingIntent;

import com.huawei.hms.kit.awareness.barrier.AwarenessBarrier;

public class BarrierEntity {
private String barrierLabel;
private AwarenessBarrier barrier;
private PendingIntent pendingIntent;

public void setBarrierLabel(String barrierLabel) {
this.barrierLabel = barrierLabel;
}

public void setBarrier(AwarenessBarrier barrier) {
this.barrier = barrier;
}

public void setPendingIntent(PendingIntent pendingIntent) {
this.pendingIntent = pendingIntent;
}

public String getBarrierLabel() {
return barrierLabel;
}

public AwarenessBarrier getBarrier() {
return barrier;
}

public PendingIntent getPendingIntent() {
return pendingIntent;
}
}
Loading

0 comments on commit e36cc87

Please sign in to comment.