# data[].attributes.body
Publishing apps to Google Store

# data[].attributes.attachment_link.readable_text
Introduction: Publishing an Android App to the Google Play Store

After many hours of designing, implementing, testing, and debugging your Android Application, you are finally ready to publish it to the Google Play Store. These instructions will make the task of publishing your app both quick and painless. The process should take less then ten minutes.

You Will Need:
-A completed Android application project in Eclipse or an already created ".apk" file
-An Internet connection
-A credit/debit card to pay for Google Developer license
-At least two screenshots of the app, stored on your computer

Share

Recommendations

Microcontroller Contest

Science of Cooking

Pocket-Sized Contest

Step 1: Opening Eclipse

The first thing you will need to do is open Eclipse and ensure that your error-free project appears in the package explorer on the left.

*Note: If you are not using eclipse or you have already exported an ".apk" file, you may skip to Step: 10.

Step 4: Checking for Errors

Step 5: Entering a Keystore

Step 7: Choosing a Password

Step 9: Choosing File Export Destination

The last step in exporting the app to a file is to click "browse" and select a destination to store the ".apk," or android application package file.

A good place to store it is in the same directory that the project file exists.

Click "finish," to export the file, and then exit eclipse.

It is now time to upload the newly created ".apk" file to the google store.

Step 12: Adding a New Application

Once inside the console, click the blue button at the top labeled, "+ Add New Application."

Step 14: Initiating APK Upload (part 2)

At the new homepage for your app, select the blue button labeled "Upload your first APK to Production," centered on your screen.

Step 19: Filling in Details

Step 21: Publishing the Application

Once all three tabs at the left have a green check-mark, you are now able to select "Publish this app" from the "Ready to Publish" drop-down menu in the top right corner of the developer console.

A confirmation bar should appear at the top, stating that your app will appear in the Google Play store in just a few hours.

Step 22: Conclusion

We have a be nice policy.
Please be positive and constructive.

# data[].attributes.attachment_link.title
Publishing an Android App to the Google Play Store

# data[].attributes.attachment_link.description
After many hours of designing, implementing, testing, and debugging your Android Application, you are finally ready to publish it to the Google Play Store. These instructions will make the task of publishing your app both quick and painless. The process should take less then ten minutes.

# data[].attributes.body
PUBLISHING ANDROIDAPPS

# data[].attributes.attachment_link.readable_text
Tools & Technologies used in this article :

Recommended Posts

There are two ways to export Aplication Package in Eclipse using Android Tools

1. Export Unsigned Application Package

2. Export Signed Application Package

1. Export Unsigned Application Package

Right click on the Android project (say 'AndroidHello') and from the context menu select Android Tools --> Export Unsigned Appliaction Package. Browse the location to save the apk and click Save button. Click Ok button in the following window to proceed.

Note:
Android system will not allow to install an application on an emulator or a device unless it is digitally signed with a certificate whose private key is held by the application's developer.

2. Export Signed Application Package

Right click on the Android project (say 'AndroidHello') and from the context menu select Android Tools --> Export Signed Appliaction Package. Select the project to export and Click Next button.

Keystore Selection

To publish the android application we need to create digitally signed apk. Here we'll create a self signed certificate / keystore. Click Create new keystore radio and provide the location and password for keystore. Click Next button.

Key Creation

Fill the form to create key and click Next button.

Destination and key/certificate checks

Browse the location where apk file will be saved and click Finish button.

Finally apk file will be created and ready for installation in android device.

References

# data[].attributes.attachment_link.title
Build Android application package file (APK) using Eclipse IDE and Android Developer Tools (ADT) Plugin - SrcCodes

# data[].attributes.attachment_link.description
Tools & Technologies used in this article : There are two ways to export Aplication Package in Eclipse using Android Tools Export Unsigned Application Package Export Signed Application Package Right click on the Android project (say 'AndroidHello') and from the context menu select Android Tools --> Export Unsigned Appliaction Package.

# data[].attributes.body
Lab 4

# data[].attributes.body
LAB 3 24/2/15

# data[].attributes.body
SMS

# data[].attributes.attachment_link.readable_text
In Android, you can use SmsManager API or device's Built-in SMS application to send a SMS message. In this tutorial, we show you two basic examples to send SMS message :

1. SmsManager API
 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);

2. Built-in SMS application
 Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent);

Of course, both need SEND_SMS permission.
P.S This project is developed in Eclipse 3.7, and tested with Samsung Galaxy S2 (Android 2.3.3).
Note
The Built-in SMS application solution is the easiest way, because you let device handle everything for you.

1. SmsManager Example

Android layout file to textboxes (phone no, sms message) and button to send the SMS message.
File : res/layout/main.xml
 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/textViewPhoneNo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enter Phone Number : " android:textAppearance="?android:attr/textAppearanceLarge" /> <EditText android:id="@+id/editTextPhoneNo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:phoneNumber="true" > </EditText> <TextView android:id="@+id/textViewSMS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enter SMS Message : " android:textAppearance="?android:attr/textAppearanceLarge" /> <EditText android:id="@+id/editTextSMS" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" android:lines="5" android:gravity="top" /> <Button android:id="@+id/buttonSend" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send" /> </LinearLayout>

File : SendSMSActivity.java - Activity to send SMS via SmsManager.

 package com.mkyong.android; import android.app.Activity; import android.os.Bundle; import android.telephony.SmsManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class SendSMSActivity extends Activity { Button buttonSend; EditText textPhoneNo; EditText textSMS; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); buttonSend = (Button) findViewById(R.id.buttonSend); textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo); textSMS = (EditText) findViewById(R.id.editTextSMS); buttonSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String phoneNo = textPhoneNo.getText().toString(); String sms = textSMS.getText().toString(); try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, sms, null, null); Toast.makeText(getApplicationContext(), "SMS Sent!", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }); } }

File : AndroidManifest.xml , need SEND_SMS permission.

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mkyong.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.SEND_SMS" /> <application android:debuggable="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".SendSMSActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

See demo :

2. Built-in SMS application Example

This example is using the device's build-in SMS application to send out the SMS message.

File : res/layout/main.xml - A button only.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/buttonSend" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send" /> </LinearLayout>

File : SendSMSActivity.java - Activity class to use build-in SMS intent to send out the SMS message.

 package com.mkyong.android; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class SendSMSActivity extends Activity { Button buttonSend; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); buttonSend = (Button) findViewById(R.id.buttonSend); buttonSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }); } }

See demo :

Download Source Code

References

# data[].attributes.attachment_link.description
In Android, you can use SmsManager API or device's Built-in SMS application to send a SMS message. In this tutorial, we show you two basic examples to send SMS message : SmsManager API SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("phoneNo", null, "sms message", null, null); Built-in SMS application Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.putExtra("sms_body", "default content"); sendIntent.setType("vnd.android-dir/mms-sms"); startActivity(sendIntent); Of course, both need SEND_SMS permission.

# data[].attributes.body
CALL

# data[].attributes.attachment_link.readable_text
In this tutorial, we show you how to make a phone call in Android,and monitor the phone call states via PhoneStateListener.
P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.
1 Android Layout Files

Simpel layout file, to display a button.
File : res/layout/main.xml
 <?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" > <Button android:id="@+id/buttonCall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="call 0377778888" /> </LinearLayout>

2. Activity

Use below code snippet to make a phone call in Android.

 Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:0377778888")); startActivity(callIntent);

File : MainActivity.java - When the button is call, make a phone to 0377778888.

 package com.mkyong.android; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { private Button button; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.buttonCall); // add button listener button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:0377778888")); startActivity(callIntent); } }); } }

3 Android Manifest

To make a phone call, Android need CALL_PHONE permission.
File : AndroidManifest.xml
 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mkyong.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".MainActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

4. PhoneStateListener example

