I have a bluetooth headset which is able to communicate with my phone. It has one large 'call' button which answers/ends calls.
I am trying to make an app which will be able to intercept when the call button is pressed. I have tried using an intent filter:
<receiver android:name=".MediaButtonIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
but the call button does not appear to be classified as a media_button
any ideas on how I can achieve this? I would just like to know when the call button is pressed
try
android.intent.action.CALL_BUTTON
http://developer.android.com/reference/android/content/Intent.html#ACTION_CALL_BUTTON
I'm not sure about it.. I think it fires for all call buttons, including any physical call buttons on the phone and buttons on the headsets .etc.
If the button is currently bringing up the Voice Dialer (mine does), you want ACTION_VOICE_COMMAND. Add the following to your intent filter:
<action android:name="android.intent.action.VOICE_COMMAND" />
<category android:name="android.intent.category.DEFAULT" />
Related
I need to catch longpress event of media button even when the device is locked or the app is in background. onKey listener does not work for apps in background. I have a working example with BroadcastReceiver, but it only works for short press. I am using AudioManager to register the receiver. What i can see in console when i press the button for a long time is this:
I/MediaSessionService(684): voice-based interactions: about to use ACTION_WEB_SEARCH
I/ActivityManager(684): START u0 {act=android.speech.action.WEB_SEARCH flg=0x10800000} from uid 1000 on display 0
So i have tried listening to ACTION_WEB_SEARCH by context.registerReceiver() method with no success. I also added receiver with intent-filter into manifest file.
Is there any other way i could try? Or does anyone know about a working solution? I have been searching and testing this one functionality for 5 days now and i am getting really angry. =D
I found the answer for the exact same issue you describe here.
All you need to do is add intent-filter to an activity you want to start by long pressing the media button.
WEB_SEARCH is called when the screen is unlocked.
VOICE_SEARCH_HANDS_FREE is called when the screen is locked.
Manifest file with added actions to the MainActivity:
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter android:priority="1000000">
<action android:name="android.speech.action.VOICE_SEARCH_HANDS_FREE" />
<action android:name="android.speech.action.WEB_SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The first time you launch your app and long press the button a small dialog box on the bottom of the screen will appear. The dialog box asks if you want to complete the action with the Google app or your own app, they both listen to the same actions.
Don't forget to add this in your Activity or it will not show on your lockscreen.
#Override
public void onAttachedToWindow() {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}
i have tried different approaches to disable hardware home button through key-guard and key-down. it didn't work, i want functionality like Go-locker app. when i press on home button activity didn't close. please give me any idea about it. Thanks in advance.
Write this Intent filter in manifest in tag of your activity
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Because the security reason, if any app can disable Home button, and also disables back button (onbackpress()), power button (by on/off receiver), so the app will never be killed, and your phone just shows the app. I think Go-locker has customed their laucher, you can do it, but i think it is not easy.
Regards !
I want to write a screen capture app, but I don't know how to trigger my app globally by special action such as shaking the device or long press a button or anything else. Which means bring up my app under any app any time. Is there any suggestion?
You'll need to use a reciever for that. For example, if you wanted the app to start activity MyReciever when the phone boots up, you could do the following:
<receiver android:name=".MyReceiver">
<intent-filter >
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I am working on an application in which I have to make call from my application using my PHP server.
I have a condition in which, whenever user presses the Green call button of Android Device and after dialing number, I have to give user an option to call from my App or normal SIM. I have done that too.
Now I want to get the number which I have dialed on the dialer before switching to the application.
Means if User selects my application to call then I must have number dialed on the phone Dial.
I am using the below code to generate the pop up to use my application for calling. The code is written as Intent filter in my manifest inside the specific activity.
<activity
android:name="com.tv.longdistcall.PlaceLongDistCall"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Please suggest me, how to get the number dialed on the dialer before switching to the activity.
You need to create a new BroadcastReceiver with NEW_OUTGOING_CALL intent filter. This receiver intercepts every call to CALL_PRIVILEGED or CALL actions on the device regardless of what app is the one targeted.
The destination number can be found on the receiver's intent extras in Intent.EXTRA_PHONE_NUMBER.
I'm working on an Android application which needs to perform an action each time a new image is taken with the phone. I don't want to take the image within my application, but rather perform some action when the Camera app takes an image and saves it to the SD card. Right now, I've gotten a BroadcastReceiver implemented that's currently listening for "android.intent.action.CAMERA_BUTTON". However, this doesn't seem to get called when I'm wanting it to. I've tried to debug the application on my own phone with a linebreak on the first line of the BroadcastReceiver's OnReceive method, but it never reaches that code.
Does anyone know what the correct intent for which I should be listening is? Or is using a BroadcastReceiver not even the best way to do this? (For example, is there a better way to accomplish this such as listening for when a new image is saved to the card)?
Thanks!
Update: I do have a Trackball on my phone (HTC Eris), so is it possible that taking photos that way doesn't get sent as "Camera Button"? If so, is there a workaround for a phone without a "Camera Button", but rather something like a Trackball?
Right now, I've gotten a BroadcastReceiver implemented that's currently listening for "android.intent.action.CAMERA_BUTTON". However, this doesn't seem to get called when I'm wanting it to.
That only gets broadcast if the foreground activity does not consume the event.
Quite an old question, if anyone still needs the solution try using
android.hardware.action.NEW_PICTURE
as your intent filter
<!-- Receiver for camera clicks -->
<receiver
android:name=".receivers.CameraEventReceiver"
android:label="CameraEventReceiver">
<intent-filter>
<!-- <action android:name="com.android.camera.NEW_PICTURE" /> -->
<action android:name="android.hardware.action.NEW_PICTURE" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
It will return the Uri of the image in intent.getData() of its onReceive() function
Hope it helps
try this one this works for me
<receiver android:name=".pictureReceiver" >
<intent-filter android:priority="10000" >
<action android:name="android.intent.action.CAMERA_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>