Structure of Android app (java) continuously scanning for Bluetooth devices - java

I want to create an application that will continuously scan for other BT devices while the process is active (not killed).
The main idea is to scan for devices that are within the custom range (signal strength that I hope I can get from RSSI) and to log those occurances to a database in cloud.
I want to use a tabbedActivity:
1 tab - Current visible devices (needs to be refreshed every x seconds)
2 tab - history of ocurrances that has been sent to the database during current session (I have to implement some methods to eleminate duplicates etc.)
The question is how the structure of my application should look like?
Where should I put whole BT thing? As I suppose it shouldn't be in the MainActivity, because it can lagg the whole application. Should I use a service class? Another thread? The same question applies to the part of the program, which sends info to database.
Any sugestions regarding the internal structure would be great.
Any tips regarding energy consumption also.

Related

Click on an x and y position in another android application

I have a Bluetooth led bulb that will only work with one specific app. I want to create an app that will open the bulb app (iHomentLight) and gradually increase the brightness slider to wake me up in the morning. I want to know if it is possible to do this, and if so how?
Apps are sandboxed so that someone can't use this kind of thing to take advantage of you (and steal your bank info for example). Some apps work around this via accessibility service.
How to perform Other app list item click using accessibility service like Voice Access app?
However, you are probably better off just figuring out what the bluetooth API for your bulb is and teaching your app to work with it. You'll have your app connect directly to the bulb and do it yourself. Search Google for the bulb name and see if anyone has reverse-engineered the API.
Here is an amazing writeup on how to reverse engineer a bluetooth API:
https://medium.com/#urish/reverse-engineering-a-bluetooth-lightbulb-56580fcb7546
Spend some time trying this out, I think it'll be a more useful skill than messing with the accessibility service.
There are around three approaches you can take:
1 - If you have access to iHomentLight's API, you could potentially send a series of intents to the app and have it gradually adjust the light over time.
2 - If that is elusive, I'd recommend trying to sending touch commands via the terminal. For example 'input tap x y android'.
How to run terminal command in Android application?
3 - Or you can use Tasker App to make commands that will adjust the light just as well

How can I implement actions based on my rest API

I have a plan of automating a process via REST api and multiple smart devices. What I am trying to do is the following. I have 4 devices that each do a series of actions to complete their task. (practicaly Im gonna be lighting 4 leds in a particular series based on the device). Im currently emulating this in Java (since I dont have the devices at hand)
So for example lets say device no.1 lights up the red led first for 10 seconds, after that device no.2 needs to light up for 10 seconds etc. That's the task. This is done automatically and forever till I shutdown the program.
I have developed a REST API using JAVA and the JAX-RS library where I state the devices and their info (so device name, current state ex. Yellow Led ON/OFF etc.).
What I dont understand is how I am gonna make the program I have now respond to the info from the API. How can I make my program get notified when a value is changed on the API info?
How can I make device 2 poll the API till it gets the response to start its action? Or make it so it starts the action if i manually change the value on the server data? Example if the yellow led is on, and i go in the server database and put it on off, how will my application get notified and change the state of the simulated led?
Since you are using HTTP, most suitable solution is to use web sockets. You can use them for full duplex communication. When you receive input from one device, you can process it and inform other devices. Note that this is not suitable for a large client base.

How to block application launch in Android

I want to create an application in Android that will show the devices list of applications and then allow the user to select which apps they want to be restricted access to for a certain period of time.
I am aware there is an Android Application named "AppBlock" but i don't know how this works.
You select the app, the period of time and then it doesn't allow you to open the app.
You cannot actually block start of another application.
The only way that I see it is possible: you need to save the list of applications Info in your app that need to be blocked with the time when it need to be blocked. Implement a service that runs "forever" and detects started applications.
Refer to this answer about how to do it. On each detection you should check if application present in your database and if the time now says it need to be blocked. If it is - close the application. Refer to this answer for learning how to do it.
That is global architecture I think you should follow.
To Build App Block u need the following things
1-Accessibity services (AS)2-Forground Services (FS)
BY AS you will be able to stop activity that you have in your bloker list
FS will alive your application context that help to find block app

