Android – Developer Tools ”; Previous Next The android developer tools let you create interactive and powerful application for android platform. The tools can be generally categorized into two types. SDK tools Platform tools SDK tools SDK tools are generally platform independent and are required no matter which android platform you are working on. When you install the Android SDK into your system, these tools get automatically installed. The list of SDK tools has been given below − Sr.No Tool & description 1 android This tool lets you manage AVDs, projects, and the installed components of the SDK 2 ddms This tool lets you debug Android applications 3 Draw 9-Patch This tool allows you to easily create a NinePatch graphic using a WYSIWYG editor 4 emulator This tools let you test your applications without using a physical device 5 mksdcard Helps you create a disk image (external sdcard storage) that you can use with the emulator 6 proguard Shrinks, optimizes, and obfuscates your code by removing unused code 7 sqlite3 Lets you access the SQLite data files created and used by Android applications 8 traceview Provides a graphical viewer for execution logs saved by your application 9 Adb Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. We will discuss three important tools here that are android,ddms and sqlite3. Android Android is a development tool that lets you perform these tasks: Manage Android Virtual Devices (AVD) Create and update Android projects Update your sdk with new platform add-ons and documentation android [global options] action [action options] DDMS DDMS stands for Dalvik debug monitor server, that provide many services on the device. The service could include message formation, call spoofing, capturing screenshot, exploring internal threads and file systems e.t.c Running DDMS From Android studio click on Tools>Android>Android device Monitor. How it works In android, each application runs in its own process and each process run in the virtual machine. Each VM exposes a unique port, that a debugger can attach to. When DDMS starts, it connects to adb. When a device is connected, a VM monitoring service is created between adb and DDMS, which notifies DDMS when a VM on the device is started or terminated. Making SMS Making sms to emulator.we need to call telnet client and server as shown below Now click on send button, and you will see an sms notification in the emulator window. It is shown below − Making Call In the DDMS, select the Emulator Control tab. In the emulator control tab , click on voice and then start typing the incoming number. It is shown in the picture below − Now click on the call button to make a call to your emulator. It is shown below − Now click on hangup in the Android studio window to terminate the call. The fake sms and call can be viewed from the notification by just dragging the notification window to the center using mouse. It is shown below − Capturing ScreenShot You can also capture screenshot of your emulator. For this look for the camera icon on the right side under Devices tab. Just point your mouse over it and select it. As soon as you select it , it will start the screen capturing process and will capture whatever screen of the emulator currently active. It is shown below − The eclipse orientation can be changed using Ctrl + F11 key. Now you can save the image or rotate it and then select done to exit the screen capture dialog. Sqlite3 Sqlite3 is a command line program which is used to manage the SQLite databases created by Android applications. The tool also allow us to execute the SQL statements on the fly. There are two way through which you can use SQlite , either from remote shell or you can use locally. Use Sqlite3 from a remote shell. Enter a remote shell by entering the following command − adb [-d|-e|-s {<serialNumber>}] shell From a remote shell, start the sqlite3 tool by entering the following command − sqlite3 Once you invoke sqlite3, you can issue sqlite3 commands in the shell. To exit and return to the adb remote shell, enter exit or press CTRL+D. Using Sqlite3 directly Copy a database file from your device to your host machine. adb pull <database-file-on-device> Start the sqlite3 tool from the /tools directory, specifying the database file − sqlite3 <database-file-on-host> Platform tools The platform tools are customized to support the features of the latest android platform. The platform tools are typically updated every time you install a new SDK platform. Each update of the platform tools is backward compatible with older platforms. Some of the platform tools are listd below − Android Debug bridge (ADB) Android Interface definition language (AIDL) aapt, dexdump , and dex e.t.c Print Page Previous Next Advertisements ”;
Category: Android
Android Questions and Answers ”; Previous Next Android Questions and Answers has been designed with a special intention of helping students and professionals preparing for various Certification Exams and Job Interviews. This section provides a useful collection of sample Interview Questions and Multiple Choice Questions (MCQs) and their answers with appropriate explanations. SN Question/Answers Type 1 Android Interview Questions This section provides a huge collection of Android Interview Questions with their answers hidden in a box to challenge you to have a go at them before discovering the correct answer. 2 Android Online Quiz This section provides a great collection of Android Multiple Choice Questions (MCQs) on a single page along with their correct answers and explanation. If you select the right option, it turns green; else red. 3 Android Online Test If you are preparing to appear for a Java and Android Framework related certification exam, then this section is a must for you. This section simulates a real online test along with a given timer which challenges you to complete the test within a given time-frame. Finally you can check your overall test score and how you fared among millions of other candidates who attended this online test. 4 Android Mock Test This section provides various mock tests that you can download at your local machine and solve offline. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself. Print Page Previous Next Advertisements ”;
Android – ProgressBar
Android Progress Bar using ProgressDialog ”; Previous Next Progress bars are used to show progress of a task. For example, when you are uploading or downloading something from the internet, it is better to show the progress of download/upload to the user. In android there is a class called ProgressDialog that allows you to create progress bar. In order to do this, you need to instantiate an object of this class. Its syntax is. ProgressDialog progress = new ProgressDialog(this); Now you can set some properties of this dialog. Such as, its style, its text etc. progress.setMessage(“Downloading Music 🙂 “); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setIndeterminate(true); Apart from these methods, there are other methods that are provided by the ProgressDialog class Sr. No Title & description 1 getMax() This method returns the maximum value of the progress. 2 incrementProgressBy(int diff) This method increments the progress bar by the difference of value passed as a parameter. 3 setIndeterminate(boolean indeterminate) This method sets the progress indicator as determinate or indeterminate. 4 setMax(int max) This method sets the maximum value of the progress dialog. 5 setProgress(int value) This method is used to update the progress dialog with some specific value. 6 show(Context context, CharSequence title, CharSequence message) This is a static method, used to display progress dialog. Example This example demonstrates the horizontal use of the progress dialog which is in fact a progress bar. It display a progress bar on pressing the button. To experiment with this example, you need to run this on an actual device after developing the application according to the steps below. Steps Description 1 You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication. 2 Modify src/MainActivity.java file to add progress code to display the progress dialog. 3 Modify res/layout/activity_main.xml file to add respective XML code. 4 Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.java. package com.example.sairamkrishna.myapplication; import android.app.ProgressDialog; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends ActionBarActivity { Button b1; private ProgressDialog progress; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button2); } public void download(View view){ progress=new ProgressDialog(this); progress.setMessage(“Downloading Music”); progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progress.setIndeterminate(true); progress.setProgress(0); progress.show(); final int totalProgressTime = 100; final Thread t = new Thread() { @Override public void run() { int jumpTime = 0; while(jumpTime < totalProgressTime) { try { sleep(200); jumpTime += 5; progress.setProgress(jumpTime); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; t.start(); } } Modify the content of res/layout/activity_main.xml to the following − <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/textView” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” android:textSize=”30dp” android:text=”Progress bar” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorials Point” android:id=”@+id/textView2″ android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” android:textSize=”35dp” android:textColor=”#ff16ff01″ /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Download” android:onClick=”download” android:id=”@+id/button2″ android:layout_marginLeft=”125dp” android:layout_marginStart=”125dp” android:layout_centerVertical=”true” /> </RelativeLayout> This is the default AndroidManifest.xml − <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.sairamkrishna.myapplication” > <application android:allowBackup=”true” android:icon=”@mipmap/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”.MainActivity” android:label=”@string/app_name” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Let”s try to run your application. We assume, you have connected your actual Android Mobile device with your computer. To run the app from Android studio, open one of your project”s activity files and click Run icon from the toolbar. Before starting your application, Android studio will display following window to select an option where you want to run your Android application. Select your mobile device as an option and then check your mobile device which will display following screen − Just press the button to start the Progress bar. After pressing, following screen would appear − It will continuously update itself. Print Page Previous Next Advertisements ”;
Android – ImageSwitcher
Android – Image Switcher ”; Previous Next Sometimes you don”t want an image to appear abruptly on the screen, rather you want to apply some kind of animation to the image when it transitions from one image to another. This is supported by android in the form of ImageSwitcher. An image switcher allows you to add some transitions on the images through the way they appear on screen. In order to use image Switcher, you need to define its XML component first. Its syntax is given below − <ImageSwitcher android:id=”@+id/imageSwitcher1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_centerHorizontal=”true” android:layout_centerVertical=”true” > </ImageSwitcher> Now we create an intance of ImageSwithcer in java file and get a reference of this XML component. Its syntax is given below − private ImageSwitcher imageSwitcher; imageSwitcher = (ImageSwitcher)findViewById(R.id.imageSwitcher1); The next thing we need to do implement the ViewFactory interface and implement unimplemented method that returns an imageView. Its syntax is below − imageSwitcher.setImageResource(R.drawable.ic_launcher); imageSwitcher.setFactory(new ViewFactory() { public View makeView() { ImageView myView = new ImageView(getApplicationContext()); return myView; } } The last thing you need to do is to add Animation to the ImageSwitcher. You need to define an object of Animation class through AnimationUtilities class by calling a static method loadAnimation. Its syntax is given below − Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left); imageSwitcher.setInAnimation(in); imageSwitcher.setOutAnimation(out); The method setInAnimaton sets the animation of the appearance of the object on the screen whereas setOutAnimation does the opposite. The method loadAnimation() creates an animation object. Apart from these methods, there are other methods defined in the ImageSwitcher class. They are defined below − Sr.No Method & description 1 setImageDrawable(Drawable drawable) Sets an image with image switcher. The image is passed in the form of bitmap 2 setImageResource(int resid) Sets an image with image switcher. The image is passed in the form of integer id 3 setImageURI(Uri uri) Sets an image with image switcher. THe image is passed in the form of URI 4 ImageSwitcher(Context context, AttributeSet attrs) Returns an image switcher object with already setting some attributes passed in the method 5 onInitializeAccessibilityEvent (AccessibilityEvent event) Initializes an AccessibilityEvent with information about this View which is the event source 6 onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info) Initializes an AccessibilityNodeInfo with information about this view Example The below example demonstrates some of the image switcher effects on the bitmap. It crates a basic application that allows you to view the animation effects on the images. To experiment with this example , you need to run this on an actual device. Steps Description 1 You will use Android studio IDE to create an Android application under a package com.example.sairamkrishna.myapplication. 2 Modify src/MainActivity.java file to add necessary code. 3 Modify the res/layout/activity_main to add respective XML components 4 Run the application and choose a running android device and install the application on it and verify the results Following is the content of the modified main activity file src/MainActivity.java. In the below code tp and abc indicates the logo of tutorialspoint.com package com.example.sairamkrishna.myapplication; import android.app.Activity; import android.app.ActionBar.LayoutParams; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.Toast; import android.widget.ViewSwitcher.ViewFactory; public class MainActivity extends Activity { private ImageSwitcher sw; private Button b1,b2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1 = (Button) findViewById(R.id.button); b2 = (Button) findViewById(R.id.button2); sw = (ImageSwitcher) findViewById(R.id.imageSwitcher); sw.setFactory(new ViewFactory() { @Override public View makeView() { ImageView myView = new ImageView(getApplicationContext()); myView.setScaleType(ImageView.ScaleType.FIT_CENTER); myView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); return myView; } }); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), “previous Image”, Toast.LENGTH_LONG).show(); sw.setImageResource(R.drawable.abc); } }); b2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), “Next Image”, Toast.LENGTH_LONG).show(); sw.setImageResource(R.drawable.tp); } }); } } Following is the modified content of the xml res/layout/activity_main.xml. <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:text=”Gestures Example” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/textview” android:textSize=”35dp” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorials point” android:id=”@+id/textView” android:layout_below=”@+id/textview” android:layout_centerHorizontal=”true” android:textColor=”#ff7aff24″ android:textSize=”35dp” /> <ImageSwitcher android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageSwitcher” android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” android:layout_marginTop=”168dp” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/left” android:id=”@+id/button” android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/right” android:id=”@+id/button2″ android:layout_alignParentBottom=”true” android:layout_alignLeft=”@+id/button” android:layout_alignStart=”@+id/button” /> </RelativeLayout> Following is the content of Strings.xml file. <resources> <string name=”app_name”>My Application</string> <string name=”left”><![CDATA[<]]></string> <string name=”right”><![CDATA[>]]></string> </resources> Following is the content of AndroidManifest.xml file. <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.sairamkrishna.myapplication” <application android:allowBackup=”true” android:icon=”@drawable/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”com.example.sairamkrishna.myapplication.MainActivity” android:label=”@string/app_name” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Let”s try to run your application we just modified. I assume you had created your AVD while doing environment setup. To run the app from Android studio, open one of your project”s activity files and click Run icon from the toolbar. Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window − Now if you will look at your device screen , you will see the two buttons. Now just select the upper button that right arrow. An image would appear from right and move towards left. It is shown below − Now tap on the below button, that will bring back the previous image with some transition. It is shown below − Print Page Previous Next Advertisements ”;
Android – AudioManager
Android – Audio Manager ”; Previous Next You can easily control your ringer volume and ringer profile i-e:(silent,vibrate,loud e.t.c) in android. Android provides AudioManager class that provides access to these controls. In order to use AndroidManager class, you have to first create an object of AudioManager class by calling the getSystemService() method. Its syntax is given below. private AudioManager myAudioManager; myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); Once you instantiate the object of AudioManager class, you can use setRingerMode method to set the audio or ringer profile of your device. Its syntax is given below. myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); The method setRingerMode takes an integer number as a parameter. For each mode , an integer number is assigned that will differentiate between different modes. The possible modes are. Sr.No Mode & Description 1 RINGER_MODE_VIBRATE This Mode sets the device at vibrate mode. 2 RINGER_MODE_NORMAL This Mode sets the device at normal(loud) mode. 3 RINGER_MODE_SILENT This Mode sets the device at silent mode. Once you have set the mode , you can call the getRingerMode() method to get the set state of the system. Its syntax is given below. int mod = myAudioManager.getRingerMode(); Apart from the getRingerMode method, there are other methods available in the AudioManager class to control the volume and other modes. They are listed below. Sr.No Method & description 1 adjustVolume(int direction, int flags) This method adjusts the volume of the most relevant stream 2 getMode() This method returns the current audio mode 3 getStreamMaxVolume(int streamType) This method returns the maximum volume index for a particular stream 4 getStreamVolume(int streamType) This method returns the current volume index for a particular stream 5 isMusicActive() This method checks whether any music is active. 6 startBluetoothSco() This method Start bluetooth SCO audio connection 7 stopBluetoothSco() This method stop bluetooth SCO audio connection. Example The below example demonstrates the use of AudioManager class. It creates a application that allows you to set different ringer modes for your device. To experiment with this example , you need to run this on an actual device. Steps Description 1 You will use Android studio IDE to create an Android application under a package com.example.sairamkrishna.myapplication. 2 Modify src/MainActivity.java file to add AudioManager code 3 Modify layout XML file res/layout/activity_main.xml add any GUI component if required. 4 Modify res/values/string.xml file and add necessary string components. 5 Modify AndroidManifest.xml to add necessary permissions. 6 Run the application and choose a running android device and install the application on it and verify the results. Here is the content of src/MainActivity.java package com.example.sairamkrishna.myapplication; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { Button mode,ring,vibrate,silent; private AudioManager myAudioManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vibrate=(Button)findViewById(R.id.button3); ring=(Button)findViewById(R.id.button2); mode=(Button)findViewById(R.id.button); silent=(Button)findViewById(R.id.button4); myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); vibrate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); Toast.makeText(MainActivity.this,”Now in Vibrate Mode”, Toast.LENGTH_LONG).show(); } }); ring.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); Toast.makeText(MainActivity.this,”Now in Ringing Mode”, Toast.LENGTH_LONG).show(); } }); silent.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); Toast.makeText(MainActivity.this,”Now in silent Mode”, Toast.LENGTH_LONG).show(); } }); mode.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int mod=myAudioManager.getRingerMode(); if(mod==AudioManager.RINGER_MODE_VIBRATE){ Toast.makeText(MainActivity.this,”Now in Vibrate Mode”, Toast.LENGTH_LONG).show(); } else if(mod==AudioManager.RINGER_MODE_NORMAL){ Toast.makeText(MainActivity.this,”Now in Ringing Mode”, Toast.LENGTH_LONG).show(); } else { Toast.makeText(MainActivity.this,”Now in Vibrate Mode”, Toast.LENGTH_LONG).show(); } } }); } } Here is the content of activity_main.xml Here abc indicates the logo of tutorialspoint <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Android Audio Recording” android:id=”@+id/textView” android:textSize=”30dp” android:layout_alignParentTop=”true” android:layout_alignParentRight=”true” android:layout_alignParentEnd=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorialspoint” android:id=”@+id/textView2″ android:textColor=”#ff3eff0f” android:textSize=”35dp” android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” /> <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageView” android:src=”@drawable/abc” android:layout_below=”@+id/textView2″ android:layout_alignLeft=”@+id/textView2″ android:layout_alignStart=”@+id/textView2″ android:layout_alignRight=”@+id/textView2″ android:layout_alignEnd=”@+id/textView2″ /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Mode” android:id=”@+id/button” android:layout_below=”@+id/imageView” android:layout_alignParentLeft=”true” android:layout_alignParentStart=”true” android:layout_marginTop=”59dp” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Ring” android:id=”@+id/button2″ android:layout_alignTop=”@+id/button” android:layout_centerHorizontal=”true” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”vibrate” android:id=”@+id/button3″ android:layout_alignTop=”@+id/button2″ android:layout_alignRight=”@+id/textView” android:layout_alignEnd=”@+id/textView” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Silent” android:id=”@+id/button4″ android:layout_below=”@+id/button2″ android:layout_alignLeft=”@+id/button2″ android:layout_alignStart=”@+id/button2″ /> </RelativeLayout> Here is the content of Strings.xml <resources> <string name=”app_name”>My Application</string> </resources> Here is the content of AndroidManifest.xml <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.sairamkrishna.myapplication” > <application android:allowBackup=”true” android:icon=”@drawable/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”com.example.sairamkrishna.myapplication” android:label=”@string/app_name” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Let”s try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from Android Studio, open one of your project”s activity files and click Run icon from the tool bar. Android studio will display Images Now select silent button, you would get silent icon at Notification bar Now just select the ring button and then press the current mode button to see that if its status has been set. Now press the Vibrate button and then press the current mode button to see that if it is set or not.It will display the following screen. Print Page Previous Next Advertisements ”;
Android – Google Maps
Android – Google Maps ”; Previous Next Android allows us to integrate google maps in our application. You can show any location on the map , or can show different routes on the map e.t.c. You can also customize the map according to your choices. Google Map – Layout file Now you have to add the map fragment into xml layout file. Its syntax is given below − <fragment android:id=”@+id/map” android:name=”com.google.android.gms.maps.MapFragment” android:layout_width=”match_parent” android:layout_height=”match_parent”/> Google Map – AndroidManifest file The next thing you need to do is to add some permissions along with the Google Map API key in the AndroidManifest.XML file. Its syntax is given below − <!–Permissions–> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” /> <uses-permission android:name=”android.permission.INTERNET” /> <uses-permission android:name=”com.google.android.providers.gsf.permission. READ_GSERVICES” /> <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE” /> <!–Google MAP API key–> <meta-data android:name=”com.google.android.maps.v2.API_KEY” android:value=”AIzaSyDKymeBXNeiFWY5jRUejv6zItpmr2MVyQ0″ /> Customizing Google Map You can easily customize google map from its default view , and change it according to your demand. Adding Marker You can place a maker with some text over it displaying your location on the map. It can be done by via addMarker() method. Its syntax is given below − final LatLng TutorialsPoint = new LatLng(21 , 57); Marker TP = googleMap.addMarker(new MarkerOptions() .position(TutorialsPoint).title(“TutorialsPoint”)); Changing Map Type You can also change the type of the MAP. There are four different types of map and each give a different view of the map. These types are Normal,Hybrid,Satellite and terrain. You can use them as below googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID); googleMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); Enable/Disable zoom You can also enable or disable the zoom gestures in the map by calling the setZoomControlsEnabled(boolean) method. Its syntax is given below − googleMap.getUiSettings().setZoomGesturesEnabled(true); Apart from these customization, there are other methods available in the GoogleMap class , that helps you more customize the map. They are listed below − Sr.No Method & description 1 addCircle(CircleOptions options) This method add a circle to the map 2 addPolygon(PolygonOptions options) This method add a polygon to the map 3 addTileOverlay(TileOverlayOptions options) This method add tile overlay to the map 4 animateCamera(CameraUpdate update) This method Moves the map according to the update with an animation 5 clear() This method removes everything from the map. 6 getMyLocation() This method returns the currently displayed user location. 7 moveCamera(CameraUpdate update) This method repositions the camera according to the instructions defined in the update 8 setTrafficEnabled(boolean enabled) This method Toggles the traffic layer on or off. 9 snapshot(GoogleMap.SnapshotReadyCallback callback) This method Takes a snapshot of the map 10 stopAnimation() This method stops the camera animation if there is one in progress Example Here is an example demonstrating the use of GoogleMap class. It creates a basic M application that allows you to navigate through the map. To experiment with this example , you can run this on an actual device or in an emulator. Create a project with google maps activity as shown below − It will open the following screen and copy the console url for API Key as shown below − Copy this and paste it to your browser. It will give the following screen − Click on continue and click on Create API Key then it will show the following screen Here is the content of activity_main.xml. <fragment xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:map=”http://schemas.android.com/apk/res-auto” xmlns:tools=”http://schemas.android.com/tools” android:id=”@+id/map” android:name=”com.google.android.gms.maps.SupportMapFragment” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”com.example.tutorialspoint7.myapplication.MapsActivity” /> Here is the content of MapActivity.java. In the below code we have given sample latitude and longitude details package com.example.tutorialspoint7.myapplication; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. * In this case, we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device. * This method will only be triggered once the user has installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera LatLng TutorialsPoint = new LatLng(21, 57); mMap.addMarker(new MarkerOptions().position(TutorialsPoint).title(“Tutorialspoint.com”)); mMap.moveCamera(CameraUpdateFactory.newLatLng(TutorialsPoint)); } } Following is the content of AndroidManifest.xml file. <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.tutorialspoint7.myapplication”> <!– The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but you must specify either coarse or fine location permissions for the ”MyLocation” functionality. –> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” /> <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” /> <uses-permission android:name=”android.permission.INTERNET” /> <application android:allowBackup=”true” android:icon=”@mipmap/ic_launcher” android:label=”@string/app_name” android:supportsRtl=”true” android:theme=”@style/AppTheme”> <!– The API key for Google Maps-based APIs is defined as a string resource. (See the file “res/values/google_maps_api.xml”). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. –> <meta-data android:name=”com.google.android.geo.API_KEY” android:value=”AIzaSyAXhBdyKxUo_cb-EkSgWJQTdqR0QjLcqes” /> <activity android:name=”.MapsActivity” android:label=”@string/title_activity_maps”> <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Output should be like this − Print Page Previous Next Advertisements ”;
Android – Auto Complete
Android – Auto Complete ”; Previous Next If you want to get suggestions , when you type in an editable text field , you can do this via AutoCompleteTextView. It provides suggestions automatically when the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with. In order to use AutoCompleteTextView you have to first create an AutoCompletTextView Field in the xml. Its syntax is given below. <AutoCompleteTextView android:id=”@+id/autoCompleteTextView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” android:layout_marginTop=”65dp” android:ems=”10″ > After that, you have to get a reference of this textview in java. Its syntax is given below. private AutoCompleteTextView actv; actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); The the next thing you need to do is to specify the list of suggestions items to be displayed. You can specify the list items as a string array in java or in strings.xml. Its syntax is given below. String[] countries = getResources().getStringArray(R.array.list_of_countries); ArrayAdapter<String> adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,countries); actv.setAdapter(adapter); The array adapter class is responsible for displaying the data as list in the suggestion box of the text field. The setAdapter method is used to set the adapter of the autoCompleteTextView. Apart from these methods, the other methods of Auto Complete are listed below. Sr.No Method & description 1 getAdapter() This method returns a filterable list adapter used for auto completion 2 getCompletionHint() This method returns optional hint text displayed at the bottom of the the matching list 3 getDropDownAnchor() This method returns returns the id for the view that the auto-complete drop down list is anchored to. 4 getListSelection() This method returns the position of the dropdown view selection, if there is one 5 isPopupShowing() This method indicates whether the popup menu is showing 6 setText(CharSequence text, boolean filter) This method sets text except that it can disable filtering 7 showDropDown() This method displays the drop down on screen. Example The below example demonstrates the use of AutoCompleteTextView class. It crates a basic application that allows you to type in and it displays suggestions on your device. To experiment with this example , you need to run this on an actual device or in an emulator. Steps Description 1 You will use Android Studio to create an Android application under a package package com.example.sairamkrishna.myapplication. 2 Modify src/MainActivity.java file to add AutoCompleteTextView code 3 Modify layout XML file res/layout/activity_main.xml add any GUI component if required. 4 Run the application and choose a running android device and install the application on it and verify the results. Here is the content of src/MainActivity.java package com.example.sairamkrishna.myapplication; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.MultiAutoCompleteTextView; import android.widget.Toast; import java.io.IOException; public class MainActivity extends Activity { AutoCompleteTextView text; MultiAutoCompleteTextView text1; String[] languages={“Android “,”java”,”IOS”,”SQL”,”JDBC”,”Web services”}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1); text1=(MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1); ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,languages); text.setAdapter(adapter); text.setThreshold(1); text1.setAdapter(adapter); text1.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); } } Here is the content of activity_main.xml Here abc indicates about logo of tutorialspoint <xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Android Auto Complete” android:id=”@+id/textView” android:textSize=”30dp” android:layout_alignParentTop=”true” android:layout_alignParentRight=”true” android:layout_alignParentEnd=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorialspoint” android:id=”@+id/textView2″ android:textColor=”#ff3eff0f” android:textSize=”35dp” android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” /> <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageView” android:src=”@drawable/logo” android:layout_below=”@+id/textView2″ android:layout_alignLeft=”@+id/textView2″ android:layout_alignStart=”@+id/textView2″ android:layout_alignRight=”@+id/textView2″ android:layout_alignEnd=”@+id/textView2″ /> <AutoCompleteTextView android:id=”@+id/autoCompleteTextView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:ems=”10″ android:layout_below=”@+id/imageView” android:layout_alignLeft=”@+id/imageView” android:layout_alignStart=”@+id/imageView” android:layout_marginTop=”72dp” android:hint=”AutoComplete TextView”> <requestFocus /> </AutoCompleteTextView> <MultiAutoCompleteTextView android:id=”@+id/multiAutoCompleteTextView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:ems=”10″ android:layout_below=”@+id/autoCompleteTextView1″ android:layout_alignLeft=”@+id/autoCompleteTextView1″ android:layout_alignStart=”@+id/autoCompleteTextView1″ android:hint=”Multi Auto Complete ” /> </RelativeLayout> Here is the content of Strings.xml <resources> <string name=”app_name”>My Application</string> </resources> Here is the content of AndroidManifest.xml <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.sairamkrishna.myapplication” > <application android:allowBackup=”true” android:icon=”@drawable/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”com.example.sairamkrishna.myapplication.MainActivity” android:label=”@string/app_name” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Let”s try to run your application. I assume you have connected your AVD while doing environment setup. To run the app from Android Studio, open one of your project”s activity files and click Run icon from the toolbar. Android studio will install this application in your AVD and your AVD will display following screen. Now just type in the text view to see suggestions of the Languages. As i just type one letter which are asa, and it shows me suggestion of language. The multiAutoCompleteTextView demonstrates suggestions for not only a word but for whole text. As after writing first word , when i start writing the second word , it displays me the suggestions. This can be shown in the picture below. Print Page Previous Next Advertisements ”;
Android – UI Layouts
Android – UI Layouts ”; Previous Next The basic building block for user interface is a View object which is created from the View class and occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components like buttons, text fields, etc. The ViewGroup is a subclass of View and provides invisible container that hold other Views or other ViewGroups and define their layout properties. At third level we have different layouts which are subclasses of ViewGroup class and a typical layout defines the visual structure for an Android user interface and can be created either at run time using View/ViewGroup objects or you can declare your layout using simple XML file main_layout.xml which is located in the res/layout folder of your project. Layout params This tutorial is more about creating your GUI based on layouts defined in XML file. A layout may contain any type of widgets such as buttons, labels, textboxes, and so on. Following is a simple example of XML file having LinearLayout − <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:orientation=”vertical” > <TextView android:id=”@+id/text” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”This is a TextView” /> <Button android:id=”@+id/button” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”This is a Button” /> <!– More GUI components go here –> </LinearLayout> Once your layout has created, you can load the layout resource from your application code, in your Activity.onCreate() callback implementation as shown below − public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } Android Layout Types There are number of Layouts provided by Android which you will use in almost all the Android applications to provide different view, look and feel. Sr.No Layout & Description 1 Linear Layout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. 2 Relative Layout RelativeLayout is a view group that displays child views in relative positions. 3 Table Layout TableLayout is a view that groups views into rows and columns. 4 Absolute Layout AbsoluteLayout enables you to specify the exact location of its children. 5 Frame Layout The FrameLayout is a placeholder on screen that you can use to display a single view. 6 List View ListView is a view group that displays a list of scrollable items. 7 Grid View GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. Layout Attributes Each layout has a set of attributes which define the visual properties of that layout. There are few common attributes among all the layouts and their are other attributes which are specific to that layout. Following are common attributes and will be applied to all the layouts: Sr.No Attribute & Description 1 android:id This is the ID which uniquely identifies the view. 2 android:layout_width This is the width of the layout. 3 android:layout_height This is the height of the layout 4 android:layout_marginTop This is the extra space on the top side of the layout. 5 android:layout_marginBottom This is the extra space on the bottom side of the layout. 6 android:layout_marginLeft This is the extra space on the left side of the layout. 7 android:layout_marginRight This is the extra space on the right side of the layout. 8 android:layout_gravity This specifies how child Views are positioned. 9 android:layout_weight This specifies how much of the extra space in the layout should be allocated to the View. 10 android:layout_x This specifies the x-coordinate of the layout. 11 android:layout_y This specifies the y-coordinate of the layout. 12 android:layout_width This is the width of the layout. 13 android:paddingLeft This is the left padding filled for the layout. 14 android:paddingRight This is the right padding filled for the layout. 15 android:paddingTop This is the top padding filled for the layout. 16 android:paddingBottom This is the bottom padding filled for the layout. Here width and height are the dimension of the layout/view which can be specified in terms of dp (Density-independent Pixels), sp ( Scale-independent Pixels), pt ( Points which is 1/72 of an inch), px( Pixels), mm ( Millimeters) and finally in (inches). You can specify width and height with exact measurements but more often, you will use one of these constants to set the width or height − android:layout_width=wrap_content tells your view to size itself to the dimensions required by its content. android:layout_width=fill_parent tells your view to become as big as its parent view. Gravity attribute plays important role in positioning the view object and it can take one or more (separated by ”|”) of the following constant values. Constant Value Description top 0x30 Push object to the top of its container, not changing its size. bottom 0x50 Push object to the bottom of its container, not changing its size. left 0x03 Push object to the left of its container, not changing its size. right 0x05 Push object to the right of its container, not changing its size. center_vertical 0x10 Place object in the vertical center of its container, not changing its size. fill_vertical 0x70 Grow the vertical size of the object if needed so it completely fills its container. center_horizontal 0x01 Place object in the horizontal center of its container, not changing its size. fill_horizontal 0x07 Grow the horizontal size of the object if needed so it completely fills its container. center 0x11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. fill 0x77 Grow the horizontal and vertical size of the object if needed so it completely fills its container. clip_vertical 0x80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container”s bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges. clip_horizontal 0x08 Additional option that can be set to have the left and/or right edges of the child clipped to its container”s bounds. The clip will
Android – Useful Resources
Android – Useful Resources ”; Previous Next The following resources contain additional information on Android. Please use them to get more in-depth knowledge on this topic. Useful Video Courses Android Online Training Course Best Seller 47 Lectures 7.5 hours Tutorialspoint More Detail Android Penetration Testing Online Training Most Popular 33 Lectures 3.5 hours Tutorialspoint More Detail The Complete XMPP Course: Android/iOS Apps Chat Server Setup 10 Lectures 1 hours Abhilash Nelson More Detail Android App Development Course for Beginners 30 Lectures 5 hours Anu Khanchandani More Detail Android Game Development Crash Course For Beginners 19 Lectures 4 hours Three Millennials More Detail Android Malware Analysis – From Zero to Hero Best Seller 30 Lectures 1.5 hours Mohamad Mahjoub More Detail Print Page Previous Next Advertisements ”;
Android – Spelling Checker
Android – Spelling Checker ”; Previous Next The Android platform offers a spelling checker framework that lets you implement and access spell checking in your application. In order to use spelling checker , you need to implement SpellCheckerSessionListener interface and override its methods. Its syntax is given below − public class HelloSpellCheckerActivity extends Activity implements SpellCheckerSessionListener { @Override public void onGetSuggestions(final SuggestionsInfo[] arg0) { // TODO Auto-generated method stub } @Override public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) { // TODO Auto-generated method stub } } Next thing you need to do is to create an object of SpellCheckerSession class. This object can be instantiated by calling newSpellCheckerSession method of TextServicesManager class. This class handles interaction between application and text services. You need to request system service to instantiate it. Its syntax is given below − private SpellCheckerSession mScs; final TextServicesManager tsm = (TextServicesManager) getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); The last thing you need to do is to call getSuggestions method to get suggestion for any text, you want. The suggestions will be passed onto the onGetSuggestions method from where you can do whatever you want. mScs.getSuggestions(new TextInfo(editText1.getText().toString()), 3); This method takes two parameters. First parameter is the string in the form of Text Info object, and second parameter is the cookie number used to distinguish suggestions. Apart from the the methods , there are other methods provided by the SpellCheckerSession class for better handling suggestions. These methods are listed below − Sr.No Method & description 1 cancel() Cancel pending and running spell check tasks 2 close() Finish this session and allow TextServicesManagerService to disconnect the bound spell checker 3 getSentenceSuggestions(TextInfo[] textInfos, int suggestionsLimit) Get suggestions from the specified sentences 4 getSpellChecker() Get the spell checker service info this spell checker session has. 5 isSessionDisconnected() True if the connection to a text service of this session is disconnected and not alive. Example Here is an example demonstrating the use of Spell Checker. It creates a basic spell checking application that allows you to write text and get suggestions. To experiment with this example , you can run this on an actual device or in an emulator. Steps Description 1 You will use Android studio to create an Android application under a package com.example.sairamkrishna.myapplication. 2 Modify src/MainActivity.java file to add necessary code. 3 Modify the res/layout/main to add respective XML components 4 Run the application and choose a running android device and install the application on it and verify the results Following is the content of the modified main activity file src/MainActivity.java. package com.example.sairamkrishna.myapplication; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.view.textservice.TextInfo; import android.view.textservice.TextServicesManager; import android.widget.Button; import android.widget.EditText; import android.view.textservice.SentenceSuggestionsInfo; import android.view.textservice.SpellCheckerSession; import android.view.textservice.SpellCheckerSession.SpellCheckerSessionListener; import android.view.textservice.SuggestionsInfo; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity implements SpellCheckerSessionListener { Button b1; TextView tv1; EditText ed1; private SpellCheckerSession mScs; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); b1=(Button)findViewById(R.id.button); tv1=(TextView)findViewById(R.id.textView3); ed1=(EditText)findViewById(R.id.editText); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), ed1.getText().toString(),Toast.LENGTH_SHORT).show(); mScs.getSuggestions(new TextInfo(ed1.getText().toString()), 3); } }); } public void onResume() { super.onResume(); final TextServicesManager tsm = (TextServicesManager) getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); mScs = tsm.newSpellCheckerSession(null, null, this, true); } public void onPause() { super.onPause(); if (mScs != null) { mScs.close(); } } public void onGetSuggestions(final SuggestionsInfo[] arg0) { final StringBuilder sb = new StringBuilder(); for (int i = 0; i < arg0.length; ++i) { // Returned suggestions are contained in SuggestionsInfo final int len = arg0[i].getSuggestionsCount(); sb.append(”n”); for (int j = 0; j < len; ++j) { sb.append(“,” + arg0[i].getSuggestionAt(j)); } sb.append(” (” + len + “)”); } runOnUiThread(new Runnable() { public void run() { tv1.append(sb.toString()); } }); } @Override public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] arg0) { // TODO Auto-generated method stub } } Following is the modified content of the xml res/layout/main.xml. In the following code abc indicates the logo of tutorialspoint.com <?xml version=”1.0″ encoding=”utf-8″?> <RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” android:paddingBottom=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:text=”Spell checker ” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/textview” android:textSize=”35dp” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorials point” android:id=”@+id/textView” android:layout_below=”@+id/textview” android:layout_centerHorizontal=”true” android:textColor=”#ff7aff24″ android:textSize=”35dp” /> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Suggestions” android:id=”@+id/button” android:layout_alignParentBottom=”true” android:layout_centerHorizontal=”true” /> <EditText android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/editText” android:hint=”Enter Text” android:layout_above=”@+id/button” android:layout_marginBottom=”56dp” android:focusable=”true” android:textColorHighlight=”#ff7eff15″ android:textColorHint=”#ffff25e6″ android:layout_alignRight=”@+id/textview” android:layout_alignEnd=”@+id/textview” android:layout_alignLeft=”@+id/textview” android:layout_alignStart=”@+id/textview” /> <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageView” android:src=”@drawable/abc” android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Suggestions” android:id=”@+id/textView3″ android:textSize=”25sp” android:layout_below=”@+id/imageView” /> </RelativeLayout> Following is the content of the res/values/string.xml. <resources> <string name=”app_name”>My Application</string> </resources> Following is the content of AndroidManifest.xml file. <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.sairamkrishna.myapplication” > <application android:allowBackup=”true” android:icon=”@mipmap/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”.MainActivity” android:label=”@string/app_name” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> </application> </manifest> Let”s try to run ourr application we just modified. I assume you had created your AVD while doing environment setup. To run the app from Android studio, open one of your project”s activity files and click Run icon from the toolbar. Android studio installs the app on your AVD and starts it and if everything is fine with your setup and application, it will display following Emulator window − Now what you need to do is to enter any text in the field. For example, i have entered some text. Press the suggestions button. The following notification would appear in you AVD along with suggestions − Now change the text and press the button again, like i did. And this is what comes on screen. Print Page Previous Next Advertisements ”;