Stopping a sensorListenser - android

I add a sensorListener(code from to my app, the allow the user shake the phone in order to start the game.
How do I disable the sensor after the first shake?
I got the sensor code from here

The API indicates that there is an "unregister method":
http://developer.android.com/reference/android/hardware/SensorManager.html#unregisterListener%28android.hardware.SensorEventListener,%20android.hardware.Sensor%29
After you have received your event you can use the Sensor Manager to unregister it - but your current code may use deprecated methods. You may want to have a look at this API to make sure it is up to date.

Related

Android: which api to use to record all incoming and outgoing call (Since in changelogs Android blocked call recording)

Is there is api where i can record all the incoming and outgoing call in android pie version . It seems nearly impossible to record a call. Please suggest what can be done in this scenario
Android disabled the api with their security update policy. Looking at the permissions list the closest you can find is the MANAGE_OWN_CALLS, meaning that the best solution for you is to implement a standalone application for calling where you should be able to interact with microphone directly.

Block incoming calls vs a system service

I wrote an application which has the capability of hanging up phone calls when they are received. In order to that I'm using the telephony manager and this permission is required:
android.permission.MODIFY_PHONE_STATE
However, this permission makes my app a system app and therefore I won't be able to place it in the play store later.
But I've seen apps in the play store that successfully block incoming calls ("Calls Blacklist" for example).
I wonder, does anyone know what API these apps are using in order to block an incoming call and also allow these apps in the play store ?
Thanks.
You need to make use of Broadcastreceiver class.
and also need to add this line in manifest to get persmission.
<uses-permission android:name="android.permission.READ_PHONE_STATE">
follow this.
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
Make sure TelephonyManager.CALL_STATE_RINGING is only incoming call.
You cannot detect outgoing call state whether it is ringing or answered.
for outgoing there only two states:
TelephonyManager.CALL_STATE_IDLE
&
TelephonyManager.CALL_STATE_OFFHOOK

How to reset MetaWear Device?

I am currently developing an application that will use Metawear device.
I have noticed that after I connect a device, I can read the live accelerometer values of that device but I want to read/download offline accelerometer values.
For that as per I refer https://gist.github.com/mbientlab/a299fc705f8ac3b64359 , I need to set Trigger.
But when I am setting triggers and if I did not remove that trigger then next time Metawear device unable to detect/scan by my device(Suppose an android mobile).
If device totally discharges and starts again then it resets.
So is there any method to remove that trigger without connecting to the device or reset the device
Thanx in advance
Use the removeAllTriggers method to remove all logging triggers. Line 100 of the aforementioned gist demonstrates trigger removal with the removeTrigger method

Android - Inactivity/Activity regardless of top app

I need to find out when the last user interaction was, regardless of which application is on top. I don't care about where or what the event was I just need to know when it was. Or alternatively, as it happens, I receive an event.
I've tried multiple things:
Create service with a window and added a touch listener. This ate the touch event and didn't pass it down
Looked for a shell command. getevent works (new line comes in every time a touch is received) however you need root and so it is not an appropriate solution for me.
Looked for "time until lock" but came up with nothing.
Also note: There is no security concern with this as I don't need any identifying information such as touch location. Just a type stamp (or live event).
I'm open to using reflection to figure it out as well.
#user2558882 has a very good solution. As of now, that's the best approach I've come across.
While that's great, it still requires the user to manually enable our application in the accessibility controls. We have customers with thousands of devices and we have a way to automatically update and change settings. We try and keep manual configuration to a minimum, but some things still require user input such as enabling Device Admin mode. So this solution is acceptable however I'm still open to a way that doesn't require any user input to enable.
I ended up implementing #user2558882's idea to use an accessibility service. Though other ideas are welcome.
This is just an idea, and may not be fully transferable.
Here's what an AccessibilityService can do:
An accessibility service runs in the background and receives callbacks
by the system when AccessibilityEvents are fired. Such events denote
some state transition in the user interface, for example, the focus
has changed, a button has been clicked, etc.
You will be informed of the event inside onAccessibilityEvent(AccessibilityEvent):
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
// Some event
timeSinceLastInteraction = System.currentTimeMillis();
}
You could periodically log the updates:
Log.i("LOG_TIME_ELAPSED", "Last user interaction was " +
((System.currentTimeMillis() - timeSinceLastInteraction) / 1000) +
" seconds ago.");
There are two ways in which you can configure your AccessibilityService:
In code, inside onServiceConnected(). (API 4 onwards)
In xml, using the meta-data tag in your service. (API 14 onwards)
In your application's case, you could probably set AccessibilityServiceInfo.eventTypes to:
accessibilitySeviceInfo.eventTypes = AccessibilityEvent.TYPES_ALL_MASK;
But, TYPES_ALL_MASK will include notifications such as: AccessibilityEvent.TYPE_ANNOUNCEMENT, AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED etc. which I am guessing you do not care to intercept. So, you'll need to choose a subset of AccessibilityEvent.TYPE_X.
Another thing you should be careful about is the notification timeout:
The timeout after the most recent event of a given type before an
AccessibilityService is notified.
The event notification timeout is useful to avoid propagating events
to the client too frequently since this is accomplished via an
expensive interprocess call. One can think of the timeout as a
criteria to determine when event generation has settled down.
So, be generous with the timeout value.
You'll find this page very helpful in case you decide to go with the AccessibilityService option: Developing an Accessibility Service.
From your comments to Chloe's answer, it seems that the device is under your control: meaning, to some extent, you don't have to rely on the user for enabling the service:
The lifecycle of an accessibility service is managed exclusively by
the system and follows the established service life cycle.
Additionally, starting or stopping an accessibility service is
triggered exclusively by an explicit user action through enabling or
disabling it in the device settings.
You can enable the AccessibilityService at time of deployment, and perhaps restrict access to Settings menu using an app like AppLock.
Another option is to check whether your AccessibilityService is enabled from time to time:
AccessibilityManager am = (AccessibilityManager)
getSystemService(ACCESSIBILITY_SERVICE);
List<AccessibilityServiceInfo> listOfServices =
am.getEnabledAccessibilityServiceList(
AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
for (AccessibilityServiceInfo asi : listOfServices) {
// Check if your AccessibilityService is running
}
In case the AccessibilityService has been disabled by a inquisitive/notorious user, you can lock the device by displaying a fullscreen view with text: Device has been locked. Contact a Sales Rep to unlock this device.
I believe you have to return false to indicate that your transparent service window did not consume the touch event. That way the event loop will pass it down the stack to the lower windows.
https://developer.android.com/reference/android/view/View.OnTouchListener.html
Another possibility, is to add a service which listens for motion/accelerometer events.
https://developer.android.com/guide/topics/sensors/sensors_motion.html
Another possibility is to listen for ACTION_USER_PRESENT
https://developer.android.com/reference/android/content/Intent.html#ACTION_USER_PRESENT
or ACTION_SCREEN_ON
https://developer.android.com/reference/android/content/Intent.html#ACTION_SCREEN_ON

BroadcastReceiver Priority issue

I am implementing SMSListener in my app and I have set it's possibly highest priority as android:priority="2147483647" so that I should get the call on new incoming sms.
In my second sample app I have set the same priority as above for SMSListener but when I get call for new incoming SMS I am using abortBroadcast();.
When I ran both these app and I found that 1 is getting the call before 2. Now I am seeking this behaviour will remain as it is or it is not constant and 2 can get call before 1.
I want to make sure that my app get's the call whenever sms comes even if there exists some other app which has the highest priority and it is aborting the sms.
I hope I have put my point and looking for some convincing answer.
Thanks for devoting your time to my problem.
The abortBroadcast only works when they get it first, usually based on installation order, but not always.) System level apps will execute, then Android will try to sort out non-system apps. If you look at the source code, the order of execution is based on priority level, but the calls to select the order of apps is not consistent for apps over 999 or for apps with the same priority level. It might be in order of installation, but system changes can result in other orders of execution (which I have seen many times with testing this).
Another thing, from what I understand, the priority for applications must be between -1000 and 1000, inclusive.
http://developer.android.com/reference/android/content/IntentFilter.html#setPriority%28int%29
http://developer.android.com/reference/android/content/IntentFilter.html#SYSTEM_HIGH_PRIORITY

Categories

Resources