Access Android sensors via NDK - android

I need read about 100 samples per second off the accelerometer on a Android, and at a fixed sample rate. The current sensormanager does or offers neither.
I've read Need to read android sensors really fast
He seems to have access to the driver code which made his life easier.
I am curious if anyone has been able to do something like this through the NDK w/o that type of knowledge.
Thanks in advance!

I have taken a look at sensor.h, and the API looks very promising; however, a little howto on how to deal with the ASensorEventQueue and ASensorEventQueue_hasEvents and so forth would be -extremely- useful.
Ha! Update:
This looks a code example for what you want to do.
http://developer.android.com/reference/android/app/NativeActivity.html

Since Android SDK version 9 (for Android > 2.2) it seems to be possible to use the sensors via NDK.
See the STABLE_APIS.html file included in the docs. (Search for "sensor.h"). A mirror of that file is here.

Example from google https://github.com/googlesamples/android-ndk/tree/master/sensor-graph.Their code allow you controll SENSOR_REFRESH_RATE_HZ for the accelerometer.Written on c++ and connected to java code through the NDK.

I have recently worked on a pure C sensor application for android. Using NDK, you can access the sensors on the device without using Java.
Check : https://github.com/PromiseMasango/sensor.
Check : https://github.com/PromiseMasango/Android-NDK-sensor-example.

Sensors can be read reading directly from system "files" like:
/sys/class/sensors/light_sensor/lux
or
/sys/class/sensors/light_sensor/raw_data
I wonder if there is a more direct way to do it, reading directly from the chip.
Like something in /dev/...

Related

Detect USB device using native library on Android

I would like to know how to detect a USB device which is connected to an Android device (as a host). In normal Linux I just use libudev to do that. What's the equivalent in Android?
Any documentation about it?
Thank you
It was past long time but I would like to add some finding with the hope to help others.
There is an Android native solution using Android's libusbhost library to access a USB device from native C++ (by #sonicdebris from github.com). Here is the link. It is a PoC and not complete but it will give some idea about the problem.
There is also a recipe about the question in the official Android documentation but it is Java. Here is the link.

Can I use Lazarus Pascal to build for iOS AND Android

I would like to know:
If it's possible to use Lazarus (Pascal) for both Android and iOS development.
If the answer seems positive, do I need a third-party SDK/API or package to do this?
Thanks!
Android: See answer from Nic Strong.
iOS (iPhone/iPad): Check google and find this result.
I am almost certain the answer is no.
EDIT: Looks like I was wrong. See http://wiki.lazarus.freepascal.org/Android_Programming
The answer is yes. For Ios Lazurs uses objectivepascal which a pascal extension that allows integration with objective-c much like objective-c++.
However it is necessary to do some work to set-up the environment and you need an Apple computer to build test and debug.
This is the best entry point for iOS development:
http://objectivepascal.com/

How to play with devices like accelerometer and camera using C/C++?

As you can see in architecture diagram below android platform has been built using different layers.
Application are developed in Java
Application Framework is written using Java (according to my understanding)
Libraries are in C/C++
For some insane reason I have to play/deal with devices like accelerometer, compass and camera using C/C++ which means directly accessing them in 3rd layer i.e. Libraries. According to my understanding the Application Framework itself would be consuming Libraries for accessing these devices and then providing APIs for Applications.
I am looking for any documentation/tutorials/demo which can help me in this regard i.e how to access and use these devices like camera, accelerometer and compass from C/C++ code or in other words how to play with these devices directly from Libraries layer.
My last option would be to get the android source code and dig deep into it to find out what I am looking for but I would like some easy way in form of a documentation/demo/tutorial/anything that can make this a bit easy for me.
I am looking for any documentation/tutorials/demo which can help me in this regard i.e how to access and use these devices like camera, accelerometer and compass from C/C++ code or in other words how to play with these devices directly from Libraries layer.
You don't. You access them from Java code. Reorganize your C/C++ code to support your Java code.
For the camera, you can use opencv to access the frames with a c++ library. For the Accelerometer, I'm looking for how to access using c++.

How to write android code in titanium

I had been working on android since a little long. Now I am wondering about titanium. Is it possible to write android (java) code in titanium app since the app is build in titanium? If yes then how? Actually I am having problem dealing with push notification for android in titanium. So I got a solution to build complete app in titanium and then if possible use android code in app to deal with push notification. How? Please do response as quickly as possible. Thanks in advance.
To answer your question directly, you will need to develop a native Android extension to call Java code via JavaScript in a Titanium application.
Rai
You should be checking out the docs Here tells you all you need to know
Hope it helps
Frank
yes it is possible but remember that the titanium tools lag behind the official android ones. Documentation is poor and often wrong, code is laggy and the resulting .apk are much bigger.
Why are you thinking of using Titanium? For cross-compatibility?
If you are thinking about that you have multiple possible ways:
1) Build a minimum common denominator, like titanium, but better: Write a core application for both android and iPhone so that it will be fast and light on memory, with a modified broswer to show your content. This way the interfaces will be much easier and you'll have to write the content just once.
Still you will be able to access low level hardware, like GPS, compass, gyroscope.... easily without consuming too much battery (unlike with titanium) as needed.
2) Find an existing minimum common denominator: Javascript work both on iPhone and Android.
3) There are many other options (Adobe air, python, custom scripting, mobile web site, ...) but I think that the cons outweigh greatly the pros.

android bluetooth

Can someone explain to me the concept behind using bluetooth?
My project in my studies is to make an android app using bluetooth, SQLLIGHT and google app
the app itself is a very easy one but I just dont get the tools I need to use :
How does the bluetooth works? Is there a simple example?
the concept behind android GUI (I already made one but I think I am not fully understood his power)?
note : I am using v 2.1
For learning bluetooth on android I guess you should dig into: http://developer.android.com/guide/topics/wireless/bluetooth.html
Should be simple.
Before you learn to program Bluetooth with API on a given platform, you need to read up a few basics first to understand the technology first. There are plenty of resource materials on internet for learning. If you prefer a book, you can try http://www.amazon.com/Bluetooth-Operation-Use-Robert-Morrow/dp/007138779X

Categories

Resources