Monday, November 21, 2011

Mobile Payments Library for Android

The PayPal Mobile Payments Library lets you accept PayPal payments within your mobile app. A buyer stays in your app while logging in to PayPal, reviewing a purchase, and completing a payment. The library provides the buyer's shipping, billing, and payment information to your app.

Please click here  for library and source code .

Thursday, November 3, 2011

Get SIM card number

 TelephonyManager teleManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
 String simNo = teleManager .getSimSerialNumber();

You also need to provide android.permission.READ_PHONE_STATE permission in android manifest file.

Saturday, October 22, 2011

Uninstall Apps from device using Intent.

You can uninstall App from device using following code.

Uri packageURI = Uri.parse("package:com.any.app");
startActivity(new Intent(Intent.ACTION_DELETE, packageURI));



Monday, October 17, 2011

Android Screencast for displaying device screen on computer

Android screen cast can display my Android device (phone or tablet) on a computer screen . It works on my HTC Legend running Android 2.2 .

The screencast will display the device screen on the computer. For rooted ROM, you can also use the computer keyboard and mouse to control the device.It doesn’t handle device screen rotation at all. So phone will display in portrait mode only and tablet in landscape mode only.

Apart from the above, it is a great tool when doing presentation with Android devices. Plug and USB cable and run the software and your audience will be able to see your device screen. No more messy setup of a separate overhead projection unit. And the display quality is way better.

You can Download the Screen Cast from Here.




Wednesday, September 28, 2011

How to get your MD5 Fingerprint for Android using Eclipse Keytool Plugin

If you're looking for easier ways to get your MD5 fingerprint without using the command line or terminal, then might as well follow this tutorial.

Get MD5 Fingureprint for Google Map.



Thursday, September 22, 2011

How To Enable the Android Market in the Google Android Emulator

If you want to enable the android market in android emulator then please follow the below link . There you can find great tutorial about android market on emulator.

Install Android Market on Emulator.

Saturday, September 17, 2011

Check Airplane Mode

Below function checks weather your device is in Airplane Mode or Not
*******************************************************************

public boolean isAirplaneMode(Context context)
{
int settingValue;
try
{
settingValue = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON);
return settingValue != 0;
} catch (SettingNotFoundException e)
{
return false;
}
}

Get Ip Address of device

Below function returns the Ip Address of Android Device
*******************************************************

public String getLocalIpAddress() {
try {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e(LOG_TAG, ex.toString());
}
return null;
}

Show all running Service in android

Below Code shows all the running service .

ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
List rs = am.getRunningServices(50);

for (int i=0; i {
ActivityManager.RunningServiceInfo
rsi = rs.get(i);
Log.i("Service", "Process " + rsi.process + " with component " + rsi.service.getClassName());
}

Friday, September 16, 2011

Calculate Total External Storage memory

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;

Here megAvailable display total External Storage Memory

Calculate Available External Storage memory

StatFs stat = new StatFs(Environment.getExternalStorageDirectory().getPath());
long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();;
long megAvailable = bytesAvailable / 1048576;

Here megAvailable display available External Storage Meomry

Calculate Total Internal Storage memory

StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getBlockSize() *(long)stat.getBlockCount();
long megAvailable = bytesAvailable / 1048576;

Here megAvailable display total Internal Storage Memory

Calculate Available Internal Storage memory

StatFs stat = new StatFs(Environment.getDataDirectory().getPath());
long bytesAvailable = (long)stat.getFreeBlocks() * (long)stat.getBlockSize();;
long megAvailable = bytesAvailable / 1048576;

Here megAvailable display available Internal Storage Memory

Load Image From Url

Below function load image from web url and return drawable.

public static Drawable LoadImageFromWebOperations(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}
catch (Exception e)
{
return null;
}
}

Tuesday, November 9, 2010

Check Internet Connection

import YourPackageName

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.ProgressDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.os.AsyncTask;
import android.widget.Toast;

