[Q] want to increase volume in [4.4.2] DN3 (Ditto Note 3) V5 60 or 63db - Galaxy Note II Themes and Apps

is there anyway to Increase Volume in [4.4.2] DN3 (Ditto Note 3) V5 60 or 63db

Hurricane sound boost tool is the best of the universe. Flash v2 and choose the level 60 or 63
http://forum.xda-developers.com/showthread.php?t=2634647
Regards.
Sent from my GT-N7100 using XDA Premium 4 mobile app

q
:good:

Just download es file manager.. give it root privileges and open the following..
System/etc and find file default_gain.conf
Modifier "Normal" {
SupportedDevice {
"Speaker"
}
Enable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 3 },
{ "Speaker Boost Volume", 4 },
{ "Speaker Volume", XX},
}
Disable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 0 },
{ "Speaker Volume", XX },
{ "Speaker Boost Volume", 0 },
}
}
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", XX },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", XX },
}
}
Just change the values in the 'XX' to 60 but not more than 65.
U r done my friend
Modifier "Normal" {
SupportedDevice {
"Headphone"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", XX },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", XX },
}
Sent from my GT-N7100 using Tapatalk

Bhupen Gaitonde said:
Just download es file manager.. give it root privileges and open the following..
System/etc and find file default_gain.conf
Modifier "Normal" {
SupportedDevice {
"Speaker"
}
Enable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 3 },
{ "Speaker Boost Volume", 4 },
{ "Speaker Volume", XX},
}
Disable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 0 },
{ "Speaker Volume", XX },
{ "Speaker Boost Volume", 0 },
}
}
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", XX },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", XX },
}
}
Just change the values in the 'XX' to 60 but not more than 65.
U r done my friend
Modifier "Normal" {
SupportedDevice {
"Headphone"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", XX },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", XX },
}
Sent from my GT-N7100 using Tapatalk
Click to expand...
Click to collapse
Please don't mind mate.
These methods are so complicated for noobs and a hassle also for everyone.
Why should one do these much things while a simple recovery flashable zip with options like 58db/60db/63db in aroma is available!!
Regards.
Sent from my GT-N7100 using XDA Premium 4 mobile app

I know friend..
But this is the easiest way.
It's very easy. I am also a noob compared to all of u. But still I find it very easy by this method.
Sent from my GT-N7100 using Tapatalk

Bhupen Gaitonde said:
I know friend..
But this is the easiest way.
It's very easy. I am also a noob compared to all of u. But still I find it very easy by this method.
Sent from my GT-N7100 using Tapatalk
Click to expand...
Click to collapse
You mean editing system file is easier than flash a zip?☺
Sent from my GT-N7100 using XDA Premium 4 mobile app

At least for this case it's easy. Because it works.
U just have to change the values as per ur requirement. Keeping in mind the potential of ur handset Speaker and Headset.
Sent from my GT-N7100 using Tapatalk

Bhupen Gaitonde said:
At least for this case it's easy. Because it works.
U just have to change the values as per ur requirement. Keeping in mind the potential of ur handset Speaker and Headset.
Sent from my GT-N7100 using Tapatalk
Click to expand...
Click to collapse
Maybe mate, but universal truth is every user prefers cwm flashable zips and if it has aroma to choose, then it feels like 'finally I got what I want'. The sound boost mod of @wesamothman got four options, stock medium high and extreme, so, one can choose his desired boost, if he feels it is not good, simply flash the zip again and choose another mod, no need to edit system files. Suppose I am a noob, I don't know anything, just got a rooted device, in this case which questions will arise?
#which file explorer should I use?
#how to open that file?
#how to edit that file?
#how to save the edited file?
#should I keep the original one? Or just edit the existing one?
#what to do if I want my stock sound back?
#i want more sound, not happy
#..........
Regards.
Sent from my GT-N7100 using XDA Premium 4 mobile app

Wow.. good answer.
Appreciate it. But I still feel that the option I mentioned is better than flash.
U just think..
Sent from my GT-N7100 using Tapatalk

Bhupen Gaitonde said:
Wow.. good answer.
Appreciate it. But I still feel that the option I mentioned is better than flash.
U just think..
Sent from my GT-N7100 using Tapatalk
Click to expand...
Click to collapse
Lol...thinking about it is just wastage of time for me mate. Users will choose the easier way.
Regards.
Sent from my GT-N7100 using XDA Premium 4 mobile app

Then go ahead..
Regards to u too..
Sent from my GT-N7100 using Tapatalk

i also have a thread.. files can be taken from there..
i am a noob but have done a decent job..

geekynoob said:
i also have a thread.. files can be taken from there..
i am a noob but have done a decent job..
Click to expand...
Click to collapse
Lol mate...I used your file for a long long time. It's really noob friendly.
Regards.
Sent from my GT-N7100 using XDA Premium 4 mobile app

Related

[HOT AUDIO MOD]♫♫♫ Increase Note2 volume significantly ♫♫♫

