Java tutorial
//package com.java2s; import android.content.ComponentName; import android.media.AudioManager; import android.util.Log; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { private static final String TAG = "MediaButtonHelper"; static Method sMethodUnregisterMediaButtonEventReceiver; @SuppressWarnings("unused") public static void unregisterMediaButtonEventReceiverCompat(AudioManager audioManager, ComponentName receiver) { if (sMethodUnregisterMediaButtonEventReceiver == null) return; try { sMethodUnregisterMediaButtonEventReceiver.invoke(audioManager, receiver); } catch (InvocationTargetException e) { // Unpack original exception when possible Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } else { // Unexpected checked exception; wrap and re-throw throw new RuntimeException(e); } } catch (IllegalAccessException e) { Log.e(TAG, "IllegalAccessException invoking unregisterMediaButtonEventReceiver."); e.printStackTrace(); } } }