Intercept button on bluetooth headset - android

I am trying to intercept the only one button on a bluetooth headset. I have tried many things found on the site but none worked. The main activivity manages the bluetooth connection (using a code from https://github.com/sauravpradhan/AnySound2BT).
I have the following manifest file :
...
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.intent.action.VOICE_COMMAND"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" >
</action>
</intent-filter>
</receiver>
...
When I click once, nothing happens and the second time the phone asks me to start "S voice" or "Google appli".
Thanks for any hint
Karim

Their are many methods to intercept the button function if this button really did something.
According to your description, the phone asks you to start "S voice" or "Google appli" then I assume one of the button's combined function is "Voice Recognition Activation".
You can export the btsnoop log of the Android, then click the HFP tab, to find out the AT command, then you can understand what the button sends.
Note that for all of the button on the headset, the long press,short press, and continue short press, the the press during calling or not calling,might have different meaning.

Related

Android PHONE_STATE not fired if phone is inactive for a night

My Android app invokes a webservice or sends SMS when a new incoming call received. I use android.intent.action.PHONE_STATE intent for this.
Everything works fine, except: the app must be restarted every morning.
It looks like if something prevents the app from receiving this broadcast if it is not used for hours, for a night.
What can cause this kind of behavior?
<application>
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".CallReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>

Is there any way to intercept Android M Bluetooh off scanning data?

I just have read that Android M performs bluetooth scanning even when the bluetooth is off
(Here is the first question: Is it only BLE scanning?).
So i thought it would be reallly nice to intercept that scanning data to discover the beacons.
I tried to register a broadcast receiver for android.bluetooth.device.action.FOUND in Manfest.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".BluetoothReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.bluetooth.device.action.FOUND" />
</intent-filter>
</receiver>
</application>
Unfortunetally that broadcast only comes on Android 5.1 and less but not the M.
Is there any way to intercept that scnanning data in order to save a battery and not running a service that manually performs scans, as the Android Beacon Library from Radius Network does?

Android Permission Denial starting Intent for Wallpaper Settings

Unfortunately when I try to run my wallpaper I get an error message saying Permission Denial starting Intent and requires android.permission.BIND_WALLPAPER but I can't seem to figure out why. My manifest looks like the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.package">
<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:exported="true"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:permission="android.permission.BIND_WALLPAPER">
<service
android:name="WallpaperService"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="#xml/livewallpaper" />
</service>
<activity
android:name=".WallpaperSetClass"
android:exported="true"
android:permission="android.permission.BIND_WALLPAPER"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The live wallpaper does run perfectly if I set it through the live wallpaper part of my phone, but I would like to have a settings area as well to be able to open in which I can't.
At the moment my settings class is basically empty containing just an onCreate function and a layout with a button.
Is there something I'm missing? I seem to have the permissions along with android:exported
Turns out I had
android:permission="android.permission.BIND_WALLPAPER"
In the wrong spot, it should be in the service tag, and only have ONE, having multiple will break it.

Android mobile app always get restarted once it is connected or disconnected to bluetooth device

We have Android native multiple tab barcode application which contains barcode field for Bluetooth device to enter the barcode. When lunch this mobile, it first have one popup to let user to select the tab. The problem is that every time when the bluetooth device is connected or disconnected to the mobile, the application always get re-lunched with this popup. How can we stop mobile to re-start when the bluetooth device is connected or disconnected?
I'm attaching the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mentor.med.mobile"
android:versionCode="1"
android:versionName="1.0.1" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CAMERA" />
<application
android:allowBackup="true"
android:icon="#drawable/med"
android:label="#string/app_name"
android:screenOrientation="sensorPortrait"
android:theme="#style/AppTheme" >
<activity
android:name="com.pdx.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan"
android:launchMode="singleTop"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http" android:host="pdx.com" android:path="/view" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="landscape"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
The application probably registers a broadcast receiver, which listens for bluetooth devices being connected. That receiver then launches the Activity with a popup. You have a few options:
One solution could be to remove the entry in the manifest file which registers the intent filter to a receiver (it could be an activity). But obviously then the app will never launch automatically when Bluetooth devices are connected.
Alternatively, you probably want to change the logic of the receiver so it checks if the activity is already open before re-opening it. One way would be to do this in the Activity itself: depending on how you want the application to behave, you may need to change launchMode="singleTop", and use override methods such as isFinishing(), onNewIntent() to determine if the application is restarting and why.

Broadcast receiver is not stopping

i am working on an app that will automatically decline incoming calls from specific numbers and send an sms in return.my broadcast receiver should be enabled from my app only.
so, i added ( android:enabled="false" ) this. but, the receiver is still on by default. i'm struck here.
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.sifydy.automsgr.Automsgr"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.sifydy.automsgr.Receiver"
android:label="#string/app_name"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
wen i switch on my mobile, my receiver is also activated wen ever there is an incoming call.
i am able disable it from my app. everything is fine once i am in my app. how to disble it by default?

Categories

Resources