Android: Backspace in WebView/BaseInputConnection

Ok, finally figured this out. In Android 4.2 (maybe in earlier versions as well) the backspace is not sent as a sendKeyEvent(…, KeyEvent.KEYCODE_DEL) by the standard soft keyboard. Instead, it is sent as deleteSurroundingText(1, 0). So the solution in my case is to make a custom InputConnection with the following: @Override public boolean deleteSurroundingText(int beforeLength, … Read more

is it possible to hide the system bar

You can’t hide it but you can disable it, except home. For that you can give your application as home category and let the user choose. <category android:name=”android.intent.category.HOME” /> Rest all can be disable. add this in manifest. <uses-permission android:name=”android.permission.EXPAND_STATUS_BAR”/> inside onCreate() this.requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_home); View v = findViewById(R.id.home_view); v.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); where home_view is the … Read more

READ_LOGS permission on Jelly Bean (api 16)

You can obtain the permission on a rooted device by executing the pm grant command from your app. Probably you will have to restart the app after that for the change to take effect, though: String pname = getPackageName(); String[] CMDLINE_GRANTPERMS = { “su”, “-c”, null }; if (getPackageManager().checkPermission(android.Manifest.permission.READ_LOGS, pname) != 0) { Log.d(TAG, “we … Read more

Jelly Bean DatePickerDialog — is there a way to cancel?

Note: Fixed as of Lollipop, source here. Automated class for use in clients (compatible with all Android versions) updated as well. TL;DR: 1-2-3 dead easy steps for a global solution: Download this class. Implement OnDateSetListener in your activity (or change the class to suit your needs). Trigger the dialog with this code (in this sample, … Read more

How to change the background color of Action Bar’s Option Menu in Android 4.2?

In case people are still visiting for a working solution, here is what worked for me:– This is for Appcompat support library. This is in continuation to ActionBar styling explained here Following is the styles.xml file. <resources> <!– Base application theme. –> <style name=”AppTheme” parent=”Theme.AppCompat.Light”> <!– This is the styling for action bar –> <item … Read more

Android Speech Recognition as a service on Android 4.1 & 4.2

This is a work around for android version 4.1.1. public class MyService extends Service { protected AudioManager mAudioManager; protected SpeechRecognizer mSpeechRecognizer; protected Intent mSpeechRecognizerIntent; protected final Messenger mServerMessenger = new Messenger(new IncomingHandler(this)); protected boolean mIsListening; protected volatile boolean mIsCountDownOn; private boolean mIsStreamSolo; static final int MSG_RECOGNIZER_START_LISTENING = 1; static final int MSG_RECOGNIZER_CANCEL = 2; @Override … Read more