Splash Screen Android Example Code

In this post you can learn on how to set up a splash screen in android before entering the home screen with a few seconds timeout which gives a professional rich UI design user experience.

HomeScreen Activity Java File

public class HomeScreen extends Activity {
     
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.homescreen); 
         
    } 
     
    @Override
    protected void onDestroy() {
         
        super.onDestroy();
         
    }
}


Splashscreen activity Java file

public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        
         
//Sleep for 5 seconds
        Thread background = new Thread() {
            public void run() {
                 
                try {
                    sleep(5000);
                     
                    Intent i=new Intent(getBaseContext(),HomeScreen.class);
                    startActivity(i);
                     
                    //remove the activity
                    finish();
                     
                } catch (Exception e) {
                 
                }
            }
        };
         
        // starting the thread
        background.start();
             
    }
     
    @Override
    protected void onDestroy() {
       
        super.onDestroy();
         
    }
}

Android ToggleButton Source Code Example

In this post you can learn on how to work with ToggleButton in android. Toggle button means giving two different functionalities in a single button and examples like turn loudspeaker on / off. The next example is mute/unmute the current call, etc... These are some of the examples of ToggleButton in android. And also you can change the image of the ToggleButton too in android.

Layout.xml File

<ToggleButton
        android:id="@+id/toggleButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ToggleButtonExample" >
android:textOn="On"
android:textOff="Off"
</ToggleButton>

On activity java file under onCreate make use of the below function to work with ToggleButton.

tb = (ToggleButton) findViewById(R.id.toggleButton1);
        tb.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                 if (tb.isChecked()) {

                        //corresponding code units
                    } else {

                        //corresponding code units
                    }
            }
        });

ImageButton Change Image OnClick XML

In this post you can learn on how to change the image of the ImageButton OnClick in android. This is very simple and you can use a simple XML file to make this functionality happen.

changeimage.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_focused"
          android:state_focused="true" />
    <item android:drawable="@drawable/button_normal" />

</selector>

changeimage is an xml file that we must create inside drawable folder where "button_pressed", "button_focused" and "button_normal" are images under drawable folder respectively.

layout.xml

Make a reference of the above XML file in the button declaration to make it effect.

<Button
        android:id="@+id/imagebutton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:background="@drawable/changeimage" />

Swipe Tabs Android Source Code Example

Hi All,

In this post I am going to explain all about swipe tabs in android with an awesome example. You all might have used facebook in your android phones right. In that you might have noticed a swipe tabs view layout for post page, notifications, etc... Likewise you can design your swipeable tabs in android which brings high user experience and ease to use and navigation and high technological one. Just have a glance on the source code examples below. Here in this example you can see a screen with two swipeable tabs songs and videos. Very easy to build swipe tabs in android and enjoy with the example below.

1. Android Manifest XML file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.swipetabs"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.android.swipetabs.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


</manifest>

2. Android main activity layout file xml

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


</android.support.v4.view.ViewPager>


3. Songs activity layout file xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="songs"
        android:textSize="20dp"
        android:layout_centerInParent="true"/>
    


</RelativeLayout>


4. Videos activity layout file xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="videos"
        android:textSize="20dp"
        android:layout_centerInParent="true"/>
    

</RelativeLayout>



5. MainActivity Java file

package com.android.swipetabs;

import com.android.swipetabs.adapter;

import com.android.swipetabs.R;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {

private ViewPager pager;
private adapter adapter;
private ActionBar action;
private String[] tabs = { "songs", "videos" };

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

pager = (ViewPager) findViewById(R.id.pager);
action = getActionBar();
adapter = new adapter(getSupportFragmentManager());

pager.setAdapter(adapter);
action.setHomeButtonEnabled(false);
action.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

for (String tab_name : tabs) {
action.addTab(action.newTab().setText(tab_name)
.setTabListener(this));
}
//on swipe tabs functionality
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

@Override
public void onPageSelected(int position) {

action.setSelectedNavigationItem(position);
}

@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}

@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// on tab selected
// show respected fragment view
pager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}

}



6. Adapter java file

package com.android.swipetabs;


