android - My broadcast receiver class not responding for volume button press? -


i'm using broadcast receiver on volume button press creating shortcut call. broadcast receiver not responding volume button press , not getting exception also.

here androidmanifest.xml class

<receiver android:name="com.abc.utilities.callbroadcastreceiver" >         <intent-filter>             <action android:name="android.media.volume_changed_action" />         </intent-filter> </receiver> 

my broadcastreceiver class

@override public void onreceive(context context, intent intent) {     // todo auto-generated method stub     if(intent.getaction().equals("android.media.volume_changed_action")){                     lod.d("broadcast", "volume button pressed.");      } } 

i try code want , it's work.

1) defined broacastreceiver in manifest :

... <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <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>     </activity>      <receiver android:name="com.example.test.callbroadcastreceiver" >         <intent-filter>             <action android:name="android.media.volume_changed_action" />         </intent-filter>     </receiver> </application> ... 

2) created callbroadcastreceiver :

package com.example.test;  import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.util.log;  public class callbroadcastreceiver extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {         int volume = (integer)intent.getextras().get("android.media.extra_volume_stream_value");         log.i("tag", "action : "+ intent.getaction() + " / volume : "+volume);           }  } 

you don't need check value of action of intent because broadcastreceiver listened volume_changed_action. if checked value of action it's android.media.volume_changed_action.

after, try app in nexus 6, it's possible problem comes phone.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -