Example usage for android.content Intent ACTION_DEVICE_STORAGE_LOW

List of usage examples for android.content Intent ACTION_DEVICE_STORAGE_LOW

Introduction

In this page you can find the example usage for android.content Intent ACTION_DEVICE_STORAGE_LOW.

Prototype

String ACTION_DEVICE_STORAGE_LOW

To view the source code for android.content Intent ACTION_DEVICE_STORAGE_LOW.

Click Source Link

Document

Broadcast Action: A sticky broadcast that indicates low storage space condition on the device

This is a protected intent that can only be sent by the system.

Usage

From source file:com.kncwallet.wallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = prefs.getInt(Constants.PREFS_KEY_BEST_CHAIN_HEIGHT_EVER, 0);

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);//from w  ww.  ja v  a2s  .  c o m

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets().open(Constants.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java

private void checkLowStorageAlert() {
    final Intent stickyIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
    if (stickyIntent != null)
        showDialog(DIALOG_LOW_STORAGE_ALERT);
}

From source file:crea.wallet.lite.service.CreativeCoinService.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    super.onCreate();

    boolean startService = WalletHelper.INSTANCE != null;

    transactionsReceived = new HashMap<>();
    Log.e(TAG, "START_SERVICE=" + startService);
    if (startService) {
        nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        WalletHelper.INSTANCE.autoSave(10);
        final String lockName = getPackageName() + " blockchain sync";

        final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);
        application = WalletApplication.INSTANCE;

        setWalletListener();/*w w  w  .j av  a  2  s . c om*/

        peerConnectivityListener = new PeerConnectivityListener();

        blockChainFile = Constants.WALLET.BLOCKCHAIN_FILE;
        final boolean blockChainFileExists = blockChainFile.exists();

        if (!blockChainFileExists) {
            new File(Constants.WALLET.WALLET_PATH).mkdirs();
        }
        try {
            blockStore = new SPVBlockStore(NETWORK_PARAMETERS, blockChainFile);
            blockStore.getChainHead(); // detect corruptions as early as possible

            final long earliestKeyCreationTime = WalletHelper.INSTANCE.getKeyCreationTime();

            Log.e(TAG, "CREATION_TIME=" + earliestKeyCreationTime + " BLOCKCHAIN_FILE=" + blockChainFileExists);
            if (!blockChainFileExists && earliestKeyCreationTime > 0) {
                try {
                    Configuration.getInstance().setDeletingBlockchain(true);
                    final long start = System.currentTimeMillis();
                    final InputStream checkpointsInputStream = getAssets()
                            .open("bitcoin/" + Constants.WALLET.CHECKPOINTS_FILENAME);
                    CheckpointManager.checkpoint(NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                            earliestKeyCreationTime);
                    Log.e(TAG, String.format("checkpoints loaded from '%1$s', took %2$dms",
                            Constants.WALLET.CHECKPOINTS_FILENAME, System.currentTimeMillis() - start));
                } catch (final IOException x) {
                    Log.e(TAG, "problem reading checkpoints, continuing without", x);
                }
            }
        } catch (final BlockStoreException x) {
            blockChainFile.delete();

            final String msg = "blockstore cannot be created";
            Log.e(TAG, msg, x);
        }

        try {
            blockChain = new BlockChain(NETWORK_PARAMETERS, WalletHelper.INSTANCE.getWallet(), blockStore);
        } catch (final BlockStoreException x) {
            throw new Error("blockchain cannot be created", x);
        }

        final IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
        intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
        registerReceiver(connectivityReceiver, intentFilter); // implicitly start PeerGroup

        registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
    } else {
        Log.e(TAG, "Incomplete conditions for start service");
        stopSelf();
    }
}

From source file:com.hamradiocoin.wallet.service.BlockchainServiceImpl.java

@Override
public void onCreate() {
    serviceCreatedAt = System.currentTimeMillis();
    log.debug(".onCreate()");

    super.onCreate();

    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    application = (WalletApplication) getApplication();
    config = application.getConfiguration();
    final Wallet wallet = application.getWallet();

    bestChainHeightEver = config.getBestChainHeightEver();

    peerConnectivityListener = new PeerConnectivityListener();

    sendBroadcastPeerState(0);/* w  w  w  .  j  av a2s . co  m*/

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    blockChainFile = new File(getDir("blockstore", Context.MODE_PRIVATE), Constants.Files.BLOCKCHAIN_FILENAME);
    final boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new SPVBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();

        if (!blockChainFileExists && earliestKeyCreationTime > 0) {
            try {
                final InputStream checkpointsInputStream = getAssets()
                        .open(Constants.Files.CHECKPOINTS_FILENAME);
                CheckpointManager.checkpoint(Constants.NETWORK_PARAMETERS, checkpointsInputStream, blockStore,
                        earliestKeyCreationTime);
            } catch (final IOException x) {
                log.error("problem reading checkpoints, continuing without", x);
            }
        }
    } catch (final BlockStoreException x) {
        blockChainFile.delete();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new BlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
}

From source file:cc.mintcoin.wallet.service.BlockchainServiceImpl.java

private void startBlockChain() {
    if (blockChain != null)
        return;//from   www .j  av  a 2s  .c  o  m

    final Wallet wallet = application.getWallet();

    final String lockName = getPackageName() + " blockchain sync";

    final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lockName);

    peerConnectivityListener = new PeerConnectivityListener();
    sendBroadcastPeerState(0);

    final IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
    intentFilter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
    registerReceiver(connectivityReceiver, intentFilter);

    boolean blockChainFileExists = blockChainFile.exists();

    if (!blockChainFileExists) {
        log.info("blockchain does not exist, resetting wallet");

        wallet.clearTransactions(0);
        wallet.setLastBlockSeenHeight(-1); // magic value
        wallet.setLastBlockSeenHash(null);
    }

    try {
        blockStore = new TxTrackingBlockStore(Constants.NETWORK_PARAMETERS, blockChainFile);
        blockStore.getChainHead(); // detect corruptions as early as possible

        final long earliestKeyCreationTime = wallet.getEarliestKeyCreationTime();
    } catch (final BlockStoreException x) {
        deleteBlockChainFile();

        final String msg = "blockstore cannot be created";
        log.error(msg, x);
        throw new Error(msg, x);
    }

    log.info("using " + blockStore.getClass().getName());

    try {
        blockChain = new TxTrackingBlockChain(Constants.NETWORK_PARAMETERS, wallet, blockStore);
    } catch (final BlockStoreException x) {
        throw new Error("blockchain cannot be created", x);
    }

    application.getWallet().addEventListener(walletEventListener, Threading.SAME_THREAD);

    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));

    maybeRotateKeys();
    return;
}

From source file:com.kncwallet.wallet.ui.WalletActivity.java

private void checkLowStorageAlert() {
    final Intent stickyIntent = registerReceiver(null, new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW));
    if (stickyIntent != null) {
        final KnCDialog.Builder builder = new KnCDialog.Builder(this);
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.wallet_low_storage_dialog_title);
        builder.setMessage(R.string.wallet_low_storage_dialog_msg);
        builder.setPositiveButton(R.string.wallet_low_storage_dialog_button_apps,
                new DialogInterface.OnClickListener() {
                    @Override//from  w ww . j  a  va  2s .  c  o  m
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivity(
                                new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS));
                        finish();
                    }
                });
        builder.setNegativeButton(R.string.button_dismiss, null);
        builder.show();
    }
}