Android Question when you press the volume down button or increase the volume, this executes an event in a service

jose luis gudino

Active Member
Licensed User
Longtime User
Hi
There is a function in which when you press the volume down button or increase the volume, this executes an event in a service that is running in the background? I plan to make a security application in which if the user presses the volume down button 5 times a notification will be generated

Thanks in advance
 

DonManfred

Expert
Licensed User
Longtime User
Try to setup a intentfilter
B4X:
<receiver android:name="com.example.myproject.receivers.MyReceiver" >
     <intent-filter>
          <action android:name="android.media.VOLUME_CHANGED_ACTION" />
     </intent-filter>
</receiver>

Or a broadcastreceiver
B4X:
public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) {
            Log.d("Music Stream", "has changed");       
        }
    }
}
 
Upvote 0
Top