import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class adapter extends FragmentPagerAdapter {

public adapter(FragmentManager fgmt) {
super(fgmt);
// TODO Auto-generated constructor stub
}


@Override
public Fragment getItem(int index) {

switch (index) {
case 0:
// Games fragment activity
return new songs();
case 1:
// Movies fragment activity
return new videos();
}

return null;
}

@Override
public int getCount() {
// get item count - equal to number of tabs
return 2;
}

}




7. songs java file

package com.android.swipetabs;

import com.android.swipetabs.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class songs extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.songs, container, false);
return rootView;
}
}


8. Videos java file

package com.android.swipetabs;

import com.android.swipetabs.R;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class videos extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.videos, container, false);
return rootView;
}

}

FlashLight Android Source Code Example

Guys, welcome you all here. Here you can find the source code example of flashlight in android. Code units are below and its very simple to design it. Just learn it and try to implement your own awesome flashlight application and launch it in the google play with adding innovations in it. By developing an awesome fantabulous flashlight of paid version you can become a millionaire soon with the high amount of downloads that you get.

1. Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myflashever.android"
    android:versionCode="1"
    android:versionName="2.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name="com.myflashever.android.flashlight"
            android:screenOrientation="portrait" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

2. Layout file - main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ToggleButton
        android:id="@+id/flashlight"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:textOn="Turn On"
        android:textOff="Turn Off"
        android:background="@drawable/change" />


</RelativeLayout>


2.1 @drawable/change
change.xml - for changing the ToggleButton image on click.


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/ooo"
          android:state_checked="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/lll"
        android:state_checked="false"/>
 </selector>


3. flashlight.java file

package com.myflashever.android;

import com.myflashever.android.R;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;

public class flashlight extends Activity {

private boolean isLightOn = false;

private Camera cam;

private ToggleButton button;

@Override
protected void onStop() {
super.onStop();

if (cam != null) {
cam.release();
}
}

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

button = (ToggleButton) findViewById(R.id.flashlight);

Context context = this;
PackageManager pm = context.getPackageManager();

if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
return;
}

cam = Camera.open();
final Parameters p = cam.getParameters();

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

if (isLightOn) {

p.setFlashMode(Parameters.FLASH_MODE_OFF);
cam.setParameters(p);
cam.stopPreview();
isLightOn = false;

} else {

p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
isLightOn = true;

}

}
});

}

}



Incredible FlashLight

Please find below a sample innovative free flashlight app in the market.
https://play.google.com/store/apps/details?id=com.myflashever.android&hl=en

My android apps in the Market

Incredible Bible

After learning android programming and writing blogs on the same, I got some good experience in the development and now I developed my first android application very simple and great and have launched it in the google play market and I released it as a paid version -Incredible Bible -(https://play.google.com/store/apps/details?id=com.udhaya.android).

Guys, It is great to learn android programming and its very great to make money with tech, non tech, games, books, etc... and al stuff from the android market. Praise the Lord.

Incredible Bible - My First Android App in the Market - https://play.google.com/store/apps/details?id=com.udhaya.android. Kindly download and make prayers to the Lord instantly and accordingly. God bless you.

Android Multiple Tab Layout Example

In this post, you can learn android source code example on tabs in android and about designing multiple tab layout in android. This functionality is mainly used in many android professional application development and you can have a clear observation and description on how to design it with the below example.

1. Create TabLayout_Activity.java file.

TabLayout_Activity.java

package com.asce;

import com.asce.R;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")
public class TabLayout_Activity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        TabHost tabHost = getTabHost();
        
        // Tab for Tab A
        TabSpec a = tabHost.newTabSpec("Tab A");
        // Title and Icon for Tab
        a.setIndicator("Tab A", getResources().getDrawable(R.drawable.tab_a));
        Intent a_Intent = new Intent(this, A_Activity.class);
        a.setContent(a_Intent);
        
        // Tab for Tab B
        TabSpec b = tabHost.newTabSpec("Tab B");
        b.setIndicator("Tab B", getResources().getDrawable(R.drawable.tab_b));
        Intent b_Intent = new Intent(this, B_Activity.class);
        b.setContent(b_Intent);
        
        // Adding all TabSpec to TabHost
        tabHost.addTab(a); // Adding Tab A tab
        tabHost.addTab(b); // Adding Tab B tab
    }

}

