Java Code Examples for android.content.Intent#ACTION_MEDIA_EJECT
The following examples show how to use
android.content.Intent#ACTION_MEDIA_EJECT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoModule.java From Camera2 with Apache License 2.0 | 5 votes |
private void installIntentFilter() { // install an intent filter to receive SD card related events. IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT); intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); intentFilter.addDataScheme("file"); mReceiver = new MyBroadcastReceiver(); mActivity.registerReceiver(mReceiver, intentFilter); }
Example 2
Source File: StatusServiceImpl.java From Cangol-appcore with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction() == Intent.ACTION_MEDIA_EJECT) { //do nothings } else if (intent.getAction() == Intent.ACTION_MEDIA_SHARED) { //do nothings } else if (intent.getAction() == Intent.ACTION_MEDIA_BAD_REMOVAL) { //do nothings } else if (intent.getAction() == Intent.ACTION_MEDIA_REMOVED) { notifyStorageRemove(context); } else if (intent.getAction() == Intent.ACTION_MEDIA_MOUNTED) { notifyStorageMount(context); } }
Example 3
Source File: DownloadServiceLifecycleSupport.java From Audinaut with GNU General Public License v3.0 | 4 votes |
public void onCreate() { new Thread(() -> { Looper.prepare(); eventLooper = Looper.myLooper(); eventHandler = new Handler(eventLooper); // Deserialize queue before starting looper try { lock.lock(); deserializeDownloadQueueNow(); // Wait until PREPARING is done to mark lifecycle as ready to receive events while (downloadService.getPlayerState() == PREPARING) { Util.sleepQuietly(50L); } setup.set(true); } finally { lock.unlock(); } Looper.loop(); }, "DownloadServiceLifecycleSupport").start(); // Stop when SD card is ejected. ejectEventReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { externalStorageAvailable = Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction()); if (!externalStorageAvailable) { Log.i(TAG, "External media is ejecting. Stopping playback."); downloadService.reset(); } else { Log.i(TAG, "External media is available."); } } }; IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT); ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); ejectFilter.addDataScheme("file"); downloadService.registerReceiver(ejectEventReceiver, ejectFilter); // React to media buttons. Util.registerMediaButtonEventReceiver(downloadService); // Pause temporarily on incoming phone calls. phoneStateListener = new MyPhoneStateListener(); // Android 6.0 removes requirement for android.Manifest.permission.READ_PHONE_STATE; TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Register the handler for outside intents. IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(DownloadService.CMD_PLAY); commandFilter.addAction(DownloadService.CMD_TOGGLEPAUSE); commandFilter.addAction(DownloadService.CMD_PAUSE); commandFilter.addAction(DownloadService.CMD_STOP); commandFilter.addAction(DownloadService.CMD_PREVIOUS); commandFilter.addAction(DownloadService.CMD_NEXT); commandFilter.addAction(DownloadService.CANCEL_DOWNLOADS); downloadService.registerReceiver(intentReceiver, commandFilter); new CacheCleaner(downloadService, downloadService).clean(); }
Example 4
Source File: DownloadServiceLifecycleSupport.java From Popeens-DSub with GNU General Public License v3.0 | 4 votes |
public void onCreate() { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); eventLooper = Looper.myLooper(); eventHandler = new Handler(eventLooper); // Deserialize queue before starting looper try { lock.lock(); deserializeDownloadQueueNow(); // Wait until PREPARING is done to mark lifecycle as ready to receive events while(downloadService.getPlayerState() == PREPARING) { Util.sleepQuietly(50L); } setup.set(true); } finally { lock.unlock(); } Looper.loop(); } }, "DownloadServiceLifecycleSupport").start(); // Stop when SD card is ejected. ejectEventReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { externalStorageAvailable = Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction()); if (!externalStorageAvailable) { Log.i(TAG, "External media is ejecting. Stopping playback."); downloadService.reset(); } else { Log.i(TAG, "External media is available."); } } }; IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT); ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED); ejectFilter.addDataScheme("file"); downloadService.registerReceiver(ejectEventReceiver, ejectFilter); // React to media buttons. Util.registerMediaButtonEventReceiver(downloadService); // Pause temporarily on incoming phone calls. phoneStateListener = new MyPhoneStateListener(); // Android 6.0 removes requirement for android.Manifest.permission.READ_PHONE_STATE; TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); // Register the handler for outside intents. IntentFilter commandFilter = new IntentFilter(); commandFilter.addAction(DownloadService.CMD_PLAY); commandFilter.addAction(DownloadService.CMD_TOGGLEPAUSE); commandFilter.addAction(DownloadService.CMD_PAUSE); commandFilter.addAction(DownloadService.CMD_STOP); commandFilter.addAction(DownloadService.CMD_PREVIOUS); commandFilter.addAction(DownloadService.CMD_NEXT); commandFilter.addAction(DownloadService.CANCEL_DOWNLOADS); downloadService.registerReceiver(intentReceiver, commandFilter); new CacheCleaner(downloadService, downloadService).clean(); }