Ok, now we update the above activity, to monitor the phone call states, when a phone call is ended, come back to the original activity (actually, it just restart the activity). Read comment, it should be self-explanatory.

Note
Run it and refer to the logcat console to understand how PhoneStateListener works.
File : MainActivity.java
 package com.mkyong.android; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class MainActivity extends Activity { final Context context = this; private Button button; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button) findViewById(R.id.buttonCall); // add PhoneStateListener PhoneCallListener phoneListener = new PhoneCallListener(); TelephonyManager telephonyManager = (TelephonyManager) this .getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE); // add button listener button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:0377778888")); startActivity(callIntent); } }); } //monitor phone call activities private class PhoneCallListener extends PhoneStateListener { private boolean isPhoneCalling = false; String LOG_TAG = "LOGGING 123"; @Override public void onCallStateChanged(int state, String incomingNumber) { if (TelephonyManager.CALL_STATE_RINGING == state) { // phone ringing Log.i(LOG_TAG, "RINGING, number: " + incomingNumber); } if (TelephonyManager.CALL_STATE_OFFHOOK == state) { // active Log.i(LOG_TAG, "OFFHOOK"); isPhoneCalling = true; } if (TelephonyManager.CALL_STATE_IDLE == state) { // run when class initial and phone call ended, // need detect flag from CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE"); if (isPhoneCalling) { Log.i(LOG_TAG, "restart app"); // restart app Intent i = getBaseContext().getPackageManager() .getLaunchIntentForPackage( getBaseContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); isPhoneCalling = false; } } } } }

Update Android Manifest file again, PhoneStateListener need READ_PHONE_STATE permission.
File : AndroidManifest.xml
 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mkyong.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".MainActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>

5. Demo

Activity started, just display a button.

When button is clicked, make a phone call to 0377778888.

When phone call is hang out or ended, restart the main activity.

Download Source Code

References

1. Android PhoneStateListener Javadoc

2. Android TelephonyManager Javadoc

3. Android Intent Javadoc

# data[].attributes.attachment_link.description
In this tutorial, we show you how to make a phone call in Android,and monitor the phone call states via PhoneStateListener. P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3. Simpel layout file, to display a button. File : res/layout/main.xml Use below code snippet to make a phone call in Android.

# data[].attributes.body
BROADCAST RECIEVERS 28/1/15

# data[].attributes.attachment_link.readable_text
The Android system uses broadcasts messages (often are called Intents or Events) to transfer information to applications. The Broadcasts can be sent either by Android apps or, most commonly, by the system itself. There are many system generated events that Intent class defines for receiving broadcasts, which some of them you can find in the Standard Broadcast Actions of Android Content. In this tutorial we are going to show you step by step how to create a BroadcastReceiver that receives a custom , which contains data that the user gave from the screen.

For this tutorial, we will use the following tools in a Windows 64-bit platform:

1. Create a New Android Application Project

Open Eclipse IDE and go to File → New → Project → Android Application Project.

Name the application, the project and the package in the appropriate fields and then click next.

In the next window, the "Create Activity" option should be checked. The new activity will be the main activity of your project. Then press next button.

In "Configure Launcher Icon" window you should choose the icon you want to have in your app. In our occasion, we will use the default icon of android, so just press next.

Select the "Blank Activity" option and press next.

You have to specify a name for the new Activity and a name for the layout description of your app. The .xml file for the layout will automatically be created in the res/layout folder. Press Finish.

2. Generate a BroadcastReceiver

Right click to com.javacodegeeks.android.broadcastreceiverstest package → New → Class.

Specify the name for the new Class and the package you want to put it. We will name it MyBroadcastReceiver and we will put it in the same package as the MainActivity.java file.

MyBroadcastReceiver is a subclass of BroadcastReceiver Android Class and in order to receive an Intent broadcast, we override the onReceive() method. As we can see in the following code, the field intentData is the message that MyBroadcastReceiver receives from the custom Intent.

Open src/com.javacodegeeks.android.broadcastreceiverstest/MyBroadcastReceiver.java and paste the following code:
MyBroadcastReceiver.java:
package com.javacodegeeks.android.broadcastreceiverstest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyBroadcastReceiver extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub

		// Extract data included in the Intent
		CharSequence intentData = intent.getCharSequenceExtra("message");
		Toast.makeText(context, "Javacodegeeks received the Intent's message: "+intentData, Toast.LENGTH_LONG).show();
	}

}

3. Broadcast a custom Intent

At this point, we want our application to broadcast a custom Intent, so we need to create and send one. To broadcast the intent to all the interested BroadcastReceivers, we use either sendBroadcast(Intent) method, or sendStickyBroadcast(Intent) method. The difference between these two methods is that in the second one, the sent intent stays even if the broadcast is completed, so the announce information remains accessible in order to be given to others BroadcastReceivers in the future.

Open src/com.javacodegeeks.android.broadcastreceiverstest/MainActivity.java and paste the following code.

package com.javacodegeeks.android.broadcastreceiverstest;

import com.javacodegeeks.android.broadcastreceiverstest.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void broadcastCustomIntent(View view)
    {
       Intent intent = new Intent("MyCustomIntent");

       EditText et = (EditText)findViewById(R.id.extraIntent);
       // add data to the Intent
       intent.putExtra("message", (CharSequence)et.getText().toString());
       intent.setAction("com.javacodegeeks.android.A_CUSTOM_INTENT");
       sendBroadcast(intent);
    }

}

As we can see from the code above, at the broadcastCustomIntent(View view) method we generate an Intent and we put into it an extra field, called message. The value of this field is taken from an EditText (id=extraIntent) in the layout of the app. The error you will notice is because we didn't define the EditText yet.

4. Register BroadcastReceiver

We should define our broadcast receiver and register the above intent ( com.javacodegeeks.android.A_CUSTOM_INTENT) in the AndroidManifest.xml file. That's the way the BroadcastReceiver and the Intents get linked. If the user presses the button, then the MyBroadcastReceiver will be notified. Generally, we can add many intents, but we have to register each one in our AndroidManifest.xml file using <receiver> ... </receiver> tags.

To add our custom Intent, open AndroidManifest.xml file, at the last tab - named "AndroidManifest.xml" - and paste the following code.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.javacodegeeks.android.broadcastreceiverstest"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.javacodegeeks.android.broadcastreceiverstest.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>

        <receiver android:name="MyBroadcastReceiver">
      	        <intent-filter>
                        <action android:name="com.javacodegeeks.android.A_CUSTOM_INTENT">
      	                </action>
      	        </intent-filter>
   	 </receiver>
    </application>
</manifest>

5. User Interface

In this app, we want an android user to broadcast the message, so we make a simple user interface. We create an editText and a button in the res/layout/activity_main.xml file. As we said above, we use the value of the editText in order to put data in the Intent. Also, we connect the button with the broadcastCustomIntent(View view) function, so when the button is been pressed, the function is enabled.

Open the res/layout/activity_main.xml file and choose the "activity_main.xml" tab. Then paste the following code.

<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" >

    <EditText android:id="@+id/extraIntent"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="@string/sendMessage" />

   <Button
       android:id="@+id/btnStartBroadcast"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_alignParentLeft="true"
       android:layout_below="@+id/extraIntent"
       android:onClick="broadcastCustomIntent"
       android:text="@string/myBroadcastIntent" />

</RelativeLayout>

You will notice an error in the following lines of that file.

android:hint="@string/sendMessage"
android:text="@string/myBroadcastIntent"

That is happening because we didn't define the strings myBroadcastIntent and sendMessage.

To solve these problems, go to res/values/strings.xml file at the "strings.xml" tab, as shown in the image below.

Then paste the following code.

<?xml version="1.0" encoding="utf-8"?>
<resources>
        <string name="app_name">BroadcastReceiversTest</string>
        <string name="action_settings">Settings</string>
        <string name="sendMessage">Write a message to broadcast!</string>
        <string name="myBroadcastIntent">Broadcast an Intent now...</string>
