hi.

I was make source to catch and process SD Card mount/unmount broadcast
received dynamically in activity.

but the USM_CONNECTED/DISCONNECTED broadcast msg is not catched
dynamically in activity like below:.

how the receiver can receive the UMS msg in activity?

below:

package com.test;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.*;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class IntentTest extends Activity {

        public static BroadcastReceiver mReceiver1 = null;

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

     // install an intent filter to receive SD card related events.
        IntentFilter intentFilter1 = new IntentFilter
(Intent.ACTION_MEDIA_MOUNTED);
        intentFilter1.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
        intentFilter1.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED);
        intentFilter1.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
        intentFilter1.addAction(Intent.ACTION_MEDIA_EJECT);
     // install an intent filter to receive UMS(USB) related events.
        intentFilter1.addAction(Intent.ACTION_UMS_CONNECTED);
        intentFilter1.addAction(Intent.ACTION_UMS_DISCONNECTED);
        intentFilter1.addAction("USB_INTENT");
        intentFilter1.addDataScheme("file");

        mReceiver1 = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                Toast.makeText(context, context.toString(),
Toast.LENGTH_LONG).show();

                String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
                        Toast.makeText(context, "SD Card mounted",
Toast.LENGTH_LONG).show();

                } else if (action.equals
(Intent.ACTION_MEDIA_UNMOUNTED)) {
                    Toast.makeText(context, "SD Card unmounted",
Toast.LENGTH_LONG).show();

                } else if (action.equals
(Intent.ACTION_MEDIA_SCANNER_STARTED)) {
                    Toast.makeText(context, "SD Card scanner started",
Toast.LENGTH_LONG).show();

                } else if (action.equals
(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
                        Toast.makeText(context, "SD Card scanner finished",
Toast.LENGTH_LONG).show();

                } else if (action.equals(Intent.ACTION_MEDIA_EJECT)) {
                        Toast.makeText(context, "SD Card eject",
Toast.LENGTH_LONG).show();

                } else if(action.equals(Intent.ACTION_UMS_CONNECTED))
{
                        Toast.makeText(context, "connected",
Toast.LENGTH_LONG).show();
                } else if(action.equals
(Intent.ACTION_UMS_DISCONNECTED)) {
                        Toast.makeText(context, "disconnected",
Toast.LENGTH_LONG).show();
                }
                // BONG_TEST }
            }
        };

        registerReceiver(mReceiver1, intentFilter1);
     }
}

-- 
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