Android Wear Wellness Sensor Moto360 - java

As far as I know , moto360 doesn't have a sensor of type : TYPE_HEART_RATE, it's called passive wellness sensor.
The problem is that this wellness sensor is not giving me any data, as opposed to every other sensor that I've tried (like gravity, accelerometer...)
I've been waiting for more than 5 min but this sensor gives me data only when I start the app.
I've tried sdk20,sdk21,sdk22,sdk23 ... still no result
I also have the android.permission.BODY_SENSORS in my manifest
Question : How to get the sensor working, what can I do?
package com.x.firstapp;
import android.app.Activity;
import android.os.Bundle;
import android.support.wearable.view.WatchViewStub;
import android.util.Log;
import android.widget.Toast;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.view.WindowManager;
public class MainActivity extends Activity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mHeartSensor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub);
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
#Override
public void onLayoutInflated(WatchViewStub stub) {
}
});
// keep watch screen on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Toast.makeText(getApplicationContext(), "Hi Oleg", Toast.LENGTH_LONG).show();
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mHeartSensor = mSensorManager.getDefaultSensor(65538); //wellness sensor
mSensorManager.registerListener(this, mHeartSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == 65538) {
String msg = "" + (int) event.values[0];
Log.d("Main Activity", msg);
}
}
#Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
Log.d("Main Activity", "accuracy : " + accuracy + " sensor : " + sensor.getName());
}
#Override
protected void onStop() {
super.onStop();
mSensorManager.unregisterListener(this);
}
}
only output out of this "wellness" sensor (only when app starts) :
D/Main Activity: accuracy : 3 sensor : Wellness Passive Sensor
D/Main Activity: 0

As you know ,the value of TYPE_HEART_RATE is not equal to the Wellness Passive Sensor, but when I set as below:
Sensor mHeartRateSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_HEART_RATE);
I find, I get the heart beat values.
By the way, don't forget to add permission.

I remember having huge problems specifically on the Moto 360 (first gen) when trying to read heart rate data. You're doing the correct thing using the passive wellness sensor as there isn't a heart rate monitor reported in the list of sensors.
Have a look at the Github repo here for inspiration (that's what I did to figure it out): https://github.com/pocmo/SensorDashboard
It's worth noting that even if you get it working, it's incredibly flaky. It's even flaky through the built in apps - have a play around with the Google Fit and Moto Body to take your heart rate, you'll see what I mean.

Google have API for fitness sensors, look at the following links
https://developers.google.com/fit/android/sensors
And project for example
https://github.com/googlesamples/android-fit/tree/master/BasicSensorsApi

Related

Detect when android user zooms an app screen in Android

I want to log an event for telemetry when user zooms in the screen of an app in android.
Based on my research I could not find a system event that I can subscribe to determine if user zoomed the screen.
Any pointers to detect that?
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.accessibilityservice.AccessibilityService;
import android.graphics.Region;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity implements AccessibilityService.MagnificationController.OnMagnificationChangedListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public void onMagnificationChanged(#NonNull AccessibilityService.MagnificationController magnificationController, #NonNull Region region, float v, float v1, float v2) {
float Scale = v;
// Scale will be changed as magnification is done on app
}
}
You are looking for Android Gestures
Here is a documentation about it:
https://developer.android.com/training/gestures
Here is a zoom/scale gesture:
https://developer.android.com/training/gestures/scale
and
Can we use scale gesture detector for pinch zoom in Android?

Google Street view + device tilting

