Android Useful Tips

Today we are learn some important tips which is use each and every android app.

1. Capitalize Every First letter of a Word in EditText
If any buddy want to capitalize the first letter of every word in a EditText,
assign android:inputType=”textCapWords” to EditText.

The same process by programatically also as shown below.
TextView txtCapitalize = (TextView) findViewById(R.id.txtCapitalize);
txtCapitalize.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);  

2. Hide  the keypad in Android
 public static void hideKeyboard(MainActivity activity) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(MainActivity.INPUT_METHOD_SERVICE);

        View view = activity.getCurrentFocus();

        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }



3.How to  start or stot adb from command line
If you start or stop the adb using the command prompt please follow blow processs

1.first open CMD
Note:-Before you execute the commands in CMD make sure that you added the adb tool to your Environment Variables path.

2.Killing adb
 adb kill-server 

3.Starting adb
 adb start-server  

4. Detect back button press in android
Override the onBackPressed() method and take the action inside this function.
@Override
    public void onBackPressed() {
        // Write code here
        super.onBackPressed();
    }





Android Realm Database with Replacing SQLite & Core Data

Realm is the database solution for proposed as  a replacement for SQLite & Core Data.It persists on its own persistence engine.
Realm is  also cross-platform that supports both iOS and Android, so developers who write Java, Swift, Objective-C can share the same Realm files painlessly.

There are some  advantages of Realm over SQLite:
1. Realm is faster than SQLite
2. it is easy to use
3. object conversion can be handled  easy
4. convenient for creating and storing data on the fly

Realm missing the following features:
1. Realm null support
2. auto incrementing
3. Map support
4. easy migrations
5. notifications on specific data changed
6. compound primary keys

Some important guide for Installation:
Realm is installed as a Gradle plugin.
Installing Realm as a Gradle plugin is a two step process.

Step 1: Add the following class path dependency to the project level build.gradle file.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "io.realm:realm-gradle-plugin:0.90.1"
    }
}

Step 2: Apply the realm-android plugin to the top of application level build.gradle file.


apply plugin: 'realm-android'





Android Text to Speech

Android has also new  feature (from Android 1.6) called Text to Speech (TTS) which speaks the text in different languages. with the help of this tutorial explains how to work with android text to speech In this tutorial i also explained changing the language type and speed level.
In this tutorial, i want to implement TTS in Android and how we can control some interesting aspects of speech engine.

Text to Speech

Now we will learn text to speech step by step

1. first we have to use the TTS in our app is initialise the engine.

engine = new TextToSpeech(this, this);

2. Implement your main Activity class from TextToSpeech.OnInitListener
This listener is used to inform our app that the engine is ready to be used

public class MainActivity extends Activity implements TextToSpeech.OnInitListener {
@Override
    public void onInit(int status) {
      if (status == TextToSpeech.SUCCESS) {
           Log.d(&Speech&, &Success!&);
           engine.setLanguage(Locale.UK);
        } 
      } 
    }


3.Read the words and speech.
Now our engine is ready to be used, we need simply pass the string we want to read. To this purpose, we use an EditText so that the user can edit his string and when he clicks on the microphone the app start reading. Without detailing too much the code because is trivial we focus our attention when user clicks on the microphone button:

 speechButton.setOnClickListener(new View.OnClickListener() { 
     @Override
     public void onClick(View v) {
        speech();
        }
    });

      private void speech() {
          engine.speak("Your text for speech", TextToSpeech.QUEUE_FLUSH, null, null);
        }

5.Control Text to Speech Engine parameters
We can control on engine to read the sentence. We can modify for example the pitch and the speech rat.

engine.setPitch((float) pitch);
engine.setSpeechRate((float) speed);
engine.speak(editText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null, null);









Android N Designing for Multi-Window

Android N  primary mode where users can be create multi-window through split-screen mode, Multi-Window is designing for every devices. user can drag the divider between the two split screens to resize the apps.

The Android Studio 2.1 Supports Android N Developer Preview
The release of Android Studio 2.1 is now available and includes updates to the platform’s IDE wizards, build system and Android Emulator. The Android Studio development team says that the latest release provides access to new features and APIs of the developer preview including the new Jack compiler and Java 8 language support. Android Studio 2.1 includes performance improvements to Instant Run which provides faster edit and deploy build speeds.


Designing a responsive UI is still an important first step towards an amazing multi-window experience.

There are some new features  of Android N
1. Multi-window mode
This is a more advanced feature that Building a responsive UI that reacts to the space available is critical to a great multi-window  experience.

2. New Notifications panel
with the help of this feature  we can just reply within the notification that appears at the top of the screen.

3. Quick Settings Menu
Google has released  new quick settings menu to the notifications shade you pull down from the top.
When pulling the notifications bar down a second time to reveal the quick settings menu.

4. 3D Touch support
Google will be released 3D Touch-style interaction to Android N, reports have confirmed.

The second iteration of the Android N developer preview, which rolled out last week, contained support for 'launcher shortcuts'.

The feature was widely expected to mimic the pressure-sensitive contextual functions introduced by the iPhone 6s, allowing users to launch specific app sub-functions by pressing harder on the screen.

N Developer Preview Support

Android Studio 2.1 release with best support for the new Jack compiler and support for Java 8. With the Jack compiler, lambdas, method references, compile-time type annotations, intersection types and type inference are available on all versions of the Android platform. Default and static methods and repeatable annotations are available on Android N and higher. To use Java 8 language features when developing with the N Developer Preview, developers need to use the Jack compiler.

Instant Run
Developers can access fast edits, builds and deploy cycles with A#336667ndroid Studio 2.0 as Instant Run now can now update incremental changes to app code much faster. Instant Run and general build speed are now faster due to two new features - incremental Java compilation and in-process dex.

Android Marshmallow for Developer

Google has also released  the Android version 23 APIs called Android 6.0 Marshmallow.Android Marshmallow was initially announced at Google I/O on May 28.

 It was released as the Android M preview for developer.The Android M developer preview gave developers a clear timeline to test their apps, and an opportunity to explore the new features the latest version of Android has to offer

There are some new features for android Marshmallow.

1. Fingerprint Authentication 
 for using this feature in your app first you need to add the  USE_FINGERPRINT permission in your  app.
2. Lock screen 
 Android Marshmallow add  the dialer shortcut with one to Google’s voice search on lock screen. 
3. Notifications Upgrade 
 This new feature use  NotificationManager.getActiveNotifications() method that allows your apps to  find out which of their notifications are currently alive
4. USB Type-C 
 This feature is silly-fast, can be used any way up – and it’s going to be the most commonly used  connection in the next few years. What’s more, it also allow for much faster charging than  conventional cables: it can fully charge a Nexus 6P in around two hours.
5. System UI Tuner
 Once enabled, System UI Tuner will appear in the settings menu at the very bottom. It provides a  few simple UI tweaks, including adding a battery percentage indicator to your battery icon, a  customizable Quick Settings area.
.App search bar and favourites
 In order to help those who think the new apps menu is worse, and there will be some, there are some  extra features to the apps area. First, there’s a search bar up at the top.


there are some small upgradation  in  Android Marshmallow
1. Bluetooth Stylus Support
2. Bluetooth Low Energy Scanning
3. Video
4. Audio
5.Camera