Getting user behavior on the Android Phone (App History, Browse History etc)

Is it possible to get the user behavior on the phone (for example Alpesh has an Android phone and he uses multiple apps, browser YouTube etc). Whatever he is doing on the phone I want to get all those things from behind (which apps he has installed, which app he opens and what he search on the phone, All these data I want to get programmatically so what all can be get in android).
For now I am aware that installed apps list can be get easily but I want to get usage history and what he do all on mobile.
This is not a code solution, but an answer to your question, so you can get start some where.
In my opinion your question title are asking about two things.
(part 1) Getting User Behavior on the Android Phone (part 2)(App History, Browse
History etc)
1- First part Getting User Behavior on the Android Phone:
There is a concept called context awareness. Short described; it is about gathering different information from the phone, like light sensor, motion sensor, sound, location or even user behavior etc. and depending on your app requirement and the gathered information:
You could send these information over cloud data store for statically usage
You could make your phone doing (behavior) different things depending on location, motion or what ever.
etc.
For context awareness it is an open area for pervasive computing research. And it is not just few lines of code to write, it is typically a complete solution depending on requirement. Example I have built a context awareness application to gather noise collected by phones from different locations for research purpose inspired from this framework, but I am pretty sure you can find other frameworks or even build your own, as I did in my case.
The mentioned framework has some examples.
2- The second part is about App History, Browse History etc.:
This is possible, but you still need to build a peace of software (App) to collect all these information (logs) from the phone. Hereafter you can make phone act on different conditions and/or again send it over a RESTful API over cloud service data store, there is no limit for it.
The problem is, there is no thing out of the box for your requirement. Even if you find frameworks you still need to research it and further work on it.
You can find different examples for your requirement, like to collect browser history, you can find SO question here:
Get browser history and search result in android
Or get list of installed application:
How to get a list of installed android applications and pick one to run
My point here is you need to solve small goals at a time and put your knowledge together at the end.
Both 1 and 2 can also be related to each other, depending on your achievement.
Conclusion
Make a goal to your project.
Define the main requirements and tasks of your project.
Research your options (Technology, Cost, Target Audience, What data I can or I should not collect, what is possible to collect, what is the limits, Privacy issues etc.).
Split your project in small assets and try to solve small problems/goals.
Finally you would be able to put the puzzles together and build your final application
but i want to get usage history and what he do all on mobile
This is not possible and shouldn't ever be possible. Each app is sandboxed by Android so apps cannot inspect what other apps are doing. Think about it, you wouldn't want apps to be able to intercept private information such as banking details.
Every app is isolated from the other ones. Unless you develop a system signed app, you will not be able to gather all that data.
What you could do is to develop your own Android Rom where you then develop your data collection the exact way you want. Then you need to distribute your rom, which is another story...

Can developer keep track of stats of app? - Android

I have made a trivia game app. Is there any way to keep track of, without the user knowing, stats like the following:
How many times a user has played a certain quiz
Overall correct percentage of questions of each quiz and of all quizzes combined
How many times the user ran out of time on a question
etc etc
I would love to be able to keep track of this so I can monitor data constantly to see, for example, if more time is needed on questions because they keep running out of time, etc etc. Right now I don't need a server or any internet interaction to play this game so if that is needed to do what I am asking above, please say that.
You should take a look at Google Analytics for Android. Internet connection will be necesary.
You could do this in a number of ways, all using web services though. It's up to you whether you want to store the statistics on the phone and then send these, or just send each individual statistic on game completion.
You would need a server to act as the web service endpoint which would then be called (using SOAP/REST probably) from the phone either nightly (if you stored the stats on a localdb on the phone) or after each game.
I'd recommend nightly or intervals rather than clogging up the phone owners bandwidth sending stats :)

Categories

Resources