Android getResources().getDrawable() deprecated API 22

You have some options to handle this deprecation the right (and future proof) way, depending on which kind of drawable you are loading: A) drawables with theme attributes ContextCompat.getDrawable(getActivity(), R.drawable.name); You’ll obtain a styled Drawable as your Activity theme instructs. This is probably what you need. B) drawables without theme attributes ResourcesCompat.getDrawable(getResources(), R.drawable.name, null); You’ll … Read more

How to handle ClickEvent for handset buttons in Android

There’s a simpler way which doesn’t require any BroadcastReceiver to be registered if you only want to listen for headset button callbacks while your app (particular activity) is running, simply override Activity onKeyDown method: @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_HEADSETHOOK){ //handle click return true; } return super.onKeyDown(keyCode, event); } For … Read more