Get free daily email updates!

Follow us!

Monday, January 20, 2014

bluetoothadapter.getdefaultadapter returns null in android. Why? How to solve it in android

I found many query regarding Bluetoothadepter return null values, “Devise not supported on higher android version”, “Emulator don’t turn on Bluetooth using Bluetooth adapter”, “Why emulator not support Bluetooth”.

But the entire above question has a single answer.

Your installed emulator must not any Bluetooth device. So BluetoothAdapter simply check your device supporting and have a Bluetooth device.

So try it your own android mobile through install android APK file in your mobile.

Useful: How to create and install apk file from your project?

bluetoothadapter.getdefaultadapter returns null > Run in actual android device which has Bluetooth device

To know more about BluetoothAdapter please reader android developer site here

Here is the sample test code and Example for you

Read more ...

Bluetooth Sample Code For Bluetooth Turn On Or Off In Android - How To Enable Bluetooth

Bluetooth in android is basic level to learn android. In any application you can use Bluetooth for sharing purpose like file sharing, Apps sharing, Audio and video file also. In some of application you have to turn on Bluetooth in between application access process.

At that time you can turn on Bluetooth in a minute by this example.

Useful: How to create and install apk file from your project?

Download Bluetooth Code for android from here:

Create new sample Bluetooth project

1. Create a new project under the File > New > Android Project

2. Open string.xml file under the resource (res) > values folder and past the below code.

    Hello world!
    My Message
    Enter Message

3. Open Mail xml file activity_main.xml file under the resource (res) > layout folder and past the below code.



4. Open Manifest file under your project. Past the Bluetooth permission line to allow Bluetooth in your device.


5. Now open file and past below code.

package com.example.bluetoothsample;

import android.os.Bundle;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {

 private static final int Request_Enabled = 0;
 private static final int Request_Discoverable = 0;
 protected void onCreate(Bundle savedInstanceState) {
  final BluetoothAdapter BTA = BluetoothAdapter.getDefaultAdapter();
//  it through getSystemService(String) with BLUETOOTH_SERVICE
  if(BTA == null)
   final TextView tv1 = (TextView)findViewById(;
   tv1.append("device not supported");
  final Button Btn1 = (Button)findViewById(;
  Btn1.setOnClickListener(new View.OnClickListener() {
   public void onClick(View arg0) {
     Intent EnableBintent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
     startActivityForResult(EnableBintent, Request_Enabled);
  final Button Btn2 = (Button)findViewById(;
  Btn2.setOnClickListener(new OnClickListener() {
   public void onClick(View arg0) {
     Toast.makeText(getApplicationContext(), "Making Your Device Discoverable", Toast.LENGTH_LONG).show();
     Intent EnableBintent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
     startActivityForResult(EnableBintent, Request_Discoverable);
  final Button btn3 = (Button)findViewById(;
  btn3.setOnClickListener(new OnClickListener() {
   public void onClick(View arg0) {
    Toast.makeText(getApplicationContext(), "Bluetooth is closed", Toast.LENGTH_LONG).show();;

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


Note: during this running Bluetooth project in emulator doesn’t work because Bluetooth adepter cant find Bluetooth device. So it’s return null. But you can check in your device directly it must work after install apk file in your mobile.

For more about: Bluetooth adapter return null.

If you have any problem and query then comment in below comment box.

Read more ...

How To Create APK File From Project (Eclipse) For Android Mobile Or Device – Get APK File From Eclipse Project

Create or get APK file from your android project development in eclipse is the first level to test your project for in mobile use. many of the developer have many confusion to get APK file of the current project. But it is so simple you can get APK file for your particular project or android application in a minute.

Note: You don’t have to create APK file at any time. It will be automatically generate under the bin folder in your workspace.

Step by Step guide to create or get APK file from your android project

Step 1,
Go current workspace on your hard drive

Android Work space
Android Work space

Step 2,
Go in your project > bin
Android Work space create APK file
Android Work space create APK file
Step 3,
You will found same name project name with .APK file. Ex, You can see apk file with name bluetoothsample.apk file.
Android Work space get APK file
Android Work space get APK file

Connect your mobile to computer. Just copy that file and past in your mobile. Disconnect mobile from PC. Prepared your SD card. Find the APK file in your mobile. Hit the double click.

Best of luck,
Any problem and suggestion, than comment in below box.

Read more ...

Wednesday, January 8, 2014

How To Add Or Import Image In Drawable Under Resource Folder In Android Eclipse

Drawable folder located under the resource folder of android project. I am explaining how to import new images from your computer hard drive as a external storage. Right click on that folder doesn’t give direct option to import image into this folder. After importing image, copy of that image automatically saved in your workspace where your android app project saved.

Steps to import images in res/drawable

Before you import images in Drawable folder you have to know about drawable-ldpi(low density), drawable-hdpi(high density), drawable-mdpi(medium density), drawable-xhdpi(extra high density), and drawable-xxhdpi.
add or import image in Drawable - android example
add or import image in Drawable - android example
add or import image in Drawable - android example
add or import image in Drawable - android example

add or import image in Drawable - android example
add or import image in Drawable - android example

add or import image in Drawable - android example
add or import image in Drawable - android example

This different folder works for to store images and display images on different size resolution through the scaling and resizing. Through this you can install same apk file on different device at the same time.
Next article helps to understand How to use different layout image folder and why we need?

Read more ...

How To Call Image ID From Drawable Folder Using Code Behind In Android

In Some situation we need to set image code behind, that time you fetch image id without XML file in you code behind. You can set it through the resource and drawable property. See in below examples

You can call this image in your application project’s XML file using XML attributes like: android:drawable and android:icon.

Android always use and support bitmap image file. So whenever you insert image in another format like .png, .jpg, .gif.

.png = preferred
.jpg = acceptable
.gif = discouraged

You can call drawable image id using code behind through the below property and syntax
// image name >> facebook_icon
Resources res = getResources();
Drawable dr = res.getDrawable(R.drawable.facebook_icon);
See below image,

Call Drawable image ID using Code behind in android
Call Drawable image ID using Code behind in android
By the calling Image id you can set image style like “image behind textbox”, “Beckground image”.
Code for Image behind textbox
Resources res = getResources();
Drawable shape = res. getDrawable(R.drawable.gradient_box);

TextView tv = (TextView)findViewByID(;
If you want to make different layout XML file under res folder for different screen size, read this article must useful

Read more ...

All Full Name And Forms In Android – Most Used Sort Cut Name In Android

Most of the android developer always forgot full form (APK, DDMS, JDK, AVD, SVN) and meaning of most useful Shortcuts code which is displayed in below. All are the shortcuts might be helpful in future for as interview question, and easy to understand functionality of any file and process.

Note all the Short names in your mind first and also note in your directory.

APK – Application Package file
DDMS – Dalvik Debug Monitor Service
API - Application Programming Interface
SDK – Software Development Kit
JDK – Java Development Toolkit
XML – Extensible markup language
AVD – Android Virtual Device
SVN – Subversion

I hope you will gain some new full name from this article if you want to know so share this article on Facebook, twitter and Google+.

Some of the short name like APK, DDMS, JDK, AVD you must know as technical person in collage and industry life. So don’t forget and remember.

Read more ...
function foo()