android


how to receive intent from headset button


The simple question is how to receive intent from headset button? I have searched for a while and nothing worked out.
My app aims on API 15-25
in Manifest
<activity
android:name=".Home"
android:windowSoftInputMode="stateAlwaysHidden"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action
android:name="com.example.action.PAUSE_PLAY_INTENT_FILTER" />
//this should be unique string as action
<action
android:name="com.example.action.NEXT_TRACK_INTENT_FILTER" />
//this should be unique string as action
<action
android:name="com.example.action.PREVIOUS_TRACK_INTENT_FILTER"
/>
//this should be unique string as action
<action android:name="android.media.VOLUME_CHANGED_ACTION" />
<action
android:name="com.example.action.UPDATE_ALL_LISTS_IN_APP" />
//this should be unique string as action/>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</activity>
in onCreate in Activity
IntentFilter mediaIntent = new IntentFilter();
mediaIntent.addAction(Intent.ACTION_MEDIA_BUTTON);
mediaIntent.setPriority(999999999);
registerReceiver(mMemoryStorage.mBroadcastReceiver, mediaIntent);
and in onReceive in BroadcastReceiver
String intentAction = intent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)){
KeyEvent event = (KeyEvent) intent
.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
int keycode = event.getKeyCode();
int action = event.getAction();
Log.i("keycode", String.valueOf(keycode));
Log.i("action", String.valueOf(action));
//onKeyDown(keyCode, event)
if (keycode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE
|| keycode == KeyEvent.KEYCODE_HEADSETHOOK&&action == KeyEvent.ACTION_DOWN) {
if(mMemoryStorage!=null){
System.out.println("playpause");
if(mMemoryStorage.musicSrv.isPng()){
mMemoryStorage.musicSrv.pausePlayer();
mMemoryStorage.musicSrv.updateNotification();
} else if(mMemoryStorage.musicSrv.isPaused){
mMemoryStorage.musicSrv.playPlayer();
mMemoryStorage.musicSrv.updateNotification();
}
//update seekbar playback in PlaySongFragment
Message message = new Message();
message.what = Params.UPDATE_SEEKBAR_PLAYSONGFRAGMENT;
mMemoryStorage.mHandler.sendMessage(message);
}
}

Related Links

Filter LogCat to get only the messages from My Application
Handle Android Back Button on Phonegap InAppBrowser
Android:Youtube Player
Android : How do i style a DatePicker and TimePicker?
How to getExtra() after an intent of FileChooser?
corona movieclip is not appearing on device
Prevent logout of the application on backpressed
intel x86 emulator accelerator not compatible with linux
android visibility if onpostexecute
android-TextView setText in Html.fromHtml to display image and text [duplicate]
App crash while getting data from database
android app running in background with timer task,suddenly stop the task
Using PhoneGap within Visual Studio
How to create different layout for Galaxy S4 and Nexus 4
How to create a string resource programatically
Stop a service at specific time

Categories

HOME
cygwin
fabricjs
scikit-learn
gdb
cheerio
developer-tools
linkedin
jmeter
sh
nuget
spring-data-mongodb
mips
onclick
elasticsearch-5
fhir
why3
angular-dart
libc
favicon
android-intent
qsqlquery
do-while
altera
null-pointer
symbols
squashfs
backpack-for-laravel
ember-cli
exploit
dapper-extensions
custom-post-type
appirater
apktool
angular-translate
bringtofront
sqsh
testcomplete
custom-controls
volatile
paragraph
android-sugarorm
reactjs.net
python-import
sql-delete
latitude-longitude
timing
filesystemwatcher
odroid
ods
cin
mongoose-schema
news
microsoft-metro
xmldocument
memory-mapping
puredata
openrasta
reportservice2010
mongotemplate
reindex
azure-cli
oracleclient
ngmaterial
juice-ui
gets
node-request
adafruit
watch-os-2
neon
delta
cifilter
createprocess
html-to-pdf
phpgrid
opl
coda
batik
uncompress
diff3
mruby
primitive-types
browserify-shim
ghcjs
contrast
spy++
genymotion-call
build-script
artemis
http-patch
pclzip
onload-event
cascadingdropdown
apache-abdera
android-loadermanager
faye
pyunit
predicatebuilder
agility.js
entitydatasource
mtu
metaweblog
undefined-index
silent
application-verifier
scrollbars
blender-2.49

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App