[HOT AUDIO MOD]♫♫♫ Increase Note2 volume significantly ♫♫♫
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
WORKS FOR ODEXED/DEOXED ROMS, all you need just root
and default_gain.conf file /system/etc
•••ORIGINAL default_gain.conf file if you have forgot to backup•••
https://www.box.com/s/zk7uccelynr8v3i4tipt
INSTALLATION:
Video how to install this mod, big credits to ashwin123
FIRST METHOD:
1.Download this file:
ULTRA VOLUME MOD
MID VOLUME MOD (58DB WHILE ULTRA HAS 60DB)
NORMAL VOLUME MOD( A BIT LOUDER THAN DEFAULT (55DB)
2.Make backup default_gain.conf file which you can find at /system/etc
3.With root explorer overwrite downloaded default_gain.conf and if it will be successfully overwritten, reboot device. Dont forget to give permissions RW- RW- RW-
If you wont be able to overwrite that file, reboot device and try again to overwrite.
Attached file (default_gain.conf) was modified and was increased volume of:
ringtones
in call
speaker
headphones
Within 60dB!!!!! Be careful, listening to music so loud!!!!
SECOND METHOD (edit manually default_gain.conf if you want only boost volume of headphones and etc):
1.With root explorer (personally i use es file explorer) copy your default_gain.conf file to sd card or external.
2.Open that file and find this:
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", 57 },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", 57 },
}
}
Modifier "Normal" {
SupportedDevice {
"Headphone"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", 57 },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", 52 },
}
}
By default DB of volume is 50, i have increased it to 57 and so far everything is fine.
Be carefully with increasing those values too much. 57 seems to be really loud listening music via headphones.
So after you change values in that file, save changes and then copy it to /system/etc and dont forget to give permissions!!!!
BE CAREFUL, I'M NOT RESPONSIBLE FOR YOUR ACTIONS!
Don' forget, for this mod you need root!!!
Thanks!
Sent from my GT-N7100 using Tapatalk 2
Reb0rn said:
Thanks!
Sent from my GT-N7100 using Tapatalk 2
Click to expand...
Click to collapse
worked for you? ;D so far no feedbacks lol
Yeah I saw that no one actually wrote anything... so I thought this awesome mod needed a bump
Sent from my GT-N7100 using Tapatalk 2
Reb0rn said:
Yeah I saw that no one actually wrote anything... so I thought this awesome mod needed a bump
Sent from my GT-N7100 using Tapatalk 2
Click to expand...
Click to collapse
thanks, btw i have increased to 59, no problems ;D i think siyah kernel for s3 used this method to increase headphones audio boosting ;D
EdgaBimbam said:
thanks, btw i have increased to 59, no problems ;D i think siyah kernel for s3 used this method to increase headphones audio boosting ;D
Click to expand...
Click to collapse
i increased to 57 and i definitely felt the diffrence,only thing bothers me is bass boost,previosly i have galaxy s1 and dsp manager does the trick but now i am not enjoying listening music on note 2,i tried to mess around with equilizer also but no luck with that.
gaurav2009 said:
i increased to 57 and i definitely felt the diffrence,only thing bothers me is bass boost,previosly i have galaxy s1 and dsp manager does the trick but now i am not enjoying listening music on note 2,i tried to mess around with equilizer also but no luck with that.
Click to expand...
Click to collapse
yeh same here, s3 with siyah kernel was so good at audio quality, bass was amazing. Maybe later will be more audio mods for note 2, i will try to ask gokhanmoral is it possible to implent his eargasm on note 2 stock kernel ;D
MBB_Gnex_v2_d3h.zip
Worked for me...
Google it.
Sent from my GT-N7100 using Tapatalk 2
hmmm got reply from gokhanmoral and he said that when he will have time, he will try to implent mdnie display tweak and audio tweak ;D
greaaaaat thank please help how can i increas IN CALL VOLUME:crying::crying::crying:
http://forum.xda-developers.com/showthread.php?t=1922715
Sent from my GT-N7100 using Tapatalk 2
Will this work on note 1
srinivas07 said:
Will this work on note 1
Click to expand...
Click to collapse
you could try, if you find these values, make copy of your old default_gain.conf and try to replace with modified. BUT MODIFY MANUALLY, DONT TRY TO REPLACE WITH DOWNLOADED FROM HERE!!!!!
navydata said:
greaaaaat thank please help how can i increas IN CALL VOLUME:crying::crying::crying:
Click to expand...
Click to collapse
you could try to edit this in your default_gain.cof
#Modifier : Incall
Modifier "Incall" {
SupportedDevice {
"Earpiece"
}
Enable {
{ "AIF2DAC2L Mixer AIF2 Switch", 0 },
{ "AIF2DAC2R Mixer AIF2 Switch", 0 },
{ "AIF2ADC HPF Mode", 1 },
{ "AIF2ADC HPF Switch", 1 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF2DAC Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "AIF2 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Output Volume", 57 },
{ "Earpiece Volume", 1 },
}
Disable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF2DAC Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "AIF2 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Output Volume", 61 },
{ "Earpiece Volume", 1 },
}
}
try to increase to 59 or 60.
#Modifier : Incall
Modifier "Incall" {
SupportedDevice {
"Earpiece"
}
Enable {
{ "AIF2DAC2L Mixer AIF2 Switch", 0 },
{ "AIF2DAC2R Mixer AIF2 Switch", 0 },
{ "AIF2ADC HPF Mode", 1 },
{ "AIF2ADC HPF Switch", 1 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF2DAC Volume", 96 },
{ "AIF1 Boost Volume", 55 },
{ "AIF2 Boost Volume", 55 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Output Volume", 63 },
{ "Earpiece Volume", 1 },
}
Disable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF2DAC Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "AIF2 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Output Volume", 61 },
{ "Earpiece Volume", 60 },
i make this and it working GREAAAAAAAAAAAAAAAAAAAAAAAT THANKS MATE u save my live
Raised level to 59 and working perfectly. Sweeet.
gaurav2009 said:
i increased to 57 and i definitely felt the diffrence,only thing bothers me is bass boost,previosly i have galaxy s1 and dsp manager does the trick but now i am not enjoying listening music on note 2,i tried to mess around with equilizer also but no luck with that.
Click to expand...
Click to collapse
I don't know for you, but with Beats audio Monster in-ear headphones (the cheapest ones which were given with the HTC Sensation XE), I have very good sound without this mod (not tried yet) with bass boost and even better with the Custom equalizer, not even extended. I'm on Vein droid Rom, which is amazing by the way.
f.
Sent from my GT-N7100 using Tapatalk
I have installed this https://play.google.com/store/apps/details?id=com.motioncoding.beats and now sound quality is better, especially bass
Bit stuck on whether to do this or not?
I really really really HATE the low output I have in my car and have been re-directed from this thread I created: http://forum.xda-developers.com/showthread.php?p=33160556
I'm a bit worried about bricking my new device if I root it... Please can someone answer these questions for me as I am new to Android..
1 - If I root my device, JUST root it (not install a custom ROM or anything like that), will I still get the standard OTA updates for the next versions of Android?
2 - If I root my device JUST to change this stupid decibel thing, will it revert back to the standard 50db when I get a new update and it unroots my device?
3 - Is my warranty still void if I root my device? I've read about "flash counter" or something but I havent a clue what it means.
4 - If the rooting fails for some reason, is it easy enough to fix?
Thanks in advance. I'm pretty clueless to all this as you can see!!
Seriously your on the wrong forum buddy @srinivas

[Q] Stop accelerometer listener after fixed amount of time

I like to start a listener; e.g. accelerometer sensor and have it stop after like 20 seconds or so. How can I force it to stop after criteria is reached (e.g 20 seconds is passed)
Here is the base code of what I have:
public class SensorActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//...
//...
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
}
@override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event) {
float[] values = event.values.clone();
float x = values[0];
float y = values[1];
float z = values[2];
//...
}
@override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@override
protected void onResume() {
super.onResume();
// register this class as a listener for the accelerometer sensor
sensorManager.registerListener(this,
sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}
@override
protected void onPause() {
// unregister listener
super.onPause();
sensorManager.unregisterListener(this);
}
}
All help is appreciated.
Thanks

[MOD] [MM] increase audio for headphones

Hi all I just bought a Note 4, immediately updated to Marshmallow, and I noticed the headphones volume was really lower than in my Note 2. I gave a look in Xda but didn't find any mod to increase audio level, so this is my solution. Of course you need root access..
Go in /Etc folder, copy default_gain.conf file to another directory and open it (I used Es note editor, which is bundled with Es file explorer).
Find the following lines:
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Noise Gate Switch", 0 },
{ "HPOUT1L Impedance Volume", 113 },
{ "HPOUT1R Impedance Volume", 113 },
{ "HPOUT1L Input 1 Volume", 32 },
{ "HPOUT1R Input 1 Volume", 32 },
}
}
Modifier "Normal" {
SupportedDevice {
"Headphone"
}
Enable {
{ "Noise Gate Switch", 0 },
{ "HPOUT1L Impedance Volume", 113 },
{ "HPOUT1R Impedance Volume", 113 },
{ "HPOUT1L Input 1 Volume", 32 },
{ "HPOUT1R Input 1 Volume", 32 },.
All you have to do is to change the value in the strings
{ "HPOUT1L Input 1 Volume", SET THE VALUE YOU LIKE },
{ "HPOUT1R Input 1 Volume", SET THE VALUE YOU LIKE }
I changed it into 48 and it's enough for me, so my lines are as follows
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Noise Gate Switch", 0 },
{ "HPOUT1L Impedance Volume", 113 },
{ "HPOUT1R Impedance Volume", 113 },
{ "HPOUT1L Input 1 Volume", 48 },
{ "HPOUT1R Input 1 Volume", 48 },
}
}
Modifier "Normal" {
SupportedDevice {
"Headphone"
}
Enable {
{ "Noise Gate Switch", 0 },
{ "HPOUT1L Impedance Volume", 113 },
{ "HPOUT1R Impedance Volume", 113 },
{ "HPOUT1L Input 1 Volume", 48 },
{ "HPOUT1R Input 1 Volume", 48 },
Now you have just to backup your original file, then copy the edited one in /Etc folder, set permissions to rw-r--r-- (I use root browser which is free) and reboot.
You headphones audio is much higher now
Link to my .conf file:
https://www.androidfilehost.com/?fid=24533103863138198
Hye you should share your own .conf file.
Sent from my SM-N910C using XDA-Developers mobile app
File added. Anyway maybe the mod adds a little bit of digital noise, even if I'm not sure about it. Please report your opinions.
Will it work if i am already having high loud sound..i want to make my phone sound normal
you perfect op! thank you.
gabripranzo said:
File added. Anyway maybe the mod adds a little bit of digital noise, even if I'm not sure about it. Please report your opinions.
Click to expand...
Click to collapse
because to me m8 works perfect your file thanks!!!
hmm... damn. sounds fantastic but won't work for my bluetooth headphones ... any recommendation where to change those values? thanks in advance!
edit: got it after reboot it was neccessary to decrease and increase the volume at the headphones. now the maximum is quite enough thanks mate.
Finally Found This!!! Thanks Alot @gabripranzo , i tried something different i've read somewhere the first row that contains "Headphone" & The 1st row that contains "Headset Out" in it i changed the value there of both (Left & Right) 113 to 125 & It works perfectly without any music stops! This Works better IMO. than the bottom lines that has 32 bec. When i changed the values there to 44 music always stopped at max volume.
MTranceAvB said:
Finally Found This!!! Thanks Alot @gabripranzo , i tried something different i've read somewhere the first row that contains "Headphone" & The 1st row that contains "Headset Out" in it i changed the value there of both (Left & Right) 113 to 125 & It works perfectly without any music stops! This Works better IMO. than the bottom lines that has 32 bec. When i changed the values there to 44 music always stopped at max volume.
Click to expand...
Click to collapse
I'm glad you found the right solution for you. I think music stops when you overcharge the amplifier, I experienced the same thing with my Note 8.0 tablet with Boeffla kernel: it allows to tweak the volume, but if it's set too high (I did it because I have high impedance headphones) music stops, probably to avoid damages.
In the end I bought a USB DAC/amp to connect to my Note 4 and I'm very happy with it

‘GymOut’- An Awareness Kit Application designed For Work Out.

This article is originally from HUAWEI Developer Foum
Forum link: https://forums.developer.huawei.com/forumPortal/en/home​
About GymOut:
GymOut is a simple work out App which uses some of the features of HMS awareness Kit. In this, we have to set Gym location (here it is taking current location) and work out time. Once we enter into Gym it prompts us to plug in the head set to listen the work out music. The music will stop playing after the completion of work out /on leaving the gym.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
An Introduction for Awareness Kit:
HUAWEI Awareness Kit provides your app with the ability to obtain contextual information including users' current time, location, behavior, audio device status, ambient light, weather, and nearby beacons. Through this features the app can gain insight into a user's current situation more efficiently, making it possible to deliver a smarter, more considerate user experience
· Capture API
The Capture API allows the app to request the current user status, such as time, location, behaviour, and whether a headset is connected. For example, it can request location for getting latitude and longitude.
· BarrierAPI
The Barrier API allows the app to set a combination of contextual conditions. When the preset contextual conditions are met, the app will receive a notification. We can even accommodate our app with different combinations of contextual conditions to support different use cases. For example, we will get notification once we enter into a specified location.
Software Requirements
Android Studio
Java JDK 1.8 or later
Huawei Mobile Services (APK) 4.0.0.300 or later
Integration
1. Create a project in android studio and Huawei AGC.
2. Provide the SHA-256 Key in App Information Section.
3. Provide storage location. (Selected Singapore here)
4. Download the agconnect-services.json from AGCand save into app directory.
5. In root build.gradle
Go to allprojects->repositories and buildscript->repositories and the given line.
Code:
maven { url 'http://developer.huawei.com/repo/' }
In dependency add class path
Code:
classpath 'com.huawei.agconnect:agcp:1.2.1.301'
6. In app build.gradle
We have to add signingConfigs and buildTypes, otherwise we have to create signed apk for awareness testing.
Code:
signingConfigs {
release {
storeFile file('store.jks')
keyAlias 'mykey'
keyPassword 'hmsapp'
storePassword 'hmsapp'
v1SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.release
debuggable true
}
}
Add Implementation
Code:
implementation 'com.huawei.hms:awareness:1.0.4.301'
Apply plugin
Code:
apply plugin: 'com.huawei.agconnect'
7. The app need the following permissions
Code:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_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.ACCESS_BACKGROUND_LOCATION" />
Code Implementation:
In this application we are using the following HMS Features:
Capture API
Location Capture: For getting gym Latitude and Longitude.
Barrier API
Location Barrier: To get notification when entering into Gym and exit from Gym .
Headset Barrier:To get alert to connect Head set for workout music
Time Barrier: To alert, once the time elapses the specified workout time.
To capture Location API using getLocation () function
Code:
private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
latitude=location.getLatitude();
longitude=location.getLongitude();
Toast.makeText(getApplicationContext(),"Longitude:" + longitude
+ ",Latitude:" + latitude,Toast.LENGTH_SHORT).show();
mLogView.printLog("Longitude:" + longitude
+ ",Latitude:" + latitude);
mp = MediaPlayer.create(getApplicationContext(), R.raw.audio);
mp.setLooping(true);
alert_stayTimeDialog();
//add_locationBarrier_enter
AwarenessBarrier enterBarrier = LocationBarrier.enter(latitude, longitude, radius);
Utils.addBarrier(getApplicationContext(), ENTER_BARRIER_LABEL, enterBarrier, mPendingIntent);
AwarenessBarrier exitBarrier = LocationBarrier.exit(latitude, longitude, radius);
Utils.addBarrier(getApplicationContext(), EXIT_BARRIER_LABEL, exitBarrier, mPendingIntent);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(),"Failed to get the location.",Toast.LENGTH_SHORT).show();
mLogView.printLog("Failed to get the location.");
Log.e(TAG, "Failed to get the location.", e);
}
});
mScrollView.postDelayed(()-> mScrollView.smoothScrollTo(0,mScrollView.getBottom()),200);
}
Using GymBarrierReceiver to receive the broadcast sent by Awareness Kit when the barrier status changes.
Code:
final class GymBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
int barrierPresentStatus = barrierStatus.getPresentStatus();
switch (label) {
case ENTER_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("You are in Gym");
alert_startWorkOutDialog();
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
// mLogView.printLog("You are away from Gym");
} else {
mLogView.printLog("The location status is unknown.");
}
break;
case STAY_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("You have to spent "
+ workOutTime + " minutes in Gym");
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
mLogView.printLog("Your time of duration in Gym is Over.");
} else {
mLogView.printLog("The location status is unknown.");
}
break;
case EXIT_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("You are exiting Gym");
mp.pause();
play_pause.setBackground(getDrawable(android.R.drawable.ic_media_play));
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
// mLogView.printLog("You are in Gym");
} else {
mLogView.printLog("The location status is unknown.");
}
break;
case KEEPING_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("Audio is playing...");
play_pause.setVisibility(View.VISIBLE);
mp.start();
play_pause.setBackground(getDrawable(android.R.drawable.ic_media_pause));
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
mLogView.printLog("Connect headset to play audio");
mp.pause();
play_pause.setBackground(getDrawable(android.R.drawable.ic_media_play));
} else {
mLogView.printLog("The headset status is unknown.");
}
break;
case CONNECTING_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("The headset is connecting. Audio is playing");
play_pause.setVisibility(View.VISIBLE);
mp.start();
play_pause.setBackground(getDrawable(android.R.drawable.ic_media_pause));
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
} else {
mLogView.printLog("The headset status is unknown.");
}
break;
case DURING_TIME_PERIOD_BARRIER_LABEL:
if (barrierPresentStatus == BarrierStatus.TRUE) {
mLogView.printLog("Your Work out is "+workOutTime+" minutes.");
} else if (barrierPresentStatus == BarrierStatus.FALSE) {
mLogView.printLog("Work out time reached "+workOutTime+" minutes.");
} else {
mLogView.printLog("The time status is unknown.");
}
break;
default:
break;
}
mScrollView.postDelayed(()-> mScrollView.smoothScrollTo(0,mScrollView.getBottom()*3),200);
}
}
MediaPlayer is added as given :
Code:
MediaPlayer mp = MediaPlayer.create(this, R.raw.audio);
mp.setLooping(true);
CountDownTimer to notify remaining workout time:
Code:
public void countDown(long workOutInMs){
new CountDownTimer(workOutInMs,1000) {
@Override
public void onTick(long millisUntilFinished) {
int seconds = (int) (millisUntilFinished / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
workOut_txt.setText(String.format("%d:%02d", minutes, seconds));
// counter++;
}
@Override
public void onFinish() {
workOut_txt.setText("Your work out is over");
mp.pause();
play_pause.setBackground(getDrawable(android.R.drawable.ic_media_play));
play_pause.setVisibility(View.GONE);
}
}.start();
}
Added different barriers as given:
Code:
AwarenessBarrier enterBarrier = LocationBarrier.enter(latitude, longitude, radius);
Utils.addBarrier(getApplicationContext(), ENTER_BARRIER_LABEL, enterBarrier, mPendingIntent);
AwarenessBarrier exitBarrier = LocationBarrier.exit(latitude, longitude, radius);
Utils.addBarrier(getApplicationContext(), EXIT_BARRIER_LABEL, exitBarrier, mPendingIntent);
AwarenessBarrier stayBarrier = LocationBarrier.stay(latitude, longitude, radius, workOutInMs);
Utils.addBarrier(getApplicationContext(), STAY_BARRIER_LABEL, stayBarrier, mPendingIntent);
AwarenessBarrier keepingConnectedBarrier = HeadsetBarrier.keeping(HeadsetStatus.CONNECTED);
Utils.addBarrier(getApplicationContext(), KEEPING_BARRIER_LABEL, keepingConnectedBarrier, mPendingIntent);
AwarenessBarrier connectingBarrier = HeadsetBarrier.connecting();
Utils.addBarrier(getApplicationContext(), CONNECTING_BARRIER_LABEL, connectingBarrier, mPendingIntent);
AwarenessBarrier timePeriodBarrier = TimeBarrier.duringTimePeriod(currentTimeStamp,
currentTimeStamp + workOutInMs);
Utils.addBarrier(getApplicationContext(), DURING_TIME_PERIOD_BARRIER_LABEL,
timePeriodBarrier, mPendingIntent);
The function alert_stayTimeDialog() is used to capture user workout time.
Code:
void alert_stayTimeDialog(){
final EditText edittext = new EditText(this);
edittext.setText("0");
edittext.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);
AlertDialog.Builder alert = new AlertDialog.Builder(
this);
alert.setMessage("Your Workout Time");
alert.setTitle("Enter time in minutes ");
alert.setView(edittext);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//What ever you want to do with the value
Editable YouEditTextValue = edittext.getText();
//OR
int stayTime = Integer.parseInt(edittext.getText().toString());
//Add the code after success
SharedPreferences.Editor editor = gymOutPref.edit();
editor.putBoolean("SET_WORKOUT", true);
editor.putInt("SET_WORKOUT_TIME", stayTime);
editor.commit();
workOutTime=stayTime;
set_workout.setEnabled(false);
set_workout.setBackground(getDrawable(R.drawable.button_style_disable));
delete_workout.setEnabled(true);
delete_workout.setBackground(getDrawable(R.drawable.button_style));
workOut_txt.setText("WorkOut Time:"+stayTime+" Mnts");
Toast.makeText(getApplicationContext(), "WorkOut Time: " + stayTime, Toast.LENGTH_LONG).show();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
});
alert.show();
}

A Journey Through HMS Awareness - Part 1

HUAWEI Awareness Kit provides your app with the ability to obtain contextual information including users' current time, location, behavior, audio device status, ambient light, weather, and nearby beacons.
There are two types of API in awareness Kit - Capture API and Barrier API. The Capture API allows the app to request the current user status and the Barrier API allows the app to set a combination of contextual conditions. In this article we are explaining about Location Awareness, Headset Awareness, Ambient Light Awareness and Bluetooth Car Stereo Awareness.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Steps for developing capture capabilities
1. Obtain the Capture Client object of HUAWEI Awareness Kit.
2. Call the respective query capability API through the Capture Client object to obtain the user's context.
3. Enable your app to listen for the result returned by HUAWEI Awareness Kit for further processing.
Steps for developing barrier capabilities
1. Define the barrier.
2. Define PendingIntent that will be triggered upon a barrier status change, for example, to send a broadcast, and create a broadcast receiver to receive the broadcast.
3. Define the label for the barrier and add the barrier.
4. Define the broadcast receiver to listen for the barrier event for further processing.
In this article we are explaining about Location Awareness, Headset Awareness, Ambient Light Awareness and Bluetooth Car Stereo Awareness.
Headset Awareness
For calling Headset Awareness capability we have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.BLUETOOTH" />
Capture API
We can use the Capture API to detect whether the user currently has their headset connected or disconnected.
To get the headset status from the Capture API we need to call the getHeadsetStatus() method - this will return an instance of the HeadsetStatusResponse class that if successful, will contain information about the devices current headphone status.
Code:
private void getHeadsetStatus() {
// Use the getHeadsetStatus API to get headset connection status.
Awareness.getCaptureClient(this)
.getHeadsetStatus()
.addOnSuccessListener(new OnSuccessListener<HeadsetStatusResponse>() {
@Override
public void onSuccess(HeadsetStatusResponse headsetStatusResponse) {
HeadsetStatus headsetStatus = headsetStatusResponse.getHeadsetStatus();
int status = headsetStatus.getStatus();
String statusStr = "Headset is " +
(status == HeadsetStatus.CONNECTED ? "connected" : "disconnected");
headset_status_capture.setText(statusStr);
if(status==HeadsetStatus.CONNECTED) {
headset_status_capture.setTextColor(getColor(R.color.green));
headset_status_image.setImageDrawable(getDrawable(R.drawable.ic_headset_connected));
}else{
headset_status_capture.setTextColor(getColor(R.color.red));
headset_status_image.setImageDrawable(getDrawable(R.drawable.ic_volume_up));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
headset_status_capture.setTextColor(getColor(R.color.red));
headset_status_capture.setText("Failed to get the headset capture.");
}
});
}
Barrier API
The given example illustrates how to develop a barrier triggered by the connecting condition. That is, the barrier will be triggered when the headset is connected or plugged in.
Code:
public class HeadsetBarrierActivity extends AppCompatActivity {
private TextView headset_status_barrier;
private ImageView headset_status_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.headset_barrier_activity);
headset_status_barrier=findViewById(R.id.headset_status_barrier);
headset_status_barrier_image=findViewById(R.id.headset_status_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "HEADSET_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
HeadsetBarrierReceiver barrierReceiver = new HeadsetBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier();
}
private void addbarrier() {
//define the barrier
AwarenessBarrier headsetBarrier = HeadsetBarrier.keeping(HeadsetStatus.CONNECTED);
//define the label for the barrier and add the barrier
String headsetBarrierLabel = "headset keeping connected barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(headsetBarrierLabel, headsetBarrier,pendingIntent).build();
Awareness.getBarrierClient(this).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add headset keeping barrier connected success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add headset keeping barrier connected failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
private class HeadsetBarrierReceiver extends BroadcastReceiver {
private static final String TAG ="Headset Barrier" ;
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
headset_status_barrier.setTextColor(getColor(R.color.green));
headset_status_barrier.setText("Headset is connected");
headset_status_barrier_image.setImageDrawable(getDrawable(R.drawable.ic_headset_connected));
break;
case BarrierStatus.FALSE:
headset_status_barrier.setTextColor(getColor(R.color.red));
headset_status_barrier.setText("Headset is disconnected");
headset_status_barrier_image.setImageDrawable(getDrawable(R.drawable.ic_volume_up));
break;
case BarrierStatus.UNKNOWN:
headset_status_barrier.setTextColor(getColor(R.color.red));
headset_status_barrier.setText("unknown");
break;
}
}
}
}
Location Awareness
For calling Location Awareness capability we have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
Capture API
We can use the Capture API to Obtains the latitude and longitude of the current location.
To get the location from the Capture API we need to call the getLocation() method - this will return an instance of the LocationResponse class that if successful, will contain information about the location.
Code:
private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
Utils.setHomeLatitude(location.getLatitude());
Utils.setHomeLongitude(location.getLongitude());
location_details_capture.setText("Longitude:" + location.getLongitude()
+ ",Latitude:" + location.getLatitude());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
location_details_capture.setText("Failed to get the location.");
}
});
}
Barrier API
Given an example in which a barrier is triggered by the enter condition. That is, the barrier will be triggered when a user enters his house.
Code:
public class LocationBarrierActivity extends AppCompatActivity {
private TextView location_details_barrier;
private ImageView location_image_barrier;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_barrier_activity);
location_details_barrier=findViewById(R.id.location_details_barrier);
location_image_barrier=findViewById(R.id.location_image_barrier);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "LOCATION_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LocationBarrierReceiver barrierReceiver = new LocationBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
//Home latitude and longitude
double latitude = Utils.getHomeLatitude();
double longitude = Utils.getHomeLongitude();
double radius = 200;
//define the barrier
AwarenessBarrier enterBarrier = LocationBarrier.enter(latitude, longitude, radius);
//define the label for the barrier and add the barrier
String locationBarrierLabel = "Home enter barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(locationBarrierLabel, enterBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add Home enter barrier barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add Home enter barrier barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event
class LocationBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
location_details_barrier.setText("You are at Home");
break;
case BarrierStatus.FALSE:
location_details_barrier.setText("You are away from home");
break;
case BarrierStatus.UNKNOWN:
location_details_barrier.setText("unknown");
break;
}
}
}
}
Ambient Light Awareness
Capture API
We can use the Capture API to obtain the illuminance of the environment where the device is located.
To get the light intensity from the Capture API we need to call the getLightIntensity () method - this will return us and instance of the AmbientLightResponse class that if successful, will contain information about the users light intensity.
Code:
private void getLightIntensity() {
Awareness.getCaptureClient(this).getLightIntensity()
.addOnSuccessListener(new OnSuccessListener<AmbientLightResponse>() {
@Override
public void onSuccess(AmbientLightResponse ambientLightResponse) {
AmbientLightStatus ambientLightStatus = ambientLightResponse.getAmbientLightStatus();
ambientLight_capture.setTextColor(getColor(R.color.green));
ambientLight_capture.setText("Light intensity is " + ambientLightStatus.getLightIntensity() + " lux");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
ambientLight_capture.setTextColor(getColor(R.color.red));
ambientLight_capture.setText("Failed to get the light intensity.");
}
});
}
Barrier API
We can use the Barrier API to set the ambient light barrier. For example, we can set the application to enable the auto flashlight function when the luminance is less than 20 lux. You can see the article "HMS Ambient Light Awareness for building an Auto Flash Light Application” for the reference.
Code:
public class AmbientLightBarrierActivity extends AppCompatActivity {
private TextView ambientLight_barrier;
private ImageView ambientLight_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ambient_light_barrier_activity);
ambientLight_barrier=findViewById(R.id.ambient_light_barrier);
ambientLight_barrier_image=findViewById(R.id.ambient_light_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "LIGHT_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LightBarrierReceiver barrierReceiver = new LightBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
//define lux here
final float luxValue = 60.0f;
//define the barrier
AwarenessBarrier lightAboveBarrier = AmbientLightBarrier.above(luxValue);
//define the label for the barrier and add the barrier
String lightBarrierLabel = "light above barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(lightBarrierLabel, lightAboveBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add light abov barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add light above barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
class LightBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
ambientLight_barrier.setTextColor(getColor(R.color.green));
ambientLight_barrier.setText("Room light is sufficient");
break;
case BarrierStatus.FALSE:
ambientLight_barrier.setTextColor(getColor(R.color.red));
ambientLight_barrier.setText("Room light is minimal");
break;
case BarrierStatus.UNKNOWN:
ambientLight_barrier.setTextColor(getColor(R.color.red));
ambientLight_barrier.setText("Unknown");
break;
}
}
}
}
Bluetooth Car Stereo Awareness
For calling Bluetooth Car Stereo Awareness capability we have to assign the given permissions in the manifest file.We have to assign the given permissions in the manifest file.
Code:
<uses-permission android:name="android.permission.BLUETOOTH" />
Capture API
We can use the Capture API to detect whether The Bluetooth car stereo is currently connected or disconnected.
To get the Bluetooth car stereo status from the Capture API we need to call the getBluetoothStatus(0) method - this will return an instance of the BluetoothStatusResponse class that if successful, will contain information about the The Bluetooth car stereo status.
Code:
private void getBluetoothStatus() {
int deviceType = 0; // Value 0 indicates a Bluetooth car stereo.
Awareness.getCaptureClient(this).getBluetoothStatus(deviceType)
.addOnSuccessListener(new OnSuccessListener<BluetoothStatusResponse>() {
@Override
public void onSuccess(BluetoothStatusResponse bluetoothStatusResponse) {
BluetoothStatus bluetoothStatus = bluetoothStatusResponse.getBluetoothStatus();
int status = bluetoothStatus.getStatus();
String statusStr = "The Bluetooth car stereo is " +
(status == BluetoothStatus.CONNECTED ? "connected" : "disconnected");
bluetooth_status_capture.setText(statusStr);
if(status== BluetoothStatus.CONNECTED) {
bluetooth_status_capture.setTextColor(getColor(R.color.green));
bluetooth_status_image.setImageDrawable(getDrawable(R.drawable.bluetooth_connected));
}else{
bluetooth_status_capture.setTextColor(getColor(R.color.red));
bluetooth_status_image.setImageDrawable(getDrawable(R.drawable.bluetooth_disconnected));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
bluetooth_status_capture.setText("Failed to get Bluetooth status.");
}
});
}
Barrier API
The following example illustrates how to develop a barrier triggered by the connecting condition. That is, the barrier will be triggered when the Bluetooth car stereo is connected.
Code:
public class BluetoothBarrierActivity extends AppCompatActivity {
private TextView bluetooth_status_barrier;
private ImageView bluetooth_status_barrier_image;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_barrier_activity);
bluetooth_status_barrier=findViewById(R.id.bluetooth_status_barrier);
bluetooth_status_barrier_image=findViewById(R.id.bluetooth_status_barrier_image);
// define PendingIntent that will be triggered upon a barrier status change.
final String BARRIER_RECEIVER_ACTION = getApplication().getPackageName() + "BLUETOOTH_BARRIER_RECEIVER_ACTION";
Intent intent = new Intent(BARRIER_RECEIVER_ACTION);
pendingIntent = PendingIntent.getBroadcast(this, 1, intent, PendingIntent.FLAG_UPDATE_CURRENT);
BluetoothBarrierReceiver barrierReceiver = new BluetoothBarrierReceiver();
registerReceiver(barrierReceiver, new IntentFilter(BARRIER_RECEIVER_ACTION));
addbarrier(this);
}
private void addbarrier(Context context) {
final int deviceType = 0; // Value 0 indicates a Bluetooth car stereo.
//define the barrier
AwarenessBarrier connectingBarrier = BluetoothBarrier.connecting(deviceType);
String bluetoothBarrierLabel = "bluetooth connecting barrier";
//add the barrier
BarrierUpdateRequest.Builder builder = new BarrierUpdateRequest.Builder();
BarrierUpdateRequest request = builder.addBarrier(bluetoothBarrierLabel, connectingBarrier,pendingIntent).build();
Awareness.getBarrierClient(context).updateBarriers(request)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Toast.makeText(getApplicationContext(), "add bluetooth connecting barrier success", Toast.LENGTH_SHORT).show();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
Toast.makeText(getApplicationContext(), "add bluetooth connecting barrier failed", Toast.LENGTH_SHORT).show();
}
});
}
// define the broadcast receiver to listen for the barrier event.
class BluetoothBarrierReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
BarrierStatus barrierStatus = BarrierStatus.extract(intent);
String label = barrierStatus.getBarrierLabel();
switch(barrierStatus.getPresentStatus()) {
case BarrierStatus.TRUE:
bluetooth_status_barrier.setTextColor(getColor(R.color.green));
bluetooth_status_barrier.setText("The Bluetooth car stereo is connected");
bluetooth_status_barrier_image.setImageDrawable(getDrawable(R.drawable.bluetooth_connected));
break;
case BarrierStatus.FALSE:
bluetooth_status_barrier.setTextColor(getColor(R.color.red));
bluetooth_status_barrier.setText("The Bluetooth car stereo is not connected");
bluetooth_status_barrier_image.setImageDrawable(getDrawable(R.drawable.bluetooth_disconnected));
break;
case BarrierStatus.UNKNOWN:
bluetooth_status_barrier.setText("Unknown");
break;
}
}
}
}
References:
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/awareness-introduction

Categories

Resources