My JAVA code:-----

package com.app.DetactUSB;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;
import android.widget.Toast;

public class DetactUSB extends BroadcastReceiver
{ 
    private static final 
String<http://www.google.com/search?hl=en&q=allinurl%3Astring+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 TAG = "DetactUSB";
    @Override
    public void 
onReceive(Context<http://www.google.com/search?hl=en&q=allinurl%3Acontext+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
 context, 
Intent intent) {
        // TODO Auto-generated method stub
        if (intent.getAction().equalsIgnoreCase(
"android.intent.action.UMS_CONNECTED"))
        {
                TextView textView = new TextView(context);
                
textView.setBackgroundColor(Color<http://www.google.com/search?hl=en&q=allinurl%3Acolor+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
.MAGENTA);
                
textView.setTextColor(Color<http://www.google.com/search?hl=en&q=allinurl%3Acolor+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
.BLUE);
                textView.setPadding(10,10,10,10);
                textView.setText("USB connected……….");
                Toast toastView = new Toast(context);
                toastView.setDuration(Toast.LENGTH_LONG);
                toastView.setGravity(Gravity.CENTER, 0,0);
                toastView.setView(textView);
                toastView.show();
                Log.i(TAG,"USB connected..");
        }

        if (intent.getAction().equalsIgnoreCase(
"android.intent.action.UMS_DISCONNECTED"))
        {
                TextView textView = new TextView(context);
                
textView.setBackgroundColor(Color<http://www.google.com/search?hl=en&q=allinurl%3Acolor+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
.MAGENTA);
                
textView.setTextColor(Color<http://www.google.com/search?hl=en&q=allinurl%3Acolor+java.sun.com&btnI=I%27m%20Feeling%20Lucky>
.BLUE);
                textView.setPadding(10,10,10,10);
                textView.setText("USB Disconnected……….");
                Toast toastView = new Toast(context);
                toastView.setDuration(Toast.LENGTH_LONG);
                toastView.setGravity(Gravity.CENTER, 0,0);
                toastView.setView(textView);
                toastView.show();
        }
    } 
}






My Menifest File:------





<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
     package="com.app.DetactUSB"
     android:versionCode="1"
     android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.INTERNET">
    </uses-permission>
    <uses-permission android:name="android.permission.RECORD_AUDIO">
    </uses-permission>
    <application android:icon="@drawable/icon" android:label=
"@string/app_name">
       <activity android:name=".MyActivity" android:label="@string/app_name"
>
                <intent-filter>
                     <action android:name="android.intent.action.MAIN" />
                     <category android:name=
"android.intent.category.LAUNCHER" />
                </intent-filter>
        </activity>
    <receiver android:name=".DetactUSB">
       <intent-filter>
            <action android:name="android.intent.action.UMS_CONNECTED" />
            <action android:name="android.intent.action.UMS_DISCONNECTED" />
       </intent-filter>
    </receiver>
    </application>
</manifest>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to