Author Archive

To integrate latest admob interstitial ads and banner ads, you have to follow following steps:

Login to your new admob home page and Click on Monitize tab.  Select one of your app that you want to add interstitial ads, then click on the “View set up instruction” link. You will see a box like following:

Set up AdMob ad units
Follow the Google Developers website for complete instructions on how to integrate the Google AdMob SDK.

click on the “Send an email with these instruction” button, a pop will come and enter your email address and click Send Email button.

You will receive an email from admob with following:

Ad unit name: xxxxxx
Ad unit ID: ca-app-pub-xxxxxx

Copy the ad unit id, we need it to paste it in the app.

/** Android Manifest settings **/

** Don’t forget to include Google play service as library in your app. For this you have to right-click on your app and select properties and select android. There you can add Google play service.

Open android Manifest XML file and add following:


<uses-permission android:name=”android.permission.INTERNET” />
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE” />

Inside the <activity> add <meta> tag:

android:theme=”@style/AppTheme” >
<meta-data android:name=””




<!– Activity required to show ad overlays. –>
<activity android:name=””



Open your app, and add following line:

/** Your ad unit id. Replace with your actual ad unit id. */
private static final String AD_UNIT_ID = “<your ad unit id>”;

/** The interstitial ad. */
private InterstitialAd interstitialAd;

boolean interstitialStatus = false;

/* This is for banner ads */
private AdView adView;

Inside the onCreate() method, just below the setContentView(), add following:

// Create an ad.
adView = new AdView(this);

// Locate the layout to load banner ads