class CheckInternetConnection
{
public Context context = null;
public ProgressDialog dialogProcess = null;

public CheckInternetConnection(Context ctx)
{
this.context = ctx;
}

@SuppressWarnings("unchecked")
public boolean CheckInternet()
{
ConnectivityManager connec = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo wifi = connec
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
android.net.NetworkInfo mobile = connec.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

if (wifi.isConnected())
{
return true;
}
else if (!mobile.isConnected())
{
Toast.makeText(context,"No Internet Connection",5000).show();
return false;
}
else
{
new AsyncCheckInternet().execute();
}

return false;
}

private class AsyncCheckInternet extends AsyncTask
{
@Override
protected void onPreExecute()
{
dialogProcess = ProgressDialog.show(context, "","Checking Internet Connection...",true);
}

@Override
protected Boolean doInBackground(Object... arg0)
{
try
{
URL url = new URL("http://www.google.com");
HttpURLConnection urlc = (HttpURLConnection) url
.openConnection();
urlc.setRequestProperty("User-Agent", "Test");
urlc.setRequestProperty("Connection", "close");
urlc.setConnectTimeout(3000); // This is time limit if the connection time limit
urlc.connect();
if (urlc.getResponseCode() == 200)
{
return true;
}
}
catch (MalformedURLException e1)
{
e1.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return false;
}

@Override
protected void onPostExecute(Object result)
{
super.onPostExecute(result);
dialogProcess.dismiss();
}

}
}

Sunday, September 19, 2010

Custom Listview with Image

public static ArrayList vidID = new ArrayList();
public static Hashtable> VideoTable = new Hashtable>();
Hashtable _tempVideo = new Hashtable();
ArrayList db_id;

--Start any required Loop

_tempVideo.put("id", curValue);
_tempVideo.put("title", curValue);
_tempVideo.put("filename", curValue);
_tempVideo.put("thumbnail", curValue);

VideoTable.put(curVidId, _tempVideo);
vidID.add(curVidId);

_tempVideo = new Hashtable();

---End Loop

private void fillData() {

ListView list = (ListView) findViewById(R.id.ListView01);

ArrayList> mylist = new ArrayList>();
HashMap map;

db_id = new ArrayList();
for (int i = 0; i < vidID.size(); i++) {
Hashtable temp = VideoTable
.get(vidID.get(i));
try {
map = new HashMap();
map.put("id", temp.get("id"));
map.put("title", temp.get("title"));
map.put("description", temp.get("description"));
map.put("theartist", temp.get("theartist"));
map.put("duration", temp.get("duration"));
map.put("views", temp.get("views") + " views");
map.put("server", temp.get("server"));
map.put("filename", temp.get("filename"));
map.put("thumbnail", temp.get("thumbnail"));

mylist.add(map);
db_id.add(vidID.get(i));
} catch (Exception e) {
}
}
SimpleAdapter videolist = new SimpleAdapter(this, mylist,
R.layout.videorow, new String[] { "id", "title", "views",
"duration", "description", "server", "filename",
"thumbnail"}, new int[] { R.id.TextView05,
R.id.TextView01, R.id.TextView02, R.id.TextView03,
R.id.TextView04, R.id.TextView06, R.id.TextView07,
R.id.TextView08 });
list.setAdapter(videolist);
list.setOnItemClickListener(this);
list.setTextFilterEnabled(true);
list.setOnHierarchyChangeListener(this);
}

@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {

TextView filename = (TextView) arg1.findViewById(R.id.TextView07);
String url = filename.getText().toString();
Log.e(".", url);
Bundle bundle = new Bundle();
bundle.putString("URL", url);
Intent myIntent = new Intent();
myIntent.setClassName("Package Name", "Package Name With Class");
myIntent.putExtras(bundle);
startActivity(myIntent);
}


@Override
public void onChildViewAdded(View parent, View child) {
View row = child;
try {
ImageView imView = (ImageView) row.findViewById(R.id.ImageView01);
imView.setImageBitmap(null);
TextView id = (TextView) row.findViewById(R.id.TextView05);
TextView thumbnail = (TextView) row.findViewById(R.id.TextView08);
TextView filename = (TextView) row.findViewById(R.id.TextView07);
imView.setTag(filename.getText().toString());
String imgurl = thumbnail.getText().toString();
grabURL(imgurl, imView, filename.getText().toString());

ImageView addFav = (ImageView) row.findViewById(R.id.ImageView02);
addFav.setTag(id.getText().toString());
addFav.setOnClickListener(myListner);
} catch (Exception e) {
}
}
@Override
public void onChildViewRemoved(View parent, View child) {

try {
View row = child;
ImageView imView = (ImageView) row.findViewById(R.id.ImageView02);
imView.setTag(null);
imView.setImageBitmap(null);
} catch (Exception e) {
}
}


public void grabURL(String url, ImageView iv, String name) {
GrabURL a = new GrabURL();
a.imgView1 = iv;
a.name = name;
a.execute(url);
}

private class GrabURL extends AsyncTask {
ImageView imgView1;
String name;

protected void onPreExecute() {
}

protected Bitmap doInBackground(String... urls) {
URL myFileUrl = null;
Bitmap bmImg = null;
try {
myFileUrl = new URL(urls[0]);
} catch (MalformedURLException e) {
}

try {
HttpURLConnection conn = (HttpURLConnection) myFileUrl
.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);

} catch (Exception e) {
Log.e(".", e.getMessage());
}
return bmImg;
}

protected void onPostExecute(Bitmap bm) {
if (name == imgView1.getTag().toString())
imgView1.setImageBitmap(bm);
}

}

Sunday, July 4, 2010

Remove app from Emulator

First,make sure the emulator is running.Then follow below steps:

1. go to tools directory in command

2. adb shell

3. cd /data/app

4. ls (It will display all the .apk installed in your emulator)

5. rm ***.apk(which you want to remove)

6. exit

Installtion on Window

1) To Install the Android on Your Window Machine
you need the following .....

A) JDK (5.0 or 6.0) Link -

B) Eclipse 3.5 Link - http://www.eclipse.org/downloads/
(Download the First One Which has 190 MB)

C) Android SDK - http://developer.android.com/sdk/index.html

2) Install the JDk

3) Extract the Eclipse

4) Unzip Android SDK at any location you want...

5) On Windows, right-click on My Computer, and select Properties.
Under the Advanced tab, hit the Environment Variables button,
and in the dialog that comes up, double-click on Path (under System
Variables).

Add the full path to the tools/ directory to the path.

6) Now Open Eclipse Go To Help->Install New Software->Add
Click on the add button that will open a new dialog box

Name : ADT Plugins
URL : https://dl-ssl.google.com/android/eclipse/

7) Back in the Available Software view, you should now see
"Developer Tools" added to the list. Select the checkbox
next to Developer Tools, which will automatically select the
nested tools Android DDMS and Android Development Tools.
Click Next.

8) In the resulting Install Details dialog, the Android DDMS
and Android Development Tools features are listed.
Click Next to read and accept the license agreement and
install any dependencies, then click Finish.

9) Restart the Eclipse.

10) Once you've successfully downnloaded ADT as described above,
the next step is to modify your ADT preferences in
Eclipse to point to the Android SDK directory:

1. Select Window > Preferences... to open the Preferences panel (Mac

OS X: Eclipse > Preferences).
2. Select Android from the left panel.
3. For the SDK Location in the main panel, click Browse... and

locate your downloaded SDK directory.
4. Click Apply, then OK.

11) Now Go Where You extract the android SDk....
Click on SDK Set Up

12) That will open a dialog box of Android SDK and AVD Manager

13) Go to Available Packages Click on the Check box
which is located in your right...

14) It Will Show u List of Api....

15) Then please tick on Your SDK Platform Android ( Your Version ) API

16) After selecting API Please Click on Install Selected Button
Which is located right bottom

17) After Installing Your Api go to Virtual Device listed in left ..

18) Click on New Button ...

19) GIve ANy Name ... And Select Your Target API....
Rest of Informatio is Optional...then click on Create AVD

20) Now Open the Eclipse and Enjoy the Android....

Installation on Linux

1) To Install the Android on Your Linux Machine
you need the following .....

A) JDK (5.0 or 6.0)

B) Eclipse 3.5 Link - http://www.eclipse.org/downloads/
(Download the First One Which has 190 MB)

C) Android SDK - http://developer.android.com/sdk/index.html

2) Install the JDk

3) Extract the Eclipse

4) Unzip Android SDK at any location you want...
(Recomended - /home/usr)

5) On Linux, edit your ~/.bash_profile or ~/.bashrc file.
Look for a line that sets the PATH environment variable and add
the full path to the tools/ directory to it. If you don't see a line
setting the path, you can add one:

export PATH=${PATH}:/tools

6) Now Open Eclipse Go To Help->Install New Software->Add
Click on the add button that will open a new dialog box

Name : ADT Plugins
URL : https://dl-ssl.google.com/android/eclipse/

7) Back in the Available Software view, you should now see
"Developer Tools" added to the list. Select the checkbox
next to Developer Tools, which will automatically select the
nested tools Android DDMS and Android Development Tools.
Click Next.

8) In the resulting Install Details dialog, the Android DDMS
and Android Development Tools features are listed.
Click Next to read and accept the license agreement and
install any dependencies, then click Finish.

9) Restart the Eclipse.

10) Once you've successfully downnloaded ADT as described above,
the next step is to modify your ADT preferences in
Eclipse to point to the Android SDK directory:

1. Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse >
Preferences).
2. Select Android from the left panel.
3. For the SDK Location in the main panel, click Browse... and
locate your downloaded SDK directory.
4. Click Apply, then OK.

11) Now Go Where You extract the android SDk....
tools->android (Click on It)

12) That will open a dialog box of Android SDK and AVD Manager

13) Go to Available Packages Click on the Check box
which is located in your right...

14) It Will Show u List of Api....

15) Then please tick on Your SDK Platform Android ( Your Version ) API

16) After selecting API Please Click on Install Selected Button
Which is located right bottom

17) After Installing Your Api go to Virtual Device listed in left ..

18) Click on New Button ...

19) GIve ANy Name ... And Select Your Target API....
Rest of Informatio is Optional...then click on Create AVD

20) Now Open the Eclipse and Enjoy the Android....