Search in sources :

Example 16 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Anki-Android by Ramblurr.

the class DeckOptions method registerExternalStorageListener.

/**
     * finish when sd card is ejected
     */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    finish();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 17 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Anki-Android by Ramblurr.

the class DeckPicker method registerExternalStorageListener.

/**
     * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver)
     */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (AnkiDroidApp.getSharedPrefs(getBaseContext()).getBoolean("internalMemory", false)) {
                    return;
                }
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
                } else if (intent.getAction().equals(SdCardReceiver.MEDIA_MOUNT)) {
                    if (mNotMountedDialog != null && mNotMountedDialog.isShowing()) {
                        mNotMountedDialog.dismiss();
                    }
                    loadCollection();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        iFilter.addAction(SdCardReceiver.MEDIA_MOUNT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 18 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Anki-Android by Ramblurr.

the class CardEditor method registerExternalStorageListener.

// ----------------------------------------------------------------------------
// CUSTOM METHODS
// ----------------------------------------------------------------------------
/**
     * finish when sd card is ejected
     */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    finish();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 19 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Anki-Android by Ramblurr.

the class CramDeckOptions method registerExternalStorageListener.

/**
     * finish when sd card is ejected
     */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    finish();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 20 with BroadcastReceiver

use of android.content.BroadcastReceiver in project Anki-Android by Ramblurr.

the class StudyOptionsActivity method registerExternalStorageListener.

/**
     * Show/dismiss dialog when sd card is ejected/remounted (collection is saved by SdCardReceiver)
     */
private void registerExternalStorageListener() {
    if (mUnmountReceiver == null) {
        mUnmountReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals(SdCardReceiver.MEDIA_EJECT)) {
                    mNotMountedDialog = StyledOpenCollectionDialog.show(StudyOptionsActivity.this, getResources().getString(R.string.sd_card_not_mounted), new OnCancelListener() {

                        @Override
                        public void onCancel(DialogInterface arg0) {
                            finish();
                        }
                    });
                } else if (intent.getAction().equals(SdCardReceiver.MEDIA_MOUNT)) {
                    if (mNotMountedDialog != null && mNotMountedDialog.isShowing()) {
                        mNotMountedDialog.dismiss();
                    }
                    mCurrentFragment.reloadCollection();
                }
            }
        };
        IntentFilter iFilter = new IntentFilter();
        iFilter.addAction(SdCardReceiver.MEDIA_EJECT);
        iFilter.addAction(SdCardReceiver.MEDIA_MOUNT);
        registerReceiver(mUnmountReceiver, iFilter);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)375 Intent (android.content.Intent)349 Context (android.content.Context)333 IntentFilter (android.content.IntentFilter)270 PendingIntent (android.app.PendingIntent)90 RemoteException (android.os.RemoteException)26 Test (org.junit.Test)23 Semaphore (java.util.concurrent.Semaphore)20 IOException (java.io.IOException)18 Point (android.graphics.Point)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ArrayList (java.util.ArrayList)15 AndroidRuntimeException (android.util.AndroidRuntimeException)14 GlobalContext (org.qii.weiciyuan.support.utils.GlobalContext)13 ComponentName (android.content.ComponentName)11 Handler (android.os.Handler)10 ErrnoException (android.system.ErrnoException)9 PackageManager (android.content.pm.PackageManager)8 ContentObserver (android.database.ContentObserver)8 Bundle (android.os.Bundle)8