2. Create A_Activity.java

A_Activity.java

package com.asce;

import com.asce.R;

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

public class A_Activity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a_layout);
    }

}

3. Create A_Activity.java

B_Activity.java

package com.asce;

import com.asce.R;

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

public class B_Activity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.b_layout);    }

}

4. Create tab_a.xml in res - drawable folder

tab_a.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/tab_a_grey"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/tab_a_white" />

</selector>

tab_a_grey & tab_b_grey are images in drawable folder

Similarly create for tab_b.xml

5. Create a_layout.xml in layout folder

a_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  
  <!-- Screen Design for Tab A -->
  <TextView android:text="Contents of Tab A here"
  android:padding="15dip"
  android:textSize="18dip"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
    

</LinearLayout>

Similarly create for b_layout.xml.

6. Now your main.xml.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>
</TabHost>

7. Your AndroidManifest.xml

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

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name="com.asce.TabLayout_Activity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <!--  Tab A Activity -->
        <activity android:name="com.asce.A_Activity" />
        
        <!--  Tab B Activity -->
        <activity android:name="com.asce.B_Activity" />
      
    </application>
</manifest>

Play Online Video in Android Device

In this post you can learn android source code example on how to play a video from a URL online from an android device. The basic functionality part is given below. This can be used in android application development for live video streaming from a URL. Using this concept you can develop android apps for online TV viewer application and online video live streaming from a valid URL containing the video.

1. Create a android project and make use of this main.xml file below.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <VideoView
            android:id="@+id/video"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center" />

        <ProgressBar
            android:id="@+id/progress"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_gravity="center" />
    </FrameLayout>

</LinearLayout>

2. Now construct your main activity file and make use of the below code.

MainActivity.java

public class MainActivity extends Activity {
      public static String url = "url_of_the_video_that_you_want_to_play";
      private VideoView videoView = null;
      private ProgressBar progress = null;
      private Context ctx = null;
      private MediaController mediaController = null;

     @Override
     public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                requestWindowFeature(Window.FEATURE_NO_TITLE);
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
                getWindow().setFormat(PixelFormat.TRANSLUCENT);
                setContentView(R.layout.main);
                ctx = this;
                progress = (ProgressBar) findViewById(R.id.progress);
                videoView = (VideoView) findViewById(R.id.video);
                Uri video = Uri.parse(url);
                mediaController = new MediaController(this);
                mediaController.setAnchorView(videoView);
                videoView.setMediaController(mediaController);
                videoView.setVideoURI(video);

                videoView.setOnErrorListener(new OnErrorListener() {

                               @Override
                               public boolean onError(MediaPlayer mp, int what, int extra) {
                                        // TODO Auto-generated method stub
                                        Toast.makeText(ctx, "Error occured", 500).show();
                                        return false;
                               }
                });

                videoView.setOnPreparedListener(new OnPreparedListener() {

                               public void onPrepared(MediaPlayer arg0) {
                                          progress.setVisibility(View.GONE);
                                          videoView.start();
                               }
               });
     }

     @Override
     protected void onDestroy() {
           try {
                   videoView.stopPlayback();
           } catch (Exception e) {
                   //
           }
           super.onDestroy();
     }
}

3. Add USES permission (Internet Permission) to your android manifest xml file without fail for internet access.

AndroidManifest.xml

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

Note : The video does not play in your android emulator. Just compile your code units perfectly and install the .apk file into your android device and start watching the video from the URL which you have embedded.

Read PDF files in Android Source Code

Dear all, In this post you can learn on how to read PDF files in android. Let us consider the below example that the PDF file is located in the SD card of your android phone. The below android source code example is illustrated on how to read this PDF file.

1. Create a Android Project. Download "PDFViewer.jar" and add it in the project build path. You can download the "PDFViewer.jar" from the below link.
https://github.com/jblough/Android-Pdf-Viewer-Library

2. Create an activity java file as below.

activity_second.java