</resources>

6. Run the Application

Now we are ready to run our application. To do this, right click to our project → Run as → Android Application. The AVD will appear with the app loaded.

If we put a simple string (for instance: Broadcast Message) and press the button, a Toast will appear, containing that message (underlined in the picture below). This Toast is generated in the onReceive() function of the MyBroadcastReceiver, in which the message is extracted from the com.javacodegeeks.android.A_CUSTOM_INTENT.

Download Eclipse Project

This was an example of Broadcast Receivers in Android. Download the Eclipse Project of this example: BroadcastReceiversTest.zip

# data[].attributes.attachment_link.description
The Android system uses broadcasts messages (often are called Intents or Events) to transfer information to applications. The Broadcasts can be sent either by Android apps or, most commonly, by the system itself. There are many system generated events that Intent class defines for receiving broadcasts, which some of them you can find in the ...

# data[].attributes.body
INTENTS AND EXCHANGE DATA 28/1/15

# data[].attributes.attachment_link.description
Implicit intents specify the action which should be performed and optionally data which provides content for the action. If an implicit intent is sent to the Android system, it searches for all components which are registered for the specific action and the fitting data type.

# data[].attributes.body
NOTIFICATIONS 28/1/15

# data[].attributes.body
ASYNCTASK 27/1/15

# data[].attributes.attachment_link.readable_text
In this tutorial we are going to see how to use Android . As we read from the Android Documentation :

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

AsyncTask is designed to be a helper class around and and does not constitute a generic threading framework. AsyncTasks should ideally be used for short operations (a few seconds at the most.) If you need to keep threads running for long periods of time, it is highly recommended you use the various APIs provided by the java.util.concurrent pacakge such as , ThreadPoolExecutor andFutureTask.

An asynchronous task is defined by a computation that runs on a background thread and whose result is published on the UI thread. An asynchronous task is defined by 3 generic types, called Params, Progress andResult, and 4 steps, called onPreExecute, doInBackground, onProgressUpdate and onPostExecute.

In this example we are going to load a web page in the backgroud and display it in a . We will notice that the UI thread still remains fast and responsive in other UI activities.

For this tutorial, we will use the following tools in a Windows 64-bit platform:

1. Create a new Android Project

Open Eclipse IDE and go to File -> New -> Project -> Android -> Android Application Project. You have to specify the Application Name, the Project Name and the Package name in the appropriate text fields and then click Next.

In the next window make sure the "Create activity" option is selected in order to create a new activity for your project, and click Next. This is optional as you can create a new activity after creating the project, but you can do it all in one step.

Select "BlankActivity" and click Next.

You will be asked to specify some information about the new activity. In the Layout Name text field you have to specify the name of the file that will contain the layout description of your app. In our case the file res/layout/main.xml will be created. Then, click Finish.

2. Create the main layout of the Application

Open res/layout/main.xml file :

And paste the following code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="readWebpage"
        android:text="Load Webpage" >
    </Button>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="dummyFunc"
        android:text="Dummy Button" />

    <WebView
        android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

Now you may open the Graphical layout editor to preview the User Interface you created:

3. Code

Now we have to write the code of the application. Use the Package Explorer to navigate to the Java file of the Activity you've created:

The code of this tutorial is pretty much self explanatory.

package com.javacodegeeks.android.androidasynctasktutorial;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Toast;

public class MainActivity extends Activity {
	final Context context = this;

	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

	}

	private class LoadWebPageASYNC extends AsyncTask<String, Void, String> {

		@Override
		protected String doInBackground(String... urls) {

			WebView webView = (WebView) findViewById(R.id.webView);
			webView.getSettings().setJavaScriptEnabled(true);
			webView.loadUrl(urls[0]);

			return null;
		}

		@Override
		protected void onPostExecute(String result) {

		}
	}

	public void dummyFunc(View view){
		Toast.makeText(MainActivity.this, "Button Clicked", Toast.LENGTH_SHORT).show();

	}

	public void readWebpage(View view) {
		LoadWebPageASYNC task = new LoadWebPageASYNC();
		task.execute(new String[] { "http://www.javacodegeeks.com" });

	}
}