I'm trying to add an activity as a feature to an app I'm building where, the API will return a lat long, and with this lat long I will load google street view. Which with the movement of the device, will rotate the 360 degree angle of the position. I'm struggling on the movement part of the device. Using your fingers on the screen you can rotate. I wonder if anyone can point me in the right direction in getting the device movement to affect the position of the street view?
The code I have so far is:
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.google.android.gms.maps.OnStreetViewPanoramaReadyCallback;
import com.google.android.gms.maps.StreetViewPanorama;
import com.google.android.gms.maps.StreetViewPanoramaFragment;
import com.google.android.gms.maps.StreetViewPanoramaOptions;
import com.google.android.gms.maps.StreetViewPanoramaView;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.StreetViewPanoramaCamera;
import com.google.android.gms.maps.model.StreetViewPanoramaLocation;
public class MainActivity extends FragmentActivity
implements OnStreetViewPanoramaReadyCallback {
private static final String TAG = MainActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StreetViewPanoramaFragment streetViewPanoramaFragment =
(StreetViewPanoramaFragment) getFragmentManager()
.findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(this);
}
#Override
public void onStreetViewPanoramaReady(final StreetViewPanorama panorama) {
final long duration = 1000;
float tilt = 30;
float bearing = 90;
final StreetViewPanoramaCamera camera = new StreetViewPanoramaCamera.Builder()
.zoom(panorama.getPanoramaCamera().zoom)
.bearing(bearing)
.tilt(tilt)
.build();
panorama.setPosition(new LatLng(52.208818, 0.090587));
panorama.setStreetNamesEnabled(false);
panorama.setZoomGesturesEnabled(false);
panorama.setOnStreetViewPanoramaChangeListener(new StreetViewPanorama.OnStreetViewPanoramaChangeListener() {
#Override
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
if (streetViewPanoramaLocation != null) {
panorama.animateTo(camera, duration);
}
Log.d(TAG, "TESTINGGGGGGGGGG");
}
});
}
}
I'm not sure given your question, so comment if i'm wrong but it seems you're able to rotate through this instruction
panorama.animateTo(camera, duration);
and you're moving to a specific location using the "camera" variable you built before.
So, if i understand correctly what you are trying to do, you have to check for mobilephone sensors (accelerometer & position) to get the motion then apply the correct motion to the panorama. Take a look at android sensor documentation in order to get the proper listeners (or how to register a sensor usage) then build the correct camera object according to the acceleration registered by the phone (left acceleration -> rotating left, right acceleration --> rotating right).
If you need a code example i'd suggest you to look this question which has some other links to help you using sensors and getting more doc.
If this does not help, comment and/or clarify the question.

Android: addProximityAlert LocationManager Method doesn't send Broadcast

I'm working on an Android Project where i'm using AddProximityAlert method, as you already know this method let you set a proximity alert for the location given by the position (latitude, longitude) and the given radius, and notify you if you are so close to it.
so i was working on that for three days ago and i was getting the same probleme again and again..
in bref: this is my simple code.
#MainActivity.java
package com.example.proximityalert;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity implements LocationListener {
LocationManager lm;
//Defining Latitude & Longitude
double lat=37.422006 ,long1=-122.084095;
//Defining Radius
float radius=1000;
//Intent Action
String ACTION_FILTER = "com.example.proximityalert";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//i'm registering my Receiver First
registerReceiver(new ProximityReciever(), new IntentFilter(ACTION_FILTER));
//i'm calling ther service Location Manager
lm=(LocationManager) getSystemService(LOCATION_SERVICE);
//for debugging...
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, this);
//Setting up My Broadcast Intent
Intent i= new Intent(ACTION_FILTER);
PendingIntent pi = PendingIntent.getBroadcast(getApplicationContext(), -1, i, 0);
//setting up proximituMethod
lm.addProximityAlert(lat, long1, radius, -1, pi);
}
#Override
//just For debugging to See the distance between my actual position and the aproximit point
public void onLocationChanged(Location newLocation) {
Location old = new Location("OLD");
old.setLatitude(lat);
old.setLongitude(long1);
double distance = newLocation.distanceTo(old);
Log.i("MyTag", "Distance: " + distance);
}
#Override
public void onProviderDisabled(String arg0) {}
#Override
public void onProviderEnabled(String arg0) {}
#Override
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {}
}
#ProximityReceiver.java
package com.example.proximityalert;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.util.Log;
import android.widget.Toast;
public class ProximityReciever extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Key for determining whether user is leaving or entering
String key = LocationManager.KEY_PROXIMITY_ENTERING;
//Gives whether the user is entering or leaving in boolean form
boolean state = intent.getBooleanExtra(key, false);
if(state){
// Call the Notification Service or anything else that you would like to do here
Log.i("MyTag", "Welcome to my Area");
Toast.makeText(context, "Welcome to my Area", Toast.LENGTH_SHORT).show();
}else{
//Other custom Notification
Log.i("MyTag", "Thank you for visiting my Area,come back again !!");
Toast.makeText(context, "Thank you for visiting my Area,come back again !!", Toast.LENGTH_SHORT).show();
}
}
}
*#the probleme is when i run the program , the BroadcastReceiver(ProximityReciever) never never called by the system even if i'm veryyy close to the proximit point, and even if the debugger shows me that distance between the two locations is < 1000m :/
I just figured out somthing about this topic and why the addProximityAlert sames to be not working, I'm sharing this with you because I noticed that some people asked the same question before and they don't get any answer!
The answer was just in front of me but i didn't pay attention to it, so when i was reading the Android officiel documentation (here) i saw this sentence "Due to the approximate nature of position estimation, if the device passes through the given area briefly, it is possible that no Intent will be fired"
what is that mean? it means when you are testing your app on the AVD and u send a gps coordinates(latitude, longitude) from the DDMS to AVD its really hard to
simulate the real aspect of a gps, (because in the first place u pick some point to be your proximPoint and just after that you choose anthor point very far from the proximPoint to see if its work) and thats not what it's happing with a real device.
so the solution is to test your app on a real device or with the DDMS try to change the coordiantes very slowly until you are in the zone wanted.