public class activity_second extends PdfViewerActivity {
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
     // TODO Auto-generated method stub
     super.onCreate(savedInstanceState);
    }
   
    public int getPreviousPageImageResource() {
     return R.drawable.left_arrow;
    }
   
    public int getNextPageImageResource() {
     return R.drawable.right_arrow;
    }
   
    public int getZoomInImageResource() {
     return R.drawable.zoom_in;
    }
   
    public int getZoomOutImageResource() {
     return R.drawable.zoom_out;
    }
   
    public int getPdfPasswordLayoutResource() {
     return R.layout.pdf_file_password;
    }
   
    public int getPdfPageNumberResource() {
     return R.layout.dialog_pagenumber;
    }
   
    public int getPdfPasswordEditField() {
     return R.id.etPassword;
    }
   
    public int getPdfPasswordOkButton() {
     return R.id.btOK;
    }
   
    public int getPdfPasswordExitButton() {
     return R.id.btExit;
    }
   
    public int getPdfPageNumberEditField() {
     return R.id.pagenum_edit;
    }
}

3. Now add the below class into your project's main activity and extend this class to ListActivity.

activity_first.java

public class activity_first extends ListActivity {
     
    String[] pdflist;
    File[] imagelist;
    @Override
    public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     //setContentView(R.layout.main);
   
     File images = Environment.getExternalStorageDirectory();
     imagelist = images.listFiles(new FilenameFilter() {
      public boolean accept(File dir, String name) {
       return ((name.endsWith(".pdf")));
      }
     });
     pdflist = new String[imagelist.length];
     for (int i = 0; i < imagelist.length; i++) {
      pdflist[i] = imagelist[i].getName();
     }
     this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, pdflist));
    }
   
    protected void onListItemClick(ListView l, View v, int position, long id) {
     super.onListItemClick(l, v, position, id);
     String path = imagelist[(int) id].getAbsolutePath();
     openPdfIntent(path);
    }
   
    private void openPdfIntent(String path) {
     try {
      final Intent intent = new Intent(activity_first.this, Second.class);
      intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, path);
      startActivity(intent);
     } catch (Exception e) {
      e.printStackTrace();
     }
    }
}

4. Add your Second Activity too in your Android Manifest.xml file without fail.

Check Internet Connection in Android Source Code

You can check the availability of internet connection in android device by using the following source code example. While building android web applications it is necessary to check whether the device has internet connection available or not. This concept is very important and is very useful while developing android applications for validation purposes.

Android Source Code Example to Check Internet Connectivity

1. The below main activity returns the boolean value as true if there is internet connection in the device and if it returns false then there is no internet access in the android device.

public class isNetworkAvailable {

//return boolean as true if there is internet access

 public static boolean isNetworkAvailable(Context context) {
     ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     if (connectivity != null) {
        NetworkInfo[] info = connectivity.getAllNetworkInfo();
        if (info != null) {
           for (int i = 0; i < info.length; i++) {
              if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                 return true;
              }
           }
        }
     }
     return false;
  }
}

2. Please add the USES permission (Internet / Wifi) in the android manifest file.

LED Notification Android Source Code Example

This is a simple android project where you can see LED notification with different colors in the android mobile screen. Please find below the source code example. No special permissions are required for this project. Just you can run with default manifest and layout. Before seeing the demo through android IDE, just lock your phone screen to see the LED illumination.

NotificationLED.java

public class NotificationLED extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

  NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

  for (int i = 0; i < 8; i++) {
   notif.cancel(1); // clear all previous notification 
   final Notification notification = new Notification();
   if (i == 0){
    notification.ledARGB = Color.MAGENTA;
   }else if (i == 1){
    notification.ledARGB = Color.BLUE;
   }else if (i == 2){
    notification.ledARGB = Color.CYAN;
   }else if (i == 3){
    notification.ledARGB = Color.GRAY;
   }else if (i == 4){
    notification.ledARGB = Color.GREEN;
   }else if (i == 5){
    notification.ledARGB = Color.RED;
   }else if (i == 6){
    notification.ledARGB = Color.WHITE;
   }else if (i == 7){
    notification.ledARGB = Color.YELLOW;
   }
   notification.ledOnMS = 1000;
   notification.flags |= Notification.FLAG_SHOW_LIGHTS;
   notif.notify(1, notification);
   try {
    Thread.sleep(2000);
   } catch (InterruptedException e) {    
    e.printStackTrace();
   }
  }

 }


My Profile