I try to code what you want and it's work.
1) I defined my BroacastReceiver in manifest like that :
...
<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) I 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 to check the value of the Action of your intent because your BroadcastReceiver just listened VOLUME_CHANGED_ACTION
. But if you checked the value of your action it's android.media.VOLUME_CHANGED_ACTION
.
After, I try this app in my Nexus 6, it's possible that the problem comes from the phone.