Learn Android for Free,issues for developers, mobengineers website provide complete solutions for developers issues posts.It also provides online training for android development

Tuesday, January 29, 2013

Bluetooth -Android Programming

  Android supports Bluetooth for wireless connectivity. It comes with API of android bluetooth.

We have different classes in the API

BluetoothAdapter: It represents local Bluetooth Adapter.Using this class, we can discover the devices near by.Uisng this we can create BluetoothServerSocket for listening from other devices.

 BluetoothDevice: By using this we can request connection to remote device through BluetoothSocket.

BluetoothSocket: We can exchange the data with other Bluetooth Device.

BluetoothServerSocket: it listens the incoming request. To connect any device, one device  must open a server socket.

BluetoothProfile:It is an interface for wireless devices.

Bluetooth: Using this class, we can connect to Bluetooth Headset.

BluetoothHealth: It represents a health device profile that controls Bluetooth service.
BluetoothA2dp(Advanced Audio Distribution Profile): It tells how audio quality streamed from one mobile to other .

BluetoothProfile.ServiceListener: It gives notification when the client connects or disconnects.

To use Bluetooth in Android, we need to declare permissions in manifest.xml

 <uses-permission android:name="android.permission.BLUETOOTH" />
 <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

How to check whether the device support Bluetooth or not?

BluetoothAdapter btAdapter=BluetoothAdapter.getDefaultAdapter();
if( btAdapter==null){
//device doesnot support Bluetooth.
else{ //device support bluetooth.

How to enable Bluetooth:
 //Prompt user to turn on Bluetooth
Intent enableI = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
    startActivityForResult(enableI, REQUEST_ENABLE_BT);

        // Set up a pointer to  remote node using address.
        BluetoothDevice device = btAdapter.getRemoteDevice(address);

/ Establish connection. 

Monday, January 28, 2013

What is Bluetooth?

        Bluetooth is a wireless technology for connecting shortest distance clients(creates personnel area network) within the range of 10 meters with the frequency of 2.4 GHZ of unlicensed band. To connect to the other client, the client also have Bluetooth. It is the greatest technology for replacing the cables for short distances.
     If we compare to the other systems, Bluetooth file transfer is faster packet transfer. It uses fastest acknowledgement, frequency hopping and unlicensed ISM band.

  At Present, most of the electronic goods coming with Bluetooth technology like Tv, mouse, audio devices, mobiles, remotes, computers etc.

cost of the Bluetooth device is cheaper than any other wireless technology.

How to use the Bluetooth and how to connect to other Bluetooth device programatically we can see in later topics.


Tuesday, January 22, 2013

Fragments- ActionBar android

public class StartActivity extends Activity {
    public static Context appContext;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        appContext = getApplicationContext();

          ActionBar actionbar = getActionBar();
        ActionBar.Tab PlayerTab = actionbar.newTab().setText("SONGS");
        ActionBar.Tab StationsTab = actionbar.newTab().setText("VIDEOS");

       ActionBar.Tab PhotosTab = actionbar.newTab().setText("PHOTOS");       
        Fragment sFragment = new SongsFragment();
        Fragment vFragment = new VideosFragment();

        sTab.setTabListener(new MyTabsListener(sFragment));
        vTab.setTabListener(new MyTabsListener(vFragment));





public class SongsFragment extends Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.songsfragment, container, false);

public class VideosFragment extends Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.videosfragment, container, false);


public class PhotosFragment extends Fragment {
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.photosfragment, container, false);


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_gravity="center">
        android:layout_height="match_parent" >


Creating Bitmap

To Create Bitmap 
Bitmap bmp = Bitmap.createBitmap((int)
getWindowManager().getDefaultDisplay().getWidth(), (int)
getWindowManager().getDefaultDisplay().getHeight(), Bitmap.Config.ARGB_8888);

To create Bitmap from resources

Bitmap image=BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher); 

Bitmap Configurations:
ALPHA_8  : 8 bits on Alpha channel, and no other colours.
ARGB_4444: 4 bits per color channel includes alpha,

ARGB_8888: 8 bits per color channel includes alpha,
RGB_565  : 5 bits for Red,6 bits for Green,5 bits for Blue 

TabHost- Tabs Android


In android, Using tabs, we can open multiple activities within single screen.
Three ways to create Tabs.

1. extends class from TabActivity or ActivityGroup

2. extending Activity and  use LocalActivityManager

3. using fragments ( Api 11 required).

Here is the sample working code for Tabs

package com.srinivas.tabs;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.app.Activity;
import android.app.LocalActivityManager;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.widget.TabHost;

public class MainActivity extends Activity {
    private static TabHost tabHost;
    protected void onCreate(Bundle savedInstanceState) {
        tabHost = (TabHost) findViewById(R.id.tabhost);
        LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
        Resources res = getResources();
        TabHost.TabSpec spec;

        Intent songintent = new Intent().setClass(this, SongsActivity.class);

        spec = tabHost.newTabSpec("songs")
                .setIndicator("Songs", res.getDrawable(R.drawable.ic_launcher))

        Intent videointent = new Intent().setClass(this, VideosActivity.class);
        spec = tabHost
                .setIndicator("Videos", res.getDrawable(R.drawable.ic_launcher))

        Intent booksintent = new Intent().setClass(this, BooksActivity.class);
        spec = tabHost.newTabSpec("books")
                .setIndicator("Books", res.getDrawable(R.drawable.ic_launcher))



<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

if you want to place Tabs at top , remove    android:layout_alignParentBottom="true"


Thursday, January 10, 2013

What is Android ?

What is android

         Android is a software stack comprising not only OS but also middleware and key applications. It is an open source operating system, means developers customize the operating system for each mobile.

      Android was released by "Android Incorporation", a small company  in 2003. In 2005, It was aquired by the Google.Google formed a group named "Open Handset Alliance" to develop open standards. In that group many companies joined like Samsung, Motorola, mobile network companies, semiconductor companies etc.

Monday, January 7, 2013

Ubuntu is going to join into Mobile os market in 2014.............

Till now android, ios os occupied the entire mobile market. Now Ubuntu (Open source) want to compitative to all other mobile os.

What is the extra features it contains?

Ubuntu for android mobile enables to Android handsets to run the Ubuntu os on it. Ubuntu is a open source software. we can install the os in any compatible devices freely. For developing applications, canonical providing free registration. Canonical is the backend company for ubuntu mobile os.

It supports most of the popular languages for developing ubuntu mobile applications. C, c+ c#,python,qml, javascript,vala by using the programming technologies , we can develop ubuntu mobile applications.

Hope we can expect the ubuntu as a future compitative mobile os among all other os.

20% off

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

NDTV Gadgets360

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts