android.content.Context#getDir ( )源码实例Demo

下面列出了android.content.Context#getDir ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenCvFaceDetect   文件: Utils.java
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码2 项目: ResistorScanner   文件: Utils.java
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码3 项目: FTCVision   文件: Utils.java
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码4 项目: SoftwarePilot   文件: Utils.java
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码5 项目: MOAAP   文件: Utils.java
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码6 项目: letv   文件: HotFix.java
public static void patch(Context context, String dexFileName, InputStream dexInputStream) {
    File dexPath = new File(context.getDir(Constant.JAR_IN_FOLDER_NAME, 0), dexFileName);
    if (prepareDex(dexPath, dexInputStream)) {
        String patchDexFile = dexPath.getAbsolutePath();
        if (new File(patchDexFile).exists()) {
            try {
                if (hasLexClassLoader()) {
                    injectInAliyunOs(context, patchDexFile);
                } else if (hasDexClassLoader()) {
                    injectAboveEqualApiLevel14(context, patchDexFile);
                } else {
                    injectBelowApiLevel14(context, patchDexFile);
                }
                Log.d(TAG, "dex patch is load the success");
            } catch (Exception e) {
                Log.e(TAG, e.getMessage());
            }
        }
    }
}
 
源代码7 项目: JZVideoDemo   文件: IjkMediaPlayer.java
public static void loadLibrariesOnce(IjkLibLoader libLoader, Context context) {
        synchronized (IjkMediaPlayer.class) {
            if (!mIsLibLoaded) {
                if (libLoader == null)
                    libLoader = sLocalLibLoader;

//                libLoader.loadLibrary("ijkffmpeg");
                File dir = context.getDir("libs", Context.MODE_PRIVATE);
                final File soFile = new File(dir, "ijkffmpeg.so");
                System.load(soFile.getAbsolutePath());
                libLoader.loadLibrary("ijksdl");
                libLoader.loadLibrary("ijkplayer");
                mIsLibLoaded = true;
            }
        }
    }
 
public static String exportResource(Context context, int resourceId, String dirname) {
    String fullname = context.getResources().getString(resourceId);
    String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
    try {
        InputStream is = context.getResources().openRawResource(resourceId);
        File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
        File resFile = new File(resDir, resName);

        FileOutputStream os = new FileOutputStream(resFile);

        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = is.read(buffer)) != -1) {
            os.write(buffer, 0, bytesRead);
        }
        is.close();
        os.close();

        return resFile.getAbsolutePath();
    } catch (IOException e) {
        e.printStackTrace();
        throw new CvException("Failed to export resource " + resName
                + ". Exception thrown: " + e);
    }
}
 
源代码9 项目: OTTLivePlayer_vlc   文件: Medialibrary.java
public int init(Context context) {
    if (context == null)
        return ML_INIT_FAILED;
    sContext = context;
    File extFilesDir = context.getExternalFilesDir(null);
    File dbDirectory = context.getDir("db", Context.MODE_PRIVATE);
    if (extFilesDir == null || !extFilesDir.exists()
            || dbDirectory == null || !dbDirectory.canWrite())
        return ML_INIT_FAILED;
    int initCode = nativeInit(dbDirectory+ VLC_MEDIA_DB_NAME, extFilesDir+ THUMBS_FOLDER_NAME);
    mIsInitiated = initCode != ML_INIT_FAILED;
    return initCode;
}
 
源代码10 项目: MarsDaemon   文件: DaemonStrategyXiaomi.java
private boolean install(Context context, String destDirName, String assetsDirName, String filename) {
	File file = new File(context.getDir(destDirName, Context.MODE_PRIVATE), filename);
	if (file.exists()) {
		return true;
	}
	try {
		copyAssets(context, (TextUtils.isEmpty(assetsDirName) ? "" : (assetsDirName + File.separator)) + filename, file, "700");
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
源代码11 项目: springreplugin   文件: PluginInfo.java
/**
 * 获取Dex(优化后)生成时所在的目录 <p>
 * 若为"纯APK"插件,则会位于app_p_od中;若为"p-n"插件,则会位于"app_plugins_v3_odex"中 <p>
 * 若支持同版本覆盖安装的话,则会位于app_p_c中; <p>
 * 注意:仅供框架内部使用
 *
 * @return 优化后Dex所在目录的File对象
 */
public File getDexParentDir() {
    // 必须使用宿主的Context对象,防止出现“目录定位到插件内”的问题
    Context context = RePluginInternal.getAppContext();
    if (isPnPlugin()) {
        return context.getDir(AppConstant.LOCAL_PLUGIN_ODEX_SUB_DIR, 0);
    } else if (getIsPendingCover()) {
        return context.getDir(AppConstant.LOCAL_PLUGIN_APK_COVER_DIR, 0);
    } else {
        return context.getDir(AppConstant.LOCAL_PLUGIN_APK_ODEX_SUB_DIR, 0);
    }
}
 
源代码12 项目: AppOpsX   文件: BFileUtils.java
static File getBackupDir(Context context) {
  File externalFilesDir = context.getExternalFilesDir(DIR_NAME);
  if (externalFilesDir != null) {
    if (externalFilesDir.exists()) {
      return externalFilesDir;
    } else {
      boolean mkdirs = externalFilesDir.mkdirs();
      if (mkdirs) {
        return externalFilesDir;
      }
    }
  }
  return context.getDir(DIR_NAME, Context.MODE_PRIVATE);
}
 
源代码13 项目: MarsDaemon   文件: DaemonStrategyUnder21.java
private boolean install(Context context, String destDirName, String assetsDirName, String filename) {
	File file = new File(context.getDir(destDirName, Context.MODE_PRIVATE), filename);
	if (file.exists()) {
		return true;
	}
	try {
		copyAssets(context, (TextUtils.isEmpty(assetsDirName) ? "" : (assetsDirName + File.separator)) + filename, file, "700");
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
源代码14 项目: ApkShield   文件: ShieldClassLoader.java
public ShieldClassLoader(
		String desDexPath ,
		Context context ,
		String dexPath ,
		PathClassLoader parent )
{
	super( dexPath , parent );
	File file = new File( desDexPath );
	this.context = context;
	this.mClassLoader = parent;
	//  		
	try
	{
		List<String> libraryPathElements;
		//			Class cls = mClassLoader.getClass();
		Class cls = PathClassLoader.class;
		Field[] fields = cls.getDeclaredFields();
		Method[] methods = cls.getDeclaredMethods();
		//			Field field = mClassLoader.getClass().getDeclaredField( "pathList" );			
		//			field.setAccessible( true );
		//			Object pathList = field.get( mClassLoader );
		//			field = pathList.getClass().getDeclaredField( "nativeLibraryDirectories" );
		//			field.setAccessible( true );
		//			File[] path = (File[])field.get( pathList );
		//拿到originalclassloader  
		//			List<String> libraryPath = (List<String>)field.get( mClassLoader );
		//====================================
		File dexOutputDir = context.getDir( "dex" , 0 );
		mDexClassLoader = new ShieldDexClassLoader( file.getAbsolutePath() , dexOutputDir.getAbsolutePath() , file.getAbsolutePath() , (PathClassLoader)context.getClassLoader() );
	}
	catch( Exception e )
	{
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	// TODO Auto-generated constructor stub
}
 
源代码15 项目: GPT   文件: ApkInstaller.java
/**
 * 返回 greedyporter 的根目录 /data/data/hostapp/app_greedyporter
 *
 * @param context host的context
 * @return 插件跟路径
 */
public static File getGreedyPorterRootPath(Context context) {
    File repoDir = context.getDir(PLUGIN_PATH, 0);

    if (!repoDir.exists()) {
        repoDir.mkdir();
    }
    return repoDir;
}
 
private File getLegacyFile(@NonNull Context context, long id) {
  return new File(context.getDir("captures", Context.MODE_PRIVATE), id + "." + BLOB_EXTENSION);
}
 
源代码17 项目: android-classyshark   文件: DexLoaderBuilder.java
public static DexClassLoader fromBytes(Context context, final byte[] dexBytes) throws Exception {

        if (null == context) {
            throw new RuntimeException("No context provided");
        }

        String dexFileName = "internal.dex";

        final File dexInternalStoragePath = new File(context.getDir("dex", Context.MODE_PRIVATE), dexFileName);

        if (!dexInternalStoragePath.exists()) {

            prepareDex(dexBytes, dexInternalStoragePath);
        }

        final File optimizedDexOutputPath = context.getCodeCacheDir();

        DexClassLoader loader = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
                optimizedDexOutputPath.getAbsolutePath(), null, context.getClassLoader().getParent());

        dexInternalStoragePath.delete();

        return loader;
    }
 
源代码18 项目: CameraV   文件: VideoConstructor.java
public VideoConstructor(Context context) throws FileNotFoundException, IOException {
	fileBinDir = context.getDir("bin",Context.MODE_PRIVATE);		
	ffmpegCtrl = new FfmpegController(context, context.getCacheDir());
	ffmpegBinPath = ffmpegCtrl.getBinaryPath();
}
 
源代码19 项目: delion   文件: WebappDirectoryManager.java
/** Returns the directory containing all of Chrome's web app data, creating it if needed. */
final File getBaseWebappDirectory(Context context) {
    return context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
}
 
源代码20 项目: 365browser   文件: WebappDirectoryManager.java
/** Returns the directory containing all of Chrome's web app data, creating it if needed. */
final File getBaseWebappDirectory(Context context) {
    return context.getDir(WEBAPP_DIRECTORY_NAME, Context.MODE_PRIVATE);
}
 
 方法所在类
 同类方法