Boa tarde Pessoal,
-- estou tentando interceptar eventos de Mount e Removal do cartão microSd.
Fiz um BroadcastReceiver assim:
public class MainActivity extends Activity{
private BroadcastReceiver mReceiver;
private IntentFilter ifilter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ifilter = new IntentFilter(Intent.ACTION_MEDIA_MOUNTED);
ifilter.addAction(Intent.ACTION_MEDIA_REMOVED);
ifilter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
ifilter.addAction(Intent.ACTION_MEDIA_EJECT);
mReceiver = new sdCardReceiver();
registerReceiver(mReceiver, ifilter);
}
E o Receiver:
public class sdCardReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("SD", "EVENT");
t.setText("funcionou");
if (intent.getAction().equals(Intent.ACTION_MEDIA_MOUNTED)) {
Log.w("SD", "Mounted");
}else if (intent.getAction().equals(Intent.ACTION_MEDIA_BAD_REMOVAL)) {
Log.w("SD", "Bad Removal");
}
else if (intent.getAction().equals(Intent.ACTION_MEDIA_REMOVED)) {
Log.w("SD", "Removed");
}
}
}
Porém não acontece absolutamente nada!
Analisando o log há mensagens assim:
MountService(382): sendStorageIntent Intent { act=android.intent.action.MEDIA_CHECKING dat=file:///mnt/external_sd (has extras) } to UserHandle{-1}
...
MediaScannerReceiver(5983): action: android.intent.action.MEDIA_MOUNTED path: /mnt/external_sd
O valor de getExternalStorageDirectory() == /mnt/sdcard
e o valor de getExternalStorageState() é sempre "mounted" mesmo sem cartão inserido.
Alguém já viu algo do tipo? Será que tenho que criar um serviço somente para ler tais actions?
Obrigado
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.






0 comentários:
Postar um comentário