4. Run the application

This is the main screen of our Application:

Now, when you press the "Load Webpage" button, the AsyncTask will start downloading and loading the Web Page. But, meanwhile if whe press the "Dummy Button", you will see that the UI remains responsive. As you can see the web pages is loading and the UI is fast and responsive:

After a little while:

Download Eclipse Project

This was an Android Timer Example. Download the Eclipse Project of this tutorial: AndroidAsyncTaskTutorial.zip

# data[].attributes.attachment_link.description
In this tutorial we are going to see how to use Android AsyncTask. As we read from the Android Documentation : AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

# data[].attributes.body
SERVICES 27/1/15

# data[].attributes.attachment_link.readable_text
In this example we are going to learn about Android Service. The Android Service is one of the most important components and building blocks in an Android System. One obvious characteristic of the Service component is that it offers no UI. It's simply a program that runs on the background as log as it is required.

It is important to notice that Services are either Threads nor processes or Activities. You should use Android Services when you have to perform a time consuming and long task, like loading an Image, or a File, or download something for the Internet and asynchronous tasks in general. Using a Service you can let the UI Thread handle only UI tasks.

Basically, there are two types of Services:

Unbounded : This type of Service is also called Started. This Service is completely independent for the Activity that called it and there is no communication or interaction between them. The Service simply starts (using startService), does its job and stops(using stopService) without the Activity noticing anything.

Bounded : This type of Service offers communication and interaction between the Service and the Activity that launched it. Using Messagers and BroadcastReceivers the Activity can at any moment monitor the status or the progress of the background task that the Service is performing. Additionally the Service can get useful feedback from the Activity.

In this example we are going to create a simple ubounded service example. For this tutorial, we will use the following tools in a Windows 64-bit platform:

1. main.xml File

This is the basic UI that we are going to use. Two buttons that simply start and stop the service:

<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" >

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentRight="true"
        android:onClick="stopNewService"
        android:text="Stop Service" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="23dp"
        android:onClick="startNewService"
        android:text="Start Service" />

</RelativeLayout>

2. MyService.java

To create a new Service simply create a new class that extends Service and override the appropriate methods:

package com.javacodegeeks.android.androidserviceexample;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class MyService extends Service {
	public MyService() {
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO: Return the communication channel to the service.
		throw new UnsupportedOperationException("Not yet implemented");
	}

	@Override
    public void onCreate() {
        Toast.makeText(this, "The new Service was Created", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onStart(Intent intent, int startId) {
    	// For time consuming an long tasks you can launch a new thread here...
        Toast.makeText(this, " Service Started", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onDestroy() {
        Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();

    }
}

3. MainActivity.java

This is the main activity of our Application:

package com.javacodegeeks.android.androidserviceexample;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	// Start the  service
	public void startNewService(View view) {

		startService(new Intent(this, MyService.class));
	}

	// Stop the  service
	public void stopNewService(View view) {

		stopService(new Intent(this, MyService.class));
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}

4. Run the application

This is the main screen of our Application:

Now, when you press the "Start Service" the Service will be created:

After a little bit, you will notice that the Service will start:

And, when you press "Stop Service" the Service will be killed:

Download Eclipse Project

This was an Android ServiceExample. Download the Eclipse Project of this tutorial: AndroidServiceExample.zip

# data[].attributes.attachment_link.description
In this example we are going to learn about Android Service. The Android Service is one of the most important components and building blocks in an Android System. One obvious characteristic of the Service component is that it offers no UI. It's simply a program that runs on the background as log as it is ...

# data[].attributes.body
THREADS 27/1/15

# data[].attributes.attachment_link.readable_text
In this example we are going to see how to use Android . As we read from the official documentation:

A Thread is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables. Each virtual machine instance has at least one main Thread running when it is started; typically, there are several others for housekeeping. The application might decide to launch additional Threads for specific purposes.

Threads in the same VM interact and synchronize by the use of shared objects and monitors associated with these objects. Synchronized methods and part of the API in also allow Threads to cooperate.

There are basically two main ways of having a Thread execute application code. One is providing a new class that extends Thread and overriding its method. The other is providing a new Thread instance with a object during its creation. In both cases, the method must be called to actually execute the new Thread.

Each Thread has an integer priority that basically determines the amount of CPU time the Thread gets. It can be set using the setPriority(int) method. A Thread can also be made a daemon, which makes it run in the background. The latter also affects VM termination behavior: the VM does not terminate automatically as long as there are non-daemon threads running.

For this tutorial, we will use the following tools in a Windows 64-bit platform:

1. Create a new Android Project

Open Eclipse IDE and go to File -> New -> Project -> Android -> Android Application Project. You have to specify the Application Name, the Project Name and the Package name in the appropriate text fields and then click Next.

In the next window make sure the "Create activity" option is selected in order to create a new activity for your project, and click Next. This is optional as you can create a new activity after creating the project, but you can do it all in one step.

Select "BlankActivity" and click Next.

You will be asked to specify some information about the new activity. In the Layout Name text field you have to specify the name of the file that will contain the layout description of your app. In our case the file res/layout/main.xml will be created. Then, click Finish.

2. Create the main layout of the Application

Open res/layout/main.xml file :

And paste the following code :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:indeterminate="false"
        android:max="10"
        android:padding="4dip" >
    </ProgressBar>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="startProgress"
        android:text="Start" />

</LinearLayout>

Now you may open the Graphical layout editor to preview the User Interface you created:

3. Code

Now we have to write the code of the application. Use the Package Explorer to navigate to the Java file of the Activity you've created:

The code of this tutorial is pretty much self explanatory. The interesting part is how to update the value of the Progress bar. We are going to use a Thread to run the backgroud process that updates tha value of the progress bar. Although this example works fine, it is strongly advised to use a Handler or an AsyncTask to explicity bind the backroud thread with the UI thread.

package com.javacodegeeks.android.androidthreadexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;

public class MainActivity extends Activity {
	private ProgressBar bar;

	/** Called when the activity is first created. */

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		bar = (ProgressBar) findViewById(R.id.progressBar1);

	}

	public void startProgress(View view) {

		bar.setProgress(0);
		new Thread(new Task()).start();
	}

	class Task implements Runnable {
		@Override
		public void run() {
			for (int i = 0; i <= 10; i++) {
				final int value = i;
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				bar.setProgress(value);

			}
		}

	}

}

4. Run the application

This is the main screen of our Application.

Now, when you press the "Start" button, the thread that updates the bar's value :

Download Eclipse Project

This was an Android Thread Example. Download the Eclipse Project of this tutorial: AndroidThreadExample

# data[].attributes.attachment_link.description
In this example we are going to see how to use Android Thread. As we read from the official documentation: A Thread is a concurrent unit of execution. It has its own call stack for methods being invoked, their arguments and local variables.

# data[].attributes.body
Action Bar

# data[].attributes.attachment_link.readable_text
In this tutorial we are going to see how to create a simple Android Menu using . It is a very handy kit when you want to create simple Menus for your application. In this tutorial we are going to see how to create a simple menu with 3 options and with Icons.

For this tutorial, we will use the following tools in a Windows 64-bit platform:

1. Create a new Android Project

Open Eclipse IDE and go to File -> New -> Project -> Android -> Android Application Project.

You have to specify the Application Name, the Project Name and the Package name in the appropriate text fields and then click Next.

In the next window make sure the "Create activity" option is selected in order to create a new activity for your project, and click Next. This is optional as you can create a new activity after creating the project, but you can do it all in one step.

Select "BlankActivity" and click Next.

You will be asked to specify some information about the new activity. In the Layout Name text field you have to specify the name of the file that will contain the layout description of your app. In our case the file res/layout/main.xml will be created. Then, click Finish.

2. Add Drawable resources

In order to display Icons instead of text in the ActionBar, we need to add the images we want in the drawable resources. Go to package Explorer. You can drag and drop the images from your local files to the project files. As you can see I've copied 3 images.

3. Creating the menu items

Open res/menu/main.xml file :

And paste the following code :

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
    <item
        android:id="@+id/home"
        android:icon="@drawable/home"
        android:orderInCategory="1"
        android:showAsAction="always"
        android:title="Home"/>

    <item
        android:id="@+id/java"
        android:icon="@drawable/java"
        android:orderInCategory="2"
        android:showAsAction="always"
        android:title="Java"/>

    <item
        android:id="@+id/android"
        android:icon="@drawable/android"
        android:orderInCategory="3"
        android:showAsAction="always"
        android:title="Android"/>

</menu>

Now let's see what all these attributes do:

First of all, android:orderInCategory dictates the position of the Item in the ActionBar.

android:showAsAction defines the way we want the Item to be displayed. For example, in our case we want the items to be always visible. We can change that to ifRoom. Now, Android will see if there is sufficient room in the screen, and if there is the option will be displayed. Else it will be places to the Overflow option. Additionally you can choose never as value. In this case the option will be hidden.

android:icon will define the icon of the option, which as you can see, will be a drawable resource.

4. Code the Main Activity

Use the Package Explorer to navigate to the Java file of the Activity you've created:

package com.javacodegeeks.android.androidactionbarexample;

import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	@SuppressLint("NewApi")
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {

		switch (item.getItemId()) {

		case R.id.home:
			homeActivity();
			return true;

		case R.id.java:
			javaActivity();
			return true;

		case R.id.android:
			androidActivity();
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}

	}

	public void homeActivity() {
		Toast.makeText(this, "Home Option Selexted", Toast.LENGTH_SHORT).show();
	}

	public void javaActivity() {
		Toast.makeText(this, "Java Option Selexted", Toast.LENGTH_SHORT).show();
	}

	public void androidActivity() {
		Toast.makeText(this, "Android Option Selexted", Toast.LENGTH_SHORT).show();
	}

}

5. Run the application

This is the main screen of our Application:

Now, when you press the on one of the options :

Of course you can customize the Actions as much as you want...

Download Eclipse Project

This was an Android Action Bar and Menus Example. Download the Eclipse Project of this tutorial: AndroidActionBarExample.zip

# data[].attributes.attachment_link.description
In this tutorial we are going to see how to create a simple Android Menu using ActionBar. It is a very handy kit when you want to create simple Menus for your application. In this tutorial we are going to see how to create a simple menu with 3 options and with Icons.

# data[].attributes.body
Fragment

# data[].attributes.attachment_link.description
Android Fragments - Learn Android Programming and how to develop android mobile phone and ipad applications starting from Environment setup, application components, activity lifecycle, service lifecycle, application architecture, publishing application, debugging applications, handling events, layouts, menus, user interface controls, styles and themes, handling rotation, fonts management, send email, data storage, managing media, send sms, phone calls.

# data[].attributes.body
TOPIC 3 : ACTIVITY

# data[].attributes.attachment_link.description
Android, an open source operating system for mobile devices (Smartphone and tablet), led by Google. The Android SDK provides a set of tools and APIs to develop Android applications, using Java. So, if you know Java, Android programming is easy :)

# data[].attributes.body
OurFirstHello

# data[].attributes.attachment_link.description
Android Hello World Example - Learn Android Programming and how to develop android mobile phone and ipad applications starting from Environment setup, application components, activity lifecycle, service lifecycle, application architecture, publishing application, debugging applications, handling events, layouts, menus, user interface controls, styles and themes, handling rotation, fonts management, send email, data storage, managing media, send sms, phone calls.

# data[].attributes.body
TOPIC 1