LinearLayout layout = (LinearLayout) findViewById(;

AdRequest adRequest1 = new AdRequest.Builder().build();

// Start loading the ad in the background.

/** Interstial ads **/

// add following just below the adView.setAdUnitId(AD_UNIT_ID);

interstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {

interstitialStatus = true;

public void onAdFailedToLoad(int errorCode) {
interstitialStatus = false;


// add a function to handle back button press:

public void onBackPressed() {
if ( interstitialStatus ) {
if ( interstitialAd.isLoaded() );

That’s it!

To fix Lint error or app_name not translated error in Android, you have to add “translate” attribute to the <string> tag entries in the string.xml file.

It is under res > values folder.

Existing lines:

<string name=”app_name”>Test App</string>

 <string name=”hello_world”>Hello world!</string>
 <string name=”menu_settings”>Settings</string>

change it to following:

<string name=”app_name” translatable=”false”>Test App</string>
 <string name=”hello_world” translatable=”false”>Hello world!</string>
 <string name=”menu_settings” translatable=”false”>Settings</string>

Clean your project (Project > Clean) and build it again.

That’s it!


Sending SMS using implicit and explicit intent

Sending SMS using implicit intent:

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(“smsto:<your phone number>”));

intent.putExtra(“sms_body”, “your message”);


Sending SMS using explicit intent:

try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(“your phone”, null, “your message”, null, null);
Toast.makeText(getApplicationContext(), “SMS sent.”,
} catch (Exception e) {
“SMS faild, please try again.”,

The following code snippet teach you on how to create a custom AlertDialog for accepting user input:

First of all, you have to create a layout file for the alert dialog:


<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=””
android:padding=”10dp” >

android:text=”Enter your name:”
android:textAppearance=”?android:attr/textAppearanceMedium” />

android:layout_height=”wrap_content” >



Open your activity file and add following:

final AlertDialog.Builder builder4 = new AlertDialog.Builder(this);
button4.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

//Inflating custom layout to alert dialog
LayoutInflater li = LayoutInflater.from(getApplicationContext());
View promptsView = li.inflate(R.layout.prompt, null);

final EditText userInput = (EditText) promptsView.findViewById(;

builder4.setPositiveButton(“OK”, new OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
System.out.println(“Your name is ” + userInput.getText().toString());

builder4.setNegativeButton(“Cancel”, new OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
System.out.println(“You pressed Cancel button”);

AlertDialog alert = builder4.create();;

The following code will show you how to download image from remote url with AsyncTask in Android

In the onCreate you have to add following code:

protected void onCreate(Bundle savedInstanceState) {
imageView = (ImageView) findViewById(;
new DownloadImageTask(imageView).execute( “http://remote_url_to_image” );

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;

protected Bitmap doInBackground(String… urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new;
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e(“Error”, e.getMessage());
return mIcon11;

protected void onPostExecute(Bitmap result) {

Incoming search terms:

  • download image from url android

The following code snippet will show you how to read Files from internal storage in Android:

byte[] buffer = null;
File file = new File(context.getFilesDir(), “myfile”);
FileInputStream fis;
String strData = null;
if( file.exists() ) {
int size;
try {
fis = new FileInputStream(file);
size = fis.available();
buffer = new byte[size];;
} catch (IOException e) {
strData = new String(buffer);


The following code snippet will show you how to write a file in the internal storage in Android:

String fname = “myfile”;
String string = data;
FileOutputStream outputStream;

try {
outputStream = openFileOutput(fname, Context.MODE_PRIVATE);
} catch (Exception e) {

The following program will display an AlertDialog with a ListView of your String array or ArrayList:


Create a string array inside your Activity class:

String [] fruits= { “Apple”, “Banana”, “Mango”,”Grapes”, “Orange”};


Inside your onCreate() method add following:

//Don't forget to create a button to trigger the Alert Dialog

final AlertDialog.Builder builder = new AlertDialog.Builder(this);

myButton.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {

builder.setItems(fruits, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

System.out.println("Selected Item:" + fruits[item]);

AlertDialog alert = builder.create();;

Thats it!

Advanced Training in Android. Online Training also available at .

Android Application Development Course Details are given below:

1. Eclipse: To Configure Eclipse to create, edit, build, and debug your Android applications and to manage project resources.

2. Android SDK: Installation, configure and use Android SDK Manager and Android Virtual Device Manager.

3. Activity Lifecycle: How activities are supposed to behave, onCreate(), onDestroy(), onPause(), onResume() and onSaveInstanceState()

4. GUI: Using XML for UI layout, Basic widgets, introductions to LinearLayout, RelativeLayout, and TableLayout.

5. Emulator: How to configure and use Android Virtual Device.

6. Resources: General theory of resources, Drawables, Values, XML and Offering multiple resource Sets

7. UI Widgets: Basic and Advanced Widget for UI Design.

8. Menu: Adding option menus, adding popup menus, showing dialogs

9. Media: Supported audio and video formats, simple audio and video playback, streaming audio and video.

10. Intents: Explicit Intents & Implicit intents.

11. Preferences and Files: Using shared preferences and simple reading and writing of files.

12. Notifications: Role of notifications, raising a notification and reacting to selected notifications.

13. Databases: Introducing SQLite, SQLiteOpenHelper and creating a database, Opening and closing a database, Working with cursors, Inserts, updates, and deletes

14. SMS, Email and Alarm: Sending an SMS and Email from your application, using AlarmManager for periodic actions and WakeLocks for work done while phone is asleep

15. Using Services: Broadcast Receivers, Services -Notifications and Toasts.

16. Maps: Adding a Google map, custom overlays with push-pins, Zoom controls and setting different map views.

17. Remote Server Communication: Use Http GET/POST for Remote Server communication via internet using AsyncTask.


Functions in Python with example

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.

As you already know, Python gives you many built-in functions like print(), etc. but you can also create your own functions. These functions are called user-defined functions.
Syntax for defining a function:

def functionname( parameters ):
return [expression]

def message():
print “Welcome to python programming”;

def yourMessage(msg):
print msg;

yourMessage(“I like Python”);

Page 1 of 5712345...102030...Last »
We Can Build Your App for You. Lets Get Started !