android 8.1 MTK 默认存储(插入sdcard时默认sdcard)

1.修改获取默认存储路径的方法
vendor/mediatek/proprietary/frameworks/base/core/java/com/mediatek/storage/StorageManagerEx.java

method: getDefaultPath();

-        path = Environment.getExternalStorageDirectory().getAbsolutePath();
+       // path = Environment.getExternalStorageDirectory().getAbsolutePath();
+
+          path = SystemProperties.get(PROP_SD_DEFAULT_PATH);
+          Log.i(TAG,"StorageManagerEx::getDefaultPath...path1:"+path);
+          if(path.equals("")){
+                  path = Environment.getExternalStorageDirectory().getAbsolutePath();
+          }
         Log.i(TAG, " Default path taken as primary storage, path=" + path);

2.添加获取外部存储路径的方法
vendor/mediatek/proprietary/frameworks/base/core/java/com/mediatek/storage/StorageManagerEx.java


 - /**
   +     * Returns external SD card path.
   +     * @hide
   +     * @internal
   +     */
   +    public static String getExternalStoragePath(Context context) {
   +                 
   +            String path = Environment.getExternalStorageDirectory().getAbsolutePath();
   +
   +            try {
   +                    StorageManager mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
   +                    StorageVolume[] volumeList = mStorageManager.getVolumeList();
   +                    final int length = volumeList.length;
   +                    for (int i = 0; i < length; i++) {
   +                        StorageVolume sv = volumeList[i];
   +                        String getPath = sv.getPath();
   +                        boolean removable = sv.isRemovable();
   +                        Log.d(TAG,"StorageManagerEx::getExternalStoragePath2...getPath:"+getPath+",
   removable:"+removable+", length:"+length+", i:"+i);
   +                        if (removable) {
   +                            path = getPath;
   +                        }
   +                    }
   +
   +            } catch (Exception e) {
   +                e.printStackTrace();
   +            } 
   +
   +            Log.i(TAG,"path1:"+path);
   +            if(path.equals("")){
   +               path = Environment.getExternalStorageDirectory().getAbsolutePath();
   +            }
   +            Log.d(TAG, "getExternalStoragePath2 path=" + path);
   +            return path;
   +
   +    }

3.在Setting建立广播监听T卡拔插,设置默认存储路径
vendor/mediatek/proprietary/packages/apps/MtkSettings/AndroidManifest.xml

+          
+              
+                  
+                  
+                  
+                  
+              
+        

vendor/mediatek/proprietary/packages/apps/MtkSettings/src/com/android/settings/UsbBroadCastReceiver.java

**+package com.android.settings;   
+   
+import android.content.BroadcastReceiver;   
+import android.content.Context;   
+import android.content.Intent;   
+import android.provider.Settings;   
+import android.util.Log;    
+import com.mediatek.storage.StorageManagerEx;   
+   
+public class UsbBroadCastReceiver extends BroadcastReceiver {   
+    String TAG = "UsbBroadCastReceiver";   
+    boolean DEBUG = true; 
+    String externalStoragePath = "";   
+   
+   
+    public void onReceive(Context context, Intent intent) {   
+ 
+       String action = intent.getAction(); 
+ 
+       if(DEBUG) Log.d(TAG,"settings_UsbBroadCastReceiver::onReceive...action:"+action); 
+ 
+       if(Intent.ACTION_MEDIA_MOUNTED.equals(action)){ 
+ 
+               if(DEBUG) Log.d(TAG,"settings_UsbBroadCastReceiver======setDefaultPath..."); 
+ 
+                       externalStoragePath = StorageManagerEx.getExternalStoragePath(context); 
+                        
+               if(null!=externalStoragePath && !"".equals(externalStoragePath) ){ 
+               StorageManagerEx.setDefaultPath(externalStoragePath);  
+               }        
+                        
+                             if(DEBUG) Log.d(TAG,"settings_UsbBroadCastReceiver::onReceive...externalStoragePath:"+externalStoragePath+", defaultPath:"+StorageManagerEx.getDefaultPath());  
+       } 
+ 
+ 
+                
+      //  if (Intent.ACTION_MEDIA_MOUNTED.equals(intent.getAction())) {   
+      //      StorageManagerEx.setDefaultPath(ExternalStoragePath);   
+       // }   
+   
+          
+    }   
+   
+}**  
										hayppy children's day.

你可能感兴趣的:(android客制,android,python,开发语言)