Depois de muito fuçar em coisas sem sentido, apareceu a linha q faltava
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);
ifilter.addDataScheme("file");
mReceiver = new sdCardReceiver();
registerReceiver(mReceiver, ifilter);
}
:/
--
Carlos Eduardo Simões Pelegrin
2013/9/25 Carlos Pelegrin <carloseduardopelegrin@gmail.com>
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;@Overrideprotected 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 {@Overridepublic 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_sdO valor de getExternalStorageDirectory() == /mnt/sdcarde 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.
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