Thursday, June 28, 2012

Disable Title Bar or Full Screen View in Android

Today i learn how to disable Notification bar (Battery, Network Status info Bar ) Top of the Screen.

and how can we set Full Screen View to Our Application Screen.

Just a pretty simple code see below..

//to disable notification bar (Top Bar)
  requestWindowFeature(Window.FEATURE_NO_TITLE);
     
 //to set full screen view
  getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                       WindowManager.LayoutParams.FLAG_FULLSCREEN);

Note: Above code put before loading the main view or we can say before this line
setContentView(R.layout.main);

also i made simple app to achieve this if need then have look on it.

-------------------------------------------
App Name: DisableTitleBar
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: MyActivity
-------------------------------------------
so here is the code 

MyActivity.java

package com.rdc;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MyActivity extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
        
     //to disable notification bar (Top Bar)
     requestWindowFeature(Window.FEATURE_NO_TITLE);
        
     //to set full screen view
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
     //make sure code should be before calling below method
     setContentView(R.layout.main);
  }
}

main.xml

 
 
  
 



AndroidManifest.xml




 
  
  
  
  
 




The output will be like this..



I'd love to hear your thoughts!

Friday, June 15, 2012

Disable Soft KeyPad in Android

Today we will learn another small trick to disable the softkeypad in Android

Sometime you need to disable the Soft Keypad / Virtual Keypad and want to input from either Physical Keypad or Design your own keypad.

Pretty simple and only single line code i have written below

        //disable soft keypad
        txtName.setInputType(InputType.TYPE_NULL);


also i made simple app to achieve this if need then have look on it.

-------------------------------------------
App Name: DisableKeypad
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: DisableKeypadActivity
-------------------------------------------
so here is the code

DisableKeypadActivity.java

package com.rdc;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.widget.EditText;

public class DisableKeypadActivity extends Activity {
    private EditText txtName=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        setContentView(R.layout.main);
        
        //get the id of edit text 
        txtName =(EditText) findViewById(R.id.txtName);
        
        //disable soft keypad
        txtName.setInputType(InputType.TYPE_NULL);
    }
}

main.xml

 
 
  
 



AndroidManifest.xml




 
  
  
  
  
 




Tested on Real Androd Device [Sony Ericsson (XPERIA)] the output will be like this..


I'd love to hear your thoughts!

Sunday, June 10, 2012

How to add Google ads in Android apps (Google Admob Ads)

These day you can find many Android app are having great features you know what still they are FREE available in Android Market/Google Play why?

Because many of those earning money through Google Ad-mob Ads showing in the apps.

so the question is how we can integrated these Google or Any ads into our Android Apps.

I am going to write this page to achieve this....

Before starting codding stuff we need  Google Advertisement Publisher ID.

Get Ads Publisher ID

First of all you need to sign-up account at Google AdSense
if you don't have then fill-up some bank and transaction stuff you will get you client ID

eg. Mine is "a1500db2724b9b8"

okay now let's create a small app with...
 -------------------------------------------
App Name: GoogleAdMob
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 /  API 10
Default Activity Name: ActivityGoogleAdMob
-------------------------------------------


Download and Add Google AdMob SDK

You can download latest Google AdMob Ads SDK here
now we need to add this sdk into our GoogleAdMob app

So right click on project --> properties-->
java build path -->Libraries-->Add External JARs see below image




Now start some coding stuff this way... your main activity should be..

ActivityGoogleAdMob.java

package com.rdc;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class ActivityGoogleAdMob extends Activity {
	private AdView adView = null;
	private static final String ADMOB_ID = "a1500db2724b9b8";

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

		// Create the adView
		adView = new AdView(this, AdSize.BANNER, ADMOB_ID);

		// Lookup your LinearLayout assuming it’s been given
		// the attribute android:id="@+id/mainLayout"
		LinearLayout lay = (LinearLayout) findViewById(R.id.mainLayout);

		// Add the adView to it
		lay.addView(adView);

		// Initiate a generic request to load it with an ad
		adView.loadAd(new AdRequest());
	}

	@Override
	public void onDestroy() {
		if (adView != null) {
			adView.destroy();
		}
		super.onDestroy();
	}

}

main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/mainLayout">
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>


Manifest file will be
<?xml version="1.0" encoding="utf-8"?>
<manifest
	xmlns:android="http://schemas.android.com/apk/res/android"
	package="com.rdc"
	android:versionCode="1"
	android:versionName="1.0">
	<uses-sdk android:minSdkVersion="10" />

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

	<application
		android:icon="@drawable/icon"
		android:label="@string/app_name">
		<activity
			android:name=".ActivityGoogleAdMob"
			android:label="@string/app_name">
			<intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
		</activity>

		<activity
			android:name="com.google.ads.AdActivity"
			android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
	</application>
</manifest>

Note: you must have app target is API 13 or newer
see the file "default.properties"
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-13

The output Screen will be like this..



You can download the Google AdMobSDK 6.0 and complete source code zip file here : GoogleAdMob

cheers!!

 I'd love to hear your thoughts!

Saturday, June 2, 2012

Disable Android Screen Rotation/Orientation

Some time you need to Disable or Lock the screen orientation.

just need to add this code in your activity which you want to lock


//for Portrait Mode only
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                                                           or
//for Landscape Mode only
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

well its pretty simple to achieve this, still i have created a small app
-------------------------------------------
App Name: DisableScreenOrientation
Package Name: com.rdc
Android SDK: Android SDK 2.3.3 / API 10
Default Activity Name: MyActivity
-------------------------------------------
so here is the code

MyActivity.java

package com.rdc;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

public class MyActivity extends Activity {
   
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
        
      //if you want to lock screen for always Portrait mode
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        
      //if you want to lock screen for always Landscape mode
      //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }
}

main.xml

 

and the manifest file is
 AndroidManifest.xml




 
  
   
   
   
  
 


Tested on Real Androd Device [Sony Ericsson (XPERIA)] the output will be like this..


I'd love to hear your thoughts!