You have specified a data scheme for that filter, but as far as I know those broadcasts do not include data.
On Thu, Nov 19, 2009 at 9:05 PM, krekar <[email protected]> wrote: > 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]<android-developers%[email protected]> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Dianne Hackborn Android framework engineer [email protected] Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. -- 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