Simple OpenGL ES 2.0 app on Android displaying blank screen: why?

So I'm following the book Open GL ES 2 for Android by Kevin Brothaler and I'm trying out the first chapter's project, which is basically coloring the screen red. I set up by Samsung Galaxy Note 3 so I can debug my app on there, and also set up an emulator that uses the host GPU for rendering. Also, I forced GPU rendering on my phone. I copied the code he had exactly into my eclipse project. Here's the code for reference:
package com.firstopenglproject.android;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
//import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class FirstOpenGLProjectActivity extends Activity {
private static final String TAG = FirstOpenGLProjectActivity.class.getSimpleName();
private GLSurfaceView glSurfaceView;
private boolean rendererSet = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "Before calling super.onCreate()");
super.onCreate(savedInstanceState);
Log.d(TAG, "Before creating a new GLSurfaceView");
glSurfaceView = new GLSurfaceView(this);
Log.d(TAG, "Creating activity manager");
final ActivityManager activityManager =
(ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Log.d(TAG, "Creating configuration info");
final ConfigurationInfo configurationInfo =
activityManager.getDeviceConfigurationInfo();
Log.d(TAG, "Getting supportsEs2 boolean");
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
// || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
// && (Build.FINGERPRINT.startsWith("generic")
// || Build.FINGERPRINT.startsWith("unknown")
// || Build.MODEL.contains("google_sdk")
// || Build.MODEL.contains("Emulator")
// || Build.MODEL.contains("Android SDK built for x86")));
Log.d(TAG, "supportsEs2 = " + supportsEs2);
if (supportsEs2) {
// Request an OpenGLES2 compatible context
glSurfaceView.setEGLContextClientVersion(2);
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
// Assign our renderer
glSurfaceView.setRenderer(new FirstOpenGLProjectRenderer());
rendererSet = true;
Toast.makeText(this, "Device supports OpenGL ES 2.0", Toast.LENGTH_LONG).show();
Log.d(TAG, "rendererSet is true");
} else {
Log.d(TAG, "OGLES2.0 not supported");
Toast.makeText(this, "This device does not support OpenGL ES 2.0", Toast.LENGTH_LONG).show();
return;
}
}
#Override
protected void onPause() {
super.onPause();
if (rendererSet) {
glSurfaceView.onPause();
}
}
#Override
protected void onResume() {
super.onResume();
if (rendererSet) {
glSurfaceView.onResume();
}
}
}
The logging tasks were ones that I added so that I can see whether the code is executing properly, and it is: I see all these log messages in LogCat. Here's the code for the renderer:
package com.firstopenglproject.android;
import static android.opengl.GLES20.GL_COLOR_BUFFER_BIT;
import static android.opengl.GLES20.glClear;
import static android.opengl.GLES20.glClearColor;
import static android.opengl.GLES20.glViewport;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView.Renderer;
public class FirstOpenGLProjectRenderer implements Renderer {
private static final String TAG = FirstOpenGLProjectRenderer.class.getSimpleName();
/*
* GLSurfaceView calls this when its time to draw a frame. We must
* draw something, even if its only to clear the screen. The rendering buffer
* will be swapped and displayed on the screen after this method returns,
* so if we don't draw anything, we'll probably get a bad flickering effect.
* */
#Override
public void onDrawFrame(GL10 arg0) {
// clear the rendering surface
glClear(GL_COLOR_BUFFER_BIT);
}
/*
* GLSurfaceView calls this after the surface is created and whenever the size has
* changed. A size change can occur when switcheing from portrait to landscape
* and vice versa.
*/
#Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
// set the openGL viewport to fill the entire surface
glViewport(0, 0, width, height);
}
/*
* GLSurfaceView calls this when the surface is created. This happens the first
* time our application is run, and it may also be called when the device wakes
* up or when the user switches back to our activity. In practice, this means that
* this method may be called multiple times while our application is still running.
*/
#Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {
glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}
}
As you can see, I only use 3 calls to static methods in the GLES20 package. When I run this app on my phone and on my emulator I get a blank screen: what is going on? I've been banging my head on the table for the last 2 hours about this, and this is as simple as it could possibly get. It's supposed to display a red screen. Thanks a bunch!
you are not setting the view in your OnCreate() method at the end of that method add:
setContentView(glSurfaceView);

why wont my Gyroscope app in android fire off any events?

alright so I'm new to programming for android, and I think I did something wrong, but I don't know what. I've looked at 3 different tutorials and my code seems to look like theirs. Can anyone tell me what I'm doing wrong? here is my src (altered from a android nehe tutorial).
package cypri.games;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
/**
* The initial Android Activity, setting and initiating
* the OpenGL ES Renderer Class #see Lesson02.java
*
* #author Savas Ziplies (nea/INsanityDesign)
*/
public class DGearActivity extends Activity {
/** The OpenGL View */
private GLSurfaceView glSurface;
DGear dGear = new DGear();
private static final String TAG = "DEBUG";
SensorManager sensorManager;
private final SensorEventListener sensorListener = new SensorEventListener(){
public void onSensorChanged(SensorEvent se) {
if (se.sensor.getType() == Sensor.TYPE_GYROSCOPE) {
dGear.playerX = se.values[0];
Log.v(TAG, "se.values[0] =" + se.values[0]);
}
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
};
/**
* Initiate the OpenGL View and set our own
* Renderer (#see Lesson02.java)
*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
//Create an Instance with this Activity
glSurface = new GLSurfaceView(this);
//Set our own Renderer
glSurface.setRenderer(dGear);
//Set the GLSurface as View to this Activity
setContentView(glSurface);
}
/**
* Remember to resume the glSurface
*/
#Override
protected void onResume() {
Log.v(TAG, "or");
super.onResume();
glSurface.onResume();
sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
}
/**
* Also pause the glSurface
*/
#Override
protected void onPause() {
super.onPause();
glSurface.onPause();
Log.v(TAG, "op");
sensorManager.unregisterListener(sensorListener);
}
}
Are you running this in the emulator or on an actual device?
If you're running it on an actual device are you sure it has a gyroscope? There are lots of different sensor types and the gyroscope is only one of them. It could very well be one of the others.
Instead of only writing to the log if it's a gyroscope type, try writing the name of the se.sensor when that event fires. That way you'll at least know the event is firing.

Categories