Android StorageManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android StorageManager class.

This code example shows how to use the following methods:isUsbMassStorageConnected
 
    public StorageNotification(Context context) {
        mContext = context;
 
        mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        final boolean connected = mStorageManager.isUsbMassStorageConnected();
        if (DEBUG) Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
                mUmsAvailable, Environment.getExternalStorageState()));
         
        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
        thr.start();
        mAsyncEventHandler = new Handler(thr.getLooper());
 
        onUsbMassStorageConnectionChanged(connected);
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMountedObbPath, isObbMounted, mountObb
    } 
 
    private void mountPatch() { 
        if (patchFile.exists()) {
            Log.d(TAG, "Mounting patch file...");
            sm.mountObb(patchFile.getAbsolutePath(), null, new OnObbStateChangeListener() {
                @Override 
                public void onObbStateChange(String path, int state) {
                    super.onObbStateChange(path, state);
                    if (state == MOUNTED) {
                        Log.d(TAG, "Mounting patch file done.");
                        patch = sm.getMountedObbPath(patchFile.getAbsolutePath());
                    } else { 
                        Log.d(TAG, "Mounting patch file failed with state = " + state);
                        listener.onObbStateChange(path, state);
                    } 
                } 
            }); 
            if (sm.isObbMounted(patchFile.getAbsolutePath())) {
                patch = sm.getMountedObbPath(patchFile.getAbsolutePath());

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isUsbMassStorageConnected
 
    public StorageNotification(Context context) {
        mContext = context;
 
        mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        mUmsAvailable = mStorageManager.isUsbMassStorageConnected();
        Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)", mUmsAvailable,
                Environment.getExternalStorageState()));
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
    public void onUsbMassStorageConnectionChanged(boolean connected) {
        mUmsAvailable = connected;
        /* 
         * Even though we may have a UMS host connected, we the SD card 
         * may not be in a state for export. 
         */ 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isUsbMassStorageConnected
 
    public StorageNotification(Context context) {
        mContext = context;
 
        mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
        final boolean connected = mStorageManager.isUsbMassStorageConnected();
        if (DEBUG) Slog.d(TAG, String.format( "Startup with UMS connection %s (media state %s)",
                mUmsAvailable, Environment.getExternalStorageState()));
         
        HandlerThread thr = new HandlerThread("SystemUI StorageNotification");
        thr.start();
        mAsyncEventHandler = new Handler(thr.getLooper());
 
        onUsbMassStorageConnectionChanged(connected);
    } 
 
    /* 
     * @override com.android.os.storage.StorageEventListener 
     */ 
    @Override 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getMountedObbPath
                @Override 
                public void onObbStateChange(String path, int state) {
                    super.onObbStateChange(path, state);
                    if (state == MOUNTED) {
                        Log.d(TAG, "Mounting main file done.");
                        main = sm.getMountedObbPath(mainFile.getAbsolutePath());
                        listener.onMountSuccess();
                        mainChecker.cancel();
                    } else { 
                        Log.d(TAG, "Mounting main file failed with state = " + state);
                        listener.onObbStateChange(path, state);
                    } 
                } 
            }); 
        } else { 
            Log.d(TAG, "Patch file not found");
        } 
    } 
 
    public static boolean isMainFileExists(Context context) {
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getVolumeState
            mounted = true;
        } else { 
            StorageManager storageManager = (StorageManager)context.getSystemService(Context.STORAGE_SERVICE);
            if (storageManager != null) {
                defaultStoragePath = StorageManager.getDefaultPath();
                defaultStorageState = storageManager.getVolumeState(defaultStoragePath);
                if (Environment.MEDIA_MOUNTED.equals(defaultStorageState) ||
                        Environment.MEDIA_MOUNTED_READ_ONLY.equals(defaultStorageState)) {
                    mounted = true;
                } 
            } 
        } 
        if (LOG) MtkLog.v(TAG, "isMediaMounted() return " + mounted + ", state=" + state
                + ", defaultStoragePath=" + defaultStoragePath + ", defaultStorageState=" + defaultStorageState);
        return mounted;
    } 
     
    public static String stringForTime(long millis) {
        int totalSeconds = (int) millis / 1000;
        int seconds = totalSeconds % 60;
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getDefaultPath
	} 
	private static File mFile;
	 
	public File getExternalStorageDirectory(){
        StorageManager mSM = (StorageManager) getApplicationContext().getSystemService(STORAGE_SERVICE);
        String path = mSM.getDefaultPath();
        final File file = getDirectory(path, "/mnt/sdcard");
        Log.i(TAG,"[getExternalStorageDirectory]file.path : "+file.getPath());
        mFile = file;
        return file;
    } 
	 
	public  File getDirectory(String path, String defaultPath) {
        Log.i("getDirectory","path : "+path);
        return path == null ? new File(defaultPath) : new File(path);
    } 
	 
    public static String getExternalStorageState() {
        try { 
            IMountService mountService = IMountService.Stub.asInterface(ServiceManager
3
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android StorageManager Questions & Answers:

See Code Examples for Android StorageManager Methods: