Android – Event Handling ”; Previous Next Events are a useful way to collect data about a user”s interaction with interactive components of Applications. Like button presses or screen touch etc. The Android framework maintains an event queue as first-in, first-out (FIFO) basis. You can capture these events in your program and take appropriate action as per requirements. There are following three concepts related to Android Event Management − Event Listeners − An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI. Event Listeners Registration − Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Event Handlers − When an event happens and we have registered an event listener for the event, the event listener calls the Event Handlers, which is the method that actually handles the event. Event Listeners & Event Handlers Event Handler Event Listener & Description onClick() OnClickListener() This is called when the user either clicks or touches or focuses upon any widget like button, text, image etc. You will use onClick() event handler to handle such event. onLongClick() OnLongClickListener() This is called when the user either clicks or touches or focuses upon any widget like button, text, image etc. for one or more seconds. You will use onLongClick() event handler to handle such event. onFocusChange() OnFocusChangeListener() This is called when the widget looses its focus ie. user goes away from the view item. You will use onFocusChange() event handler to handle such event. onKey() OnFocusChangeListener() This is called when the user is focused on the item and presses or releases a hardware key on the device. You will use onKey() event handler to handle such event. onTouch() OnTouchListener() This is called when the user presses the key, releases the key, or any movement gesture on the screen. You will use onTouch() event handler to handle such event. onMenuItemClick() OnMenuItemClickListener() This is called when the user selects a menu item. You will use onMenuItemClick() event handler to handle such event. onCreateContextMenu() onCreateContextMenuItemListener() This is called when the context menu is being built(as the result of a sustained “long click) There are many more event listeners available as a part of View class like OnHoverListener, OnDragListener etc which may be needed for your application. So I recommend to refer official documentation for Android application development in case you are going to develop a sophisticated apps. Event Listeners Registration Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Though there are several tricky ways to register your event listener for any event, but I”m going to list down only top 3 ways, out of which you can use any of them based on the situation. Using an Anonymous Inner Class Activity class implements the Listener interface. Using Layout file activity_main.xml to specify event handler directly. Below section will provide you detailed examples on all the three scenarios − Touch Mode Users can interact with their devices by using hardware keys or buttons or touching the screen.Touching the screen puts the device into touch mode. The user can then interact with it by touching the on-screen virtual buttons, images, etc.You can check if the device is in touch mode by calling the View class’s isInTouchMode() method. Focus A view or widget is usually highlighted or displays a flashing cursor when it’s in focus. This indicates that it’s ready to accept input from the user. isFocusable() − it returns true or false isFocusableInTouchMode() − checks to see if the view is focusable in touch mode. (A view may be focusable when using a hardware key but not when the device is in touch mode) android:foucsUp=”@=id/button_l” onTouchEvent() public boolean onTouchEvent(motionEvent event){ switch(event.getAction()){ case TOUCH_DOWN: Toast.makeText(this,”you have clicked down Touch button”,Toast.LENTH_LONG).show(); break(); case TOUCH_UP: Toast.makeText(this,”you have clicked up touch button”,Toast.LENTH_LONG).show(); break; case TOUCH_MOVE: Toast.makeText(this,”you have clicked move touch button”Toast.LENTH_LONG).show(); break; } return super.onTouchEvent(event) ; } Event Handling Examples Event Listeners Registration Using an Anonymous Inner Class Here you will create an anonymous implementation of the listener and will be useful if each class is applied to a single control only and you have advantage to pass arguments to event handler. In this approach event handler methods can access private data of Activity. No reference is needed to call to Activity. But if you applied the handler to more than one control, you would have to cut and paste the code for the handler and if the code for the handler is long, it makes the code harder to maintain. Following are the simple steps to show how we will make use of separate Listener class to register and capture click event. Similar way you can implement your listener for any other required event type. Step Description 1 You will use Android studio IDE to create an Android application and name it as myapplication under a package com.example.myapplication as explained in the Hello World Example chapter. 2 Modify src/MainActivity.java file to add click event listeners and handlers for the two buttons defined. 3 Modify the detault content of res/layout/activity_main.xml file to include Android UI controls. 4 No need to declare default string constants.Android studio takes care default constants. 5 Run the application to launch Android emulator and verify the result of the changes done in the aplication. Following is the content of the modified main activity file src/com.example.myapplication/MainActivity.java. This file can include each of the fundamental lifecycle methods. package com.example.myapplication; import android.app.ProgressDialog; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends ActionBarActivity { private ProgressDialog progress; Button b1,b2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progress = new
Category: Android
Android – Localization
Android – Localization ”; Previous Next An android application can run on many devices in many different regions. In order to make your application more interactive, your application should handle text,numbers,files e.t.c in ways appropriate to the locales where your application will be used. The way of changing string into different languages is called as localization In this chapter we will explain , how you can localize your application according to different regions e.t.c. We will localize the strings used in the application, and in the same way other things can be localized. Localizing Strings In order to localize the strings used in your application , make a new folder under res with name of values-local where local would be the replaced with the region. For example, in the case of italy, the values-it folder would be made under res. It is shown in the image below − Once that folder is made, copy the strings.xmlfrom default folder to the folder you have created. And change its contents. For example, i have changed the value of hello_world string. Italy, res/values-it/strings.xml <;?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”hello_world”>Ciao mondo!</string> </resources> Spanish, res/values-it/strings.xml <;?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”hello_world”>Hola Mundo!</string> </resources> French, res/values-it/strings.xml <;?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”hello_world”>Bonjour le monde !</string> </resources> Apart from these languages, the region code of other languages have been given in the table below − Sr.No Language & code 1 Afrikanns Code: af. Folder name: values-af 2 Arabic Code: ar. Folder name: values-ar 3 Bengali Code: bn. Folder name: values-bn 4 Czech Code: cs. Folder name: values-cs 5 Chinese Code: zh. Folder name: values-zh 6 German Code: de. Folder name: values-de 7 French Code: fr. Folder name: values-fr 8 Japanese Code: ja. Folder name: values-ja Example 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 the res/layout/activity_main to add respective XML components 3 Modify the res/values/string.xml to add necessary string components 4 Run the application and choose a running android device and install the application on it and verify the results 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=”Wifi” 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” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/hindi” android:id=”@+id/textView2″ android:layout_below=”@+id/textView” android:layout_centerHorizontal=”true” android:layout_marginTop=”50dp” android:textColor=”#ff59ff1a” android:textSize=”30dp” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/marathi” android:id=”@+id/textView3″ android:textSize=”30dp” android:textColor=”#ff67ff1e” android:layout_centerVertical=”true” android:layout_centerHorizontal=”true” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/arabic” android:id=”@+id/textView4″ android:layout_below=”@+id/textView3″ android:layout_centerHorizontal=”true” android:layout_marginTop=”42dp” android:textColor=”#ff40ff08″ android:textSize=”30dp” /> <TextView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/chinese” android:id=”@+id/textView5″ android:layout_below=”@+id/textView4″ android:layout_alignLeft=”@+id/textView3″ android:layout_alignStart=”@+id/textView3″ android:layout_marginTop=”42dp” android:textSize=”30dp” android:textColor=”#ff56ff12″ android:layout_alignRight=”@+id/textView3″ android:layout_alignEnd=”@+id/textView3″ /> </RelativeLayout> Following is the content of the res/values/string.xml. <resources> <string name=”app_name”>My Application</string> <string name=”hello_world”>Hello world!</string> <string name=”action_settings”>Settings</string> <string name=”hindi”>ట్యుటోరియల్స్ పాయింట్</string> <string name=”marathi”>शिकवण्या बिंदू</string> <string name=”arabic”>نقطة الدروس7</string> <string name=”chinese”>教程点</string> </resources> Let”s try to run our 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 − Print Page Previous Next Advertisements ”;
Location Based Services
Android – Location Based Services ”; Previous Next Android location APIs make it easy for you to build location-aware applications, without needing to focus on the details of the underlying location technology. This becomes possible with the help of Google Play services, which facilitates adding location awareness to your app with automated location tracking, geofencing, and activity recognition. This tutorial shows you how to use Location Services in your APP to get the current location, get periodic location updates, look up addresses etc. The Location Object The Location object represents a geographic location which can consist of a latitude, longitude, time stamp, and other information such as bearing, altitude and velocity. There are following important methods which you can use with Location object to get location specific information − Sr.No. Method & Description 1 float distanceTo(Location dest) Returns the approximate distance in meters between this location and the given location. 2 float getAccuracy() Get the estimated accuracy of this location, in meters. 3 double getAltitude() Get the altitude if available, in meters above sea level. 4 float getBearing() Get the bearing, in degrees. 5 double getLatitude() Get the latitude, in degrees. 6 double getLongitude() Get the longitude, in degrees. 7 float getSpeed() Get the speed if it is available, in meters/second over ground. 8 boolean hasAccuracy() True if this location has an accuracy. 9 boolean hasAltitude() True if this location has an altitude. 10 boolean hasBearing() True if this location has a bearing. 11 boolean hasSpeed() True if this location has a speed. 12 void reset() Clears the contents of the location. 13 void setAccuracy(float accuracy) Set the estimated accuracy of this location, meters. 14 void setAltitude(double altitude) Set the altitude, in meters above sea level. 15 void setBearing(float bearing) Set the bearing, in degrees. 16 void setLatitude(double latitude) Set the latitude, in degrees. 17 void setLongitude(double longitude) Set the longitude, in degrees. 18 void setSpeed(float speed) Set the speed, in meters/second over ground. 19 String toString() Returns a string containing a concise, human-readable description of this object. Get the Current Location To get the current location, create a location client which is LocationClient object, connect it to Location Services using connect() method, and then call its getLastLocation() method. This method returns the most recent location in the form of Location object that contains latitude and longitude coordinates and other information as explained above. To have location based functionality in your activity, you will have to implement two interfaces − GooglePlayServicesClient.ConnectionCallbacks GooglePlayServicesClient.OnConnectionFailedListener These interfaces provide following important callback methods, which you need to implement in your activity class − Sr.No. Callback Methods & Description 1 abstract void onConnected(Bundle connectionHint) This callback method is called when location service is connected to the location client successfully. You will use connect() method to connect to the location client. 2 abstract void onDisconnected() This callback method is called when the client is disconnected. You will use disconnect() method to disconnect from the location client. 3 abstract void onConnectionFailed(ConnectionResult result) This callback method is called when there was an error connecting the client to the service. You should create the location client in onCreate() method of your activity class, then connect it in onStart(), so that Location Services maintains the current location while your activity is fully visible. You should disconnect the client in onStop() method, so that when your app is not visible, Location Services is not maintaining the current location. This helps in saving battery power up-to a large extent. Get the Updated Location If you are willing to have location updates, then apart from above mentioned interfaces, you will need to implement LocationListener interface as well. This interface provide following callback method, which you need to implement in your activity class − Sr.No. Callback Method & Description 1 abstract void onLocationChanged(Location location) This callback method is used for receiving notifications from the LocationClient when the location has changed. Location Quality of Service The LocationRequest object is used to request a quality of service (QoS) for location updates from the LocationClient. There are following useful setter methods which you can use to handle QoS. There are equivalent getter methods available which you can check in Android official documentation. Sr.No. Method & Description 1 setExpirationDuration(long millis) Set the duration of this request, in milliseconds. 2 setExpirationTime(long millis) Set the request expiration time, in millisecond since boot. 3 setFastestInterval(long millis) Explicitly set the fastest interval for location updates, in milliseconds. 4 setInterval(long millis) Set the desired interval for active location updates, in milliseconds. 5 setNumUpdates(int numUpdates) Set the number of location updates. 6 setPriority(int priority) Set the priority of the request. Now for example, if your application wants high accuracy location it should create a location request with setPriority(int) set to PRIORITY_HIGH_ACCURACY and setInterval(long) to 5 seconds. You can also use bigger interval and/or other priorities like PRIORITY_LOW_POWER for to request “city” level accuracy or PRIORITY_BALANCED_POWER_ACCURACY for “block” level accuracy. Activities should strongly consider removing all location request when entering the background (for example at onPause()), or at least swap the request to a larger interval and lower quality to save power consumption. Displaying a Location Address Once you have Location object, you can use Geocoder.getFromLocation() method to get an address for a given latitude and longitude. This method is synchronous, and may take a long time to do its work, so you should call the method from the doInBackground() method of an AsyncTask class. The AsyncTask must be subclassed to be used and the subclass will override doInBackground(Params…) method to perform a task in the background and onPostExecute(Result) method is invoked on the UI thread after the background computation finishes and at the time to display the result. There is one more important method available in AyncTask which is execute(Params… params), this method executes the task with the specified parameters. Example Following example shows you in practical how to to use Location Services in your app to get the current location and its equivalent addresses etc. To experiment with this
Android – Sending Email
Android – Sending Email ”; Previous Next Email is messages distributed by electronic means from one system user to one or more recipients via a network. Before starting Email Activity, You must know Email functionality with intent, Intent is carrying data from one component to another component with-in the application or outside the application. To send an email from your application, you don’t have to implement an email client from the beginning, but you can use an existing one like the default Email app provided from Android, Gmail, Outlook, K-9 Mail etc. For this purpose, we need to write an Activity that launches an email client, using an implicit Intent with the right action and data. In this example, we are going to send an email from our app by using an Intent object that launches existing email clients. Following section explains different parts of our Intent object required to send an email. Intent Object – Action to send Email You will use ACTION_SEND action to launch an email client installed on your Android device. Following is simple syntax to create an intent with ACTION_SEND action. Intent emailIntent = new Intent(Intent.ACTION_SEND); Intent Object – Data/Type to send Email To send an email you need to specify mailto: as URI using setData() method and data type will be to text/plain using setType() method as follows − emailIntent.setData(Uri.parse(“mailto:”)); emailIntent.setType(“text/plain”); Intent Object – Extra to send Email Android has built-in support to add TO, SUBJECT, CC, TEXT etc. fields which can be attached to the intent before sending the intent to a target email client. You can use following extra fields in your email − Sr.No. Extra Data & Description 1 EXTRA_BCC A String[] holding e-mail addresses that should be blind carbon copied. 2 EXTRA_CC A String[] holding e-mail addresses that should be carbon copied. 3 EXTRA_EMAIL A String[] holding e-mail addresses that should be delivered to. 4 EXTRA_HTML_TEXT A constant String that is associated with the Intent, used with ACTION_SEND to supply an alternative to EXTRA_TEXT as HTML formatted text. 5 EXTRA_SUBJECT A constant string holding the desired subject line of a message. 6 EXTRA_TEXT A constant CharSequence that is associated with the Intent, used with ACTION_SEND to supply the literal data to be sent. 7 EXTRA_TITLE A CharSequence dialog title to provide to the user when used with a ACTION_CHOOSER. Here is an example showing you how to assign extra data to your intent − emailIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{“Recipient”}); emailIntent.putExtra(Intent.EXTRA_SUBJECT, “subject”); emailIntent.putExtra(Intent.EXTRA_TEXT , “Message Body”); The out-put of above code is as below shown an image Email Example Example Following example shows you in practical how to use Intent object to launch Email client to send an Email to the given recipients. To Email experiment with this example, you will need actual Mobile device equipped with latest Android OS, otherwise you might get struggle with emulator which may not work properly. Second you will need to have an Email client like GMail(By default every android version having Gmail client App) or K9mail installed on your device. Step Description 1 You will use Android studio to create an Android application and name it as Tutorialspoint under a package com.example.tutorialspoint. 2 Modify src/MainActivity.java file and add required code to take care of sending email. 3 Modify layout XML file res/layout/activity_main.xml add any GUI component if required. I”m adding a simple button to launch Email Client. 4 Modify res/values/strings.xml to define required constant values 5 Modify AndroidManifest.xml as shown below 6 Run the application to launch Android emulator and verify the result of the changes done in the application. Following is the content of the modified main activity file src/com.example.Tutorialspoint/MainActivity.java. package com.example.tutorialspoint; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button startBtn = (Button) findViewById(R.id.sendEmail); startBtn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { sendEmail(); } }); } protected void sendEmail() { Log.i(“Send email”, “”); String[] TO = {“”}; String[] CC = {“”}; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse(“mailto:”)); emailIntent.setType(“text/plain”); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, “Your subject”); emailIntent.putExtra(Intent.EXTRA_TEXT, “Email message goes here”); try { startActivity(Intent.createChooser(emailIntent, “Send mail…”)); finish(); Log.i(“Finished sending email…”, “”); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, “There is no email client installed.”, Toast.LENGTH_SHORT).show(); } } } Following will be the content of res/layout/activity_main.xml file − Here abc indicates about tutorialspoint logo <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/textView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Sending Mail Example” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” android:textSize=”30dp” /> <TextView android:id=”@+id/textView2″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Tutorials point ” android:textColor=”#ff87ff09″ android:textSize=”30dp” android:layout_above=”@+id/imageButton” android:layout_alignRight=”@+id/imageButton” android:layout_alignEnd=”@+id/imageButton” /> <ImageButton android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageButton” android:src=”@drawable/abc” android:layout_centerVertical=”true” android:layout_centerHorizontal=”true” /> <Button android:id=”@+id/sendEmail” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”@string/compose_email”/> </LinearLayout> Following will be the content of res/values/strings.xml to define two new constants − <?xml version=”1.0″ encoding=”utf-8″?> <resources> <string name=”app_name”>Tutorialspoint</string> <string name=”compose_email”>Compose Email</string> </resources> Following is the default content of AndroidManifest.xml − <?xml version=”1.0″ encoding=”utf-8″?> <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.Tutorialspoint” > <application android:allowBackup=”true” android:icon=”@drawable/ic_launcher” android:label=”@string/app_name” android:theme=”@style/AppTheme” > <activity android:name=”com.example.tutorialspoint.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 tutorialspoint 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 toolbar. Before starting your application, Android studio installer 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 − Now use Compose Email button to list down all the installed email clients. From the list, you can choose one of email clients to send your email. I”m going to use Gmail client to send my email which will have all the provided defaults fields available as shown below. Here From: will be default email ID you have registered for your Android device. You can modify either of the given default fields and finally use send email button to
Android – Emulator
Android – Emulator ”; Previous Next The Android SDK includes a virtual mobile device emulator that runs on your computer. The emulator lets you prototype, develop and test Android applications without using a physical device. In this chapter we are going to explore different functionalities in the emulator that are present in the real android device. Creating AVD If you want to emulate a real device, first crate an AVD with the same device configurations as real device, then launch this AVD from AVD manager. Changing Orientation Usually by default when you launch the emulator, its orientation is vertical, but you can change it orientation by pressing Ctrl+F11 key from keyboard. First launch the emulator. It is shown in the picture below − Once it is launched, press Ctrl+F11 key to change its orientation. It is shown below − Emulator Commands. Apart from just orientation commands, there are other very useful commands of emulator that you should keep in mind while using emulator. They are listed below − Sr.No Command & description 1 Home Shifts to main screen 2 F2 Toggles context sensitive menu 3 F3 Bring out call log 4 F4 End call 5 F5 Search 6 F6 Toggle trackball mode 7 F7 Power button 8 F8 Toggle data network 9 Ctrl+F5 Ring Volume up 10 Ctrl+F6 Ring Volume down Emulator – Sending SMS You can emulate sending SMS to your emulator. There are two ways to do that. You can do that from DDMS which can be found in Android studio, or from Telnet.(Network utility found in windows). Sending SMS through Telnet. Telnet is not enabled by default in windows. You have to enable it to use it. Once enabled you can go to command prompt and start telnet by typing telnet. In order to send SMS , note down the AVD number which can be found on the title bar of the emulator. It could be like this 5554 e.t.c. Once noted , type this command in command prompt. telnet localhost 5554 Press enter when you type the command. It is shown below in the figure. You will see that you are now connected to your emulator. Now type this command to send message. sms send 1234 “hello” Once you type this command , hit enter. Now look at the AVD. You will receive a notification displaying that you got a new text message. It is shown below − Emulator – Making Call You can easily make phone calls to your emulator using telent client. You need to connect to your emulator from telnet. It is discussed in the sending sms topic above. After that you will type this command in the telent window to make a call. Its syntax is given below − gsm call 1234 Once you type this command , hit enter. Now look at the AVD. You will receive a call from the number your put in the command. It is shown below − Emulator – Transferring files You can easily transfer files into the emulator and vice versa. In order to do that, you need to select the DDMS utility in Android studio. After that select the file explorer tab. It is shown below − Browse through the explorer and make new folder , view existing contents e.t.c. Print Page Previous Next Advertisements ”;
Android – JetPlayer
Android – JetPlayer ”; Previous Next The Android platform includes a JET engine that lets you add interactive playback of JET audio content in your applications. Android provides JetPlayer class to handle this stuff. In order to Jet Content , you need to use the JetCreator tool that comes with AndroidSDK. The usage of jetCreator has been discussed in the example. In order to play the content created by JetCreator, you need JetPlayer class supported by android. In order to use JetPlayer , you need to instantiate an object of JetPlayer class. Its syntax is given below − JetPlayer jetPlayer = JetPlayer.getJetPlayer(); The next thing you need to do is to call loadJetFile method and pass in the path of your Jet file. After that you have to add this into the Queue of JetPlayer. Its syntax is given below − jetPlayer.loadJetFile(“/sdcard/level1.jet”); byte segmentId = 0; // queue segment 5, repeat once, use General MIDI, transpose by -1 octave jetPlayer.queueJetSegment(5, -1, 1, -1, 0, segmentId++); The method queueJetSegment Queues the specified segment in the JET Queue. The last thing you need to is to call the play method to start playing the music. Its syntax is given below − jetPlayer.play(); Apart from these methods, there are other methods defined in the JetPlayer class. They are defined below − Sr.No Method & description 1 clearQueue() Empties the segment queue, and clears all clips that are scheduled for playback 2 closeJetFile() Closes the resource containing the JET content 3 getJetPlayer() Factory method for the JetPlayer class 4 loadJetFile(String path) Loads a .jet file from a given path 5 pause() Pauses the playback of the JET segment queue 6 release() Stops the current JET playback, and releases all associated native resources Example The following example demonstrates the use of JetCreator tool to create Jet content. Once that content is created, you can play it through JetPlayer. 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 IDE to create an Android application and name it as JetPlayer under a package com.example.jetplayer. 2 Install Python and WxPython on your computer from internet. 3 Run the jet creator from command prompt 4 Create Jet content and then save it 5 Run the application and verify the results Using JetCreator Installing python The first step that you need while using JetCreator is to install the python. The python can be installed from its official website here or from any where else on the internet. Please keep in mind the version number of the python should either be 2.6 or 2.7 because this example follows that. Once you download python install it. After installing you have to set path to the python. Open your command prompt and type the following command.It is shown in the image below − Once path is set , you can verify it by typing python and hit enter. It is shown below − Installing WxPython The next thing you need to do is to install the wxPython. It can be downloaded here. Once downloaded , you will install it. It will be automatically installed in the python directory. Ruuning JetCreator The next thing you need to is to move to the path where JetCreator is present. It is in the tools,SDK folder of the android. It is shown below − Once in the folder type this command and hit enter. python JetCreator.py It is shown in the figure below − As soon as you hit enter, Jet Creator window will open. It would be something like this. Creating JetContent In the above Jet Window, click on the import button. And select JetCreator_demo_1 or 2 from the JetFolder from the demo content folder in the Jet folder. It is shown in the image below: Once you import the content , you will see the content in the JetCreator window. It is shown below − Now you can explore different options of JetCreator by visiting the JetCreator link here. Finally in order to create .jet file , you need to save the content from the file menu. Verifying Results Once you got the jet file, you can play it using jet player. The main code of playing it has been given below − JetPlayer jetPlayer = JetPlayer.getJetPlayer(); jetPlayer.loadJetFile(“/sdcard/level1.jet”); byte segmentId = 0; // queue segment 5, repeat once, use General MIDI, transpose by -1 octave jetPlayer.queueJetSegment(5, -1, 1, -1, 0, segmentId++); jetPlayer.play(); Print Page Previous Next Advertisements ”;
Android – Twitter Integration ”; Previous Next Android allows your application to connect to twitter and share data or any kind of updates on twitter. This chapter is about integrating twitter into your application. There are two ways through which you can integrate twitter and share something from your application. These ways are listed below − Twitter SDK (Twitter4J) Intent Share Integrating Twitter SDK This is the first way of connecting with Twitter. You have to register your application and then receive some Application Id, and then you have to download the twitter SDK and add it to your project. The steps are listed below − Registering your application Create a new twitter application at dev.twitter.com/apps/new and fill all the information. It is shown below − Now under settings tab, change the access to read,write and access messages and save the settings. It is shown below − If everything works fine, you will receive an consumer ID with the secret. Just copy the application id and save it somewhere. It is shown in the image below − Downloading SDK and integrating it Download twitter sdk here. Copy the twitter4J jar into your project libs folder. Posting tweets on twitter application Once everything is complete , you can run the twitter 4J samples which can be found here. In order to use twitter, you need to instantiate an object of twitter class.It can be done by calling the static method getsingleton(). Its syntax is given below. // The factory instance is re-usable and thread safe. Twitter twitter = TwitterFactory.getSingleton(); In order to update the status , you can call updateStatus() method. Its syntax is given below − Status status = twitter.updateStatus(latestStatus); System.out.println(“Successfully updated the status to [” + status.getText() + “].”); Intent share Intent share is used to share data between applications. In this strategy, we will not handle the SDK stuff, but let the twitter application handles it. We will simply call the twitter application and pass the data to share. This way, we can share something on twitter. Android provides intent library to share data between activities and applications. In order to use it as share intent, we have to specify the type of the share intent to ACTION_SEND. Its syntax is given below − Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); Next thing you need to is to define the type of data to pass, and then pass the data. Its syntax is given below − shareIntent.setType(“text/plain”); shareIntent.putExtra(Intent.EXTRA_TEXT, “Hello, from tutorialspoint”); startActivity(Intent.createChooser(shareIntent, “Share your thoughts”)); Apart from the these methods, there are other methods available that allows intent handling. They are listed below − Sr.No Method & description 1 addCategory(String category) This method add a new category to the intent. 2 createChooser(Intent target, CharSequence title) Convenience function for creating a ACTION_CHOOSER Intent 3 getAction() This method retrieve the general action to be performed, such as ACTION_VIEW 4 getCategories() This method return the set of all categories in the intent and the current scaling event 5 putExtra(String name, int value) This method add extended data to the intent. 6 toString() This method returns a string containing a concise, human-readable description of this object Example Here is an example demonstrating the use of IntentShare to share data on twitter. It creates a basic application that allows you to share some text on twitter. 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/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 MainActivity.java. package com.example.sairamkrishna.myapplication; import android.content.Intent; import android.net.Uri; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageView; import java.io.FileNotFoundException; import java.io.InputStream; public class MainActivity extends ActionBarActivity { private ImageView img; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); img=(ImageView)findViewById(R.id.imageView); Button b1=(Button)findViewById(R.id.button); b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); Uri screenshotUri = Uri.parse(“android.resource://comexample.sairamkrishna.myapplication/*”); try { InputStream stream = getContentResolver().openInputStream(screenshotUri); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } sharingIntent.setType(“image/jpeg”); sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); startActivity(Intent.createChooser(sharingIntent, “Share image using”)); } }); } } 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: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=”Twitter share ” /> <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″ /> <ImageView android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:id=”@+id/imageView” android:layout_below=”@+id/textView2″ android:layout_centerHorizontal=”true” android:src=”@drawable/abc”/> <Button android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Share” android:id=”@+id/button” android:layout_marginTop=”61dp” android:layout_below=”@+id/imageView” android:layout_centerHorizontal=”true” /> </RelativeLayout> 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 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 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 your default screen − Now just tap on the button and you will see a list of share providers. Now just select twitter from that list and then write any message. It is shown in the image below − Now just select the tweet button and then it would be post on your twitter page. It is shown below − Print Page Previous Next Advertisements ”;
Android – RenderScript
Android – RenderScript ”; Previous Next In this chapter, we will learn about Android RenderScript. Usually the apps on android are designed as to consume as minimum resources as possible. But some applications like some 3D games need high level processing on android. To provide these applications high performance android introduced the RenderScript. It is android based framework which is used for running applications that perform very highly computational tasks. The development on this framework is done in Native Development Kit(NDK) provided by android. RenderScript is extremely useful for applications which performs following types of actions − 3D Rendering Image Processing Computational Photography Computer Vision How RenderScript Works RenderScript framework is basically based on data parallel computation. It distributes your application workload on all the processors available on your device like multi-core CPUs or GPUs. This parallel distribution of workload frees the programmer from the tension of load balancing and work scheduling. You can write more detailed and complex algorithms for your app without the worry of computational power. How to Begin To use the RenderScript Framework you must have following two things − A RenderScript Kernel RenderScript APIs A RenderScript Kernel A kernel is a program which manages data processing instructions and manage workload on Central Processing Units.A kernel is a fundamental part of the operating system. Similarly to run the RenderScript framework we need a written script named as Kernel to manage all the data processing requests from our app and utilize more features of the android OS provided by the NDK and as mentioned earlier that the development of RenderScript is done in the Native Development Kit of Android. The Kernel Script is written in C-99 standard of C-language. This Standard was before the development of C++. A RenderScript kernel script file usually placed in .rs file. Each file is called as a script. A RenderScript Kernel script can contain following elements − Sr.No Elements & Description 1 A Language declaration It declares the version of RenderScript Kernel language used in this script. 2 A package declaration This declaration names the package name of the Java class which will be affected by this Kernel Code. 3 Invokable functions You can call these invokable functions from your JAVA code with arbitrary arguments. 4 Script Global Variables These are just like the variables defined in C and C++ programming language. You can access these variables from your JAVA code. Following is the Sample Code of a Kernel − uchar4 __convert__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) { uchar4 out = in; out.r = 255 – in.r; out.g = 255 – in.g; return out; } RenderScript APIs If you want to use RenderScript in your API, you can do it in following two ways − Sr.No APIs & Description 1 android.renderscript This API is available on devices running Android 3.0 and higher. 2 android.support.v8.renderscript This API is available on devices running Android 2.2 and higher. To android support library following tools are required − Latest Android SDK Tools version Latest Android SDK Build-tools version How to use RenderScript Support Library First Open the project.properties file in your project and add following lines in the file − renderscript.target=18 renderscript.support.mode=true sdk.buildtools=18.1.0 Now open your main class which use RenderScript and add an import for the Support Library classes as following − import android.support.v8.renderscript.*; Following are the purposes of above mentioned properties that we add in the project.properties file. Sr.No Project properties & Description 1 renderscript.target It specifies the byte code version to be generated. 2 renderscript.support.mode It specifies a compatible version for the generated byte code to fall back. 3 sdk.buildtools It Specifies the versions of Android SDK build tools to use. Now call your RenderScript Kernel functions and compute complex algorithms in your app. Print Page Previous Next Advertisements ”;
Android – XML Parsers
Android – XML Parser ”; Previous Next XML stands for Extensible Mark-up Language.XML is a very popular format and commonly used for sharing data on the internet. This chapter explains how to parse the XML file and extract necessary information from it. Android provides three types of XML parsers which are DOM,SAX and XMLPullParser. Among all of them android recommend XMLPullParser because it is efficient and easy to use. So we are going to use XMLPullParser for parsing XML. The first step is to identify the fields in the XML data in which you are interested in. For example. In the XML given below we interested in getting temperature only. <?xml version=”1.0″?> <current> <city id=”2643743″ name=”London”> <coord lon=”-0.12574″ lat=”51.50853″/> <country>GB</country> <sun rise=”2013-10-08T06:13:56″ set=”2013-10-08T17:21:45″/> </city> <temperature value=”289.54″ min=”289.15″ max=”290.15″ unit=”kelvin”/> <humidity value=”77″ unit=”%”/> <pressure value=”1025″ unit=”hPa”/> </current> XML – Elements An xml file consist of many components. Here is the table defining the components of an XML file and their description. Sr.No Component & description 1 Prolog An XML file starts with a prolog. The first line that contains the information about a file is prolog 2 Events An XML file has many events. Event could be like this. Document starts , Document ends, Tag start , Tag end and Text e.t.c 3 Text Apart from tags and events, and xml file also contains simple text. Such as GB is a text in the country tag. 4 Attributes Attributes are the additional properties of a tag such as value e.t.c XML – Parsing In the next step, we will create XMLPullParser object , but in order to create that we will first create XmlPullParserFactory object and then call its newPullParser() method to create XMLPullParser. Its syntax is given below − private XmlPullParserFactory xmlFactoryObject = XmlPullParserFactory.newInstance(); private XmlPullParser myparser = xmlFactoryObject.newPullParser(); The next step involves specifying the file for XmlPullParser that contains XML. It could be a file or could be a Stream. In our case it is a stream.Its syntax is given below − myparser.setInput(stream, null); The last step is to parse the XML. An XML file consist of events, Name, Text, AttributesValue e.t.c. So XMLPullParser has a separate function for parsing each of the component of XML file. Its syntax is given below − int event = myParser.getEventType(); while (event != XmlPullParser.END_DOCUMENT) { String name=myParser.getName(); switch (event){ case XmlPullParser.START_TAG: break; case XmlPullParser.END_TAG: if(name.equals(“temperature”)){ temperature = myParser.getAttributeValue(null,”value”); } break; } event = myParser.next(); } The method getEventType returns the type of event that happens. e.g: Document start , tag start e.t.c. The method getName returns the name of the tag and since we are only interested in temperature , so we just check in conditional statement that if we got a temperature tag , we call the method getAttributeValue to return us the value of temperature tag. Apart from the these methods, there are other methods provided by this class for better parsing XML files. These methods are listed below − Sr.No Method & description 1 getAttributeCount() This method just Returns the number of attributes of the current start tag 2 getAttributeName(int index) This method returns the name of the attribute specified by the index value 3 getColumnNumber() This method returns the Returns the current column number, starting from 0. 4 getDepth() This method returns Returns the current depth of the element. 5 getLineNumber() Returns the current line number, starting from 1. 6 getNamespace() This method returns the name space URI of the current element. 7 getPrefix() This method returns the prefix of the current element 8 getName() This method returns the name of the tag 9 getText() This method returns the text for that particular element 10 isWhitespace() This method checks whether the current TEXT event contains only whitespace characters. Example Here is an example demonstrating the use of XML DOM Parser. It creates a basic application that allows you to parse XML. 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/activity_main to add respective XML components 4 Create a new XML file under Assets Folder/file.xml 5 Modify AndroidManifest.xml to add necessary internet permission 6 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 MainActivity.java. package com.example.sairamkrishna.myapplication; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { TextView tv1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv1=(TextView)findViewById(R.id.textView1); try { InputStream is = getAssets().open(“file.xml”); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(is); Element element=doc.getDocumentElement(); element.normalize(); NodeList nList = doc.getElementsByTagName(“employee”); for (int i=0; i<nList.getLength(); i++) { Node node = nList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element2 = (Element) node; tv1.setText(tv1.getText()+”nName : ” + getValue(“name”, element2)+”n”); tv1.setText(tv1.getText()+”Surname : ” + getValue(“surname”, element2)+”n”); tv1.setText(tv1.getText()+”———————–“); } } } catch (Exception e) {e.printStackTrace();} } private static String getValue(String tag, Element element) { NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes(); Node node = nodeList.item(0); return node.getNodeValue(); } } Following is the content of Assets/file.xml. <?xml version=”1.0″?> <records> <employee> <name>Sairamkrishna</name> <surname>Mammahe</surname> <salary>50000</salary> </employee> <employee> <name>Gopal </name> <surname>Varma</surname> <salary>60000</salary> </employee> <employee> <name>Raja</name> <surname>Hr</surname> <salary>70000</salary> </employee> </records> 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:paddingBottom=”@dimen/activity_vertical_margin” android:paddingLeft=”@dimen/activity_horizontal_margin” android:paddingRight=”@dimen/activity_horizontal_margin” android:paddingTop=”@dimen/activity_vertical_margin” tools:context=”.MainActivity”> <TextView android:id=”@+id/textView1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> </RelativeLayout> 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 our 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
Publishing Android Application ”; Previous Next Android application publishing is a process that makes your Android applications available to users. Infect, publishing is the last phase of the Android application development process. Android development life cycle Once you developed and fully tested your Android Application, you can start selling or distributing free using Google Play (A famous Android marketplace). You can also release your applications by sending them directly to users or by letting users download them from your own website. You can check a detailed publishing process at Android official website, but this tutorial will take you through simple steps to launch your application on Google Play. Here is a simplified check list which will help you in launching your Android application − Step Activity 1 Regression Testing Before you publish your application, you need to make sure that its meeting the basic quality expectations for all Android apps, on all of the devices that you are targeting. So perform all the required testing on different devices including phone and tablets. 2 Application Rating When you will publish your application at Google Play, you will have to specify a content rating for your app, which informs Google Play users of its maturity level. Currently available ratings are (a) Everyone (b) Low maturity (c) Medium maturity (d) High maturity. 3 Targeted Regions Google Play lets you control what countries and territories where your application will be sold. Accordingly you must take care of setting up time zone, localization or any other specific requirement as per the targeted region. 4 Application Size Currently, the maximum size for an APK published on Google Play is 50 MB. If your app exceeds that size, or if you want to offer a secondary download, you can use APK Expansion Files, which Google Play will host for free on its server infrastructure and automatically handle the download to devices. 5 SDK and Screen Compatibility It is important to make sure that your app is designed to run properly on the Android platform versions and device screen sizes that you want to target. 6 Application Pricing Deciding whether you app will be free or paid is important because, on Google Play, free app”s must remain free. If you want to sell your application then you will have to specify its price in different currencies. 7 Promotional Content It is a good marketing practice to supply a variety of high-quality graphic assets to showcase your app or brand. After you publish, these appear on your product details page, in store listings and search results, and elsewhere. 8 Build and Upload release-ready APK The release-ready APK is what you you will upload to the Developer Console and distribute to users. You can check complete detail on how to create a release-ready version of your app: Preparing for Release. 9 Finalize Application Detail Google Play gives you a variety of ways to promote your app and engage with users on your product details page, from colourful graphics, screen shots, and videos to localized descriptions, release details, and links to your other apps. So you can decorate your application page and provide as much as clear crisp detail you can provide. Export Android Application Process Apk development process Before exporting the apps, you must some of tools Dx tools(Dalvik executable tools ): It going to convert .class file to .dex file. it has useful for memory optimization and reduce the boot-up speed time AAPT(Android assistance packaging tool):it has useful to convert .Dex file to.Apk APK(Android packaging kit): The final stage of deployment process is called as .apk. You will need to export your application as an APK (Android Package) file before you upload it Google Play marketplace. To export an application, just open that application project in Android studio and select Build → Generate Signed APK from your Android studio and follow the simple steps to export your application − Next select, Generate Signed APK option as shown in the above screen shot and then click it so that you get following screen where you will choose Create new keystore to store your application. Enter your key store path,key store password,key alias and key password to protect your application and click on Next button once again. It will display following screen to let you create an application − Once you filled up all the information,like app destination,build type and flavours click finish button While creating an application it will show as below Finally, it will generate your Android Application as APK formate File which will be uploaded at Google Play marketplace. Google Play Registration The most important step is to register with Google Play using Google Play Marketplace. You can use your existing google ID if you have any otherwise you can create a new Google ID and then register with the marketplace. You will have following screen to accept terms and condition. You can use Continue to payment button to proceed to make a payment of $25 as a registration fee and finally to complete your account detail. Once you are a registered user at Google Play, you can upload release-ready APK for your application and finally you will complete application detail using application detail page as mentioned in step 9 of the above mentioned checklist. Signing Your App Manually You do not need Android Studio to sign your app. You can sign your app from the command line using standard tools from the Android SDK and the JDK. To sign an app in release mode from the command line − Generate a private key using keytool $ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 Compile your app in release mode to obtain an unsigned APK Sign your app with your private key using jarsigner $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name Verify that your APK is signed. For example − $ jarsigner -verify -verbose -certs my_application.apk Align the final APK package using zipalign. $