当前位置: 首页>>代码示例>>Java>>正文


Java Context.getDir方法代码示例

本文整理汇总了Java中android.content.Context.getDir方法的典型用法代码示例。如果您正苦于以下问题:Java Context.getDir方法的具体用法?Java Context.getDir怎么用?Java Context.getDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.getDir方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: exportResource

import android.content.Context; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:jorenham,项目名称:fingerblox,代码行数:26,代码来源:Utils.java

示例2: onDaemonAssistantCreate

import android.content.Context; //导入方法依赖的package包/类
@Override
public void onDaemonAssistantCreate(final Context context, DaemonConfigurations configs) {
	initAmsBinder();
	initServiceParcel(context, configs.PERSISTENT_CONFIG.SERVICE_NAME);
	startServiceByAmsBinder();
	
	Thread t = new Thread(){
		public void run() {
			File indicatorDir = context.getDir(INDICATOR_DIR_NAME, Context.MODE_PRIVATE);
			new NativeDaemonAPI21(context).doDaemon(
					new File(indicatorDir, INDICATOR_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(), 
					new File(indicatorDir, INDICATOR_PERSISTENT_FILENAME).getAbsolutePath(), 
					new File(indicatorDir, OBSERVER_DAEMON_ASSISTANT_FILENAME).getAbsolutePath(),
					new File(indicatorDir, OBSERVER_PERSISTENT_FILENAME).getAbsolutePath());
		};
	};
	t.start();
	
	if(configs != null && configs.LISTENER != null){
		this.mConfigs = configs;
		configs.LISTENER.onDaemonAssistantStart(context);
	}
	
}
 
开发者ID:paozhuanyinyu,项目名称:FreshMember,代码行数:25,代码来源:DaemonStrategy22.java

示例3: create

import android.content.Context; //导入方法依赖的package包/类
public static ReadStateHelper create(Context context, String fileName, int maxPoolSize) {
    fileName = fileName + ".json";
    if (helperCache.containsKey(fileName)) {
        return helperCache.get(fileName);
    }
    File file = new File(context.getDir("read_state", Context.MODE_PRIVATE), fileName);
    if (!file.exists()) {
        File parent = file.getParentFile();
        if (!parent.exists() && !parent.mkdirs()) {
            throw new RuntimeException("can't mkdirs by:" + parent.toString());
        }
        try {
            if (!file.createNewFile()) {
                throw new IOException("can't createNewFile by:" + file.toString());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    ReadStateHelper helper = new ReadStateHelper(file, maxPoolSize);
    helperCache.put(fileName, helper);// key值是文件名, 博客:blog 或 新闻:news 等配置的文件名。
    return helper;
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:24,代码来源:ReadStateHelper.java

示例4: deleteUnknownLibs

import android.content.Context; //导入方法依赖的package包/类
private static void deleteUnknownLibs(Context context, PxAll all) {
    HashSet<String> names = new HashSet<>();
    for (PluginInfo p : all.getPlugins()) {
        names.add(p.getNativeLibsDir().getName());
    }

    File dir = context.getDir(AppConstant.LOCAL_PLUGIN_DATA_LIB_DIR, 0);
    File files[] = dir.listFiles();
    if (files != null) {
        for (File f : files) {
            if (names.contains(f.getName())) {
                continue;
            }
            if (LOG) {
                LogDebug.d(PLUGIN_TAG, "delete unknown libs=" + f.getAbsolutePath());
            }
            try {
                FileUtils.forceDelete(f);
            } catch (IOException e) {
                if (LOG) {
                    LogDebug.d(PLUGIN_TAG, "can't delete unknown libs=" + f.getAbsolutePath(), e);
                }
            }
        }
    }
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:27,代码来源:Builder.java

示例5: readCascadeFile

import android.content.Context; //导入方法依赖的package包/类
/**
 * Reads a Cascade file from a raw resource and returns the {@link File}
 */
public static File readCascadeFile(Context context, int rawFile, String dir,
                                   String fileOutput) throws IOException {
    // load cascade file from application resources
    InputStream is = context.getResources().openRawResource(rawFile);
    File cascadeDir = context.getDir(dir, Context.MODE_PRIVATE);
    File cascadeFile = new File(cascadeDir, fileOutput);
    FileOutputStream os = new FileOutputStream(cascadeFile);
    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = is.read(buffer)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    is.close();
    os.close();
    return cascadeFile;
}
 
开发者ID:raulh82vlc,项目名称:Image-Detection-Samples,代码行数:20,代码来源:FileHelper.java

示例6: initIndicators

import android.content.Context; //导入方法依赖的package包/类
private boolean initIndicators(Context context){
	File dirFile = context.getDir(INDICATOR_DIR_NAME, Context.MODE_PRIVATE);
	if(!dirFile.exists()){
		dirFile.mkdirs();
	}
	try {
		createNewFile(dirFile, INDICATOR_PERSISTENT_FILENAME);
		createNewFile(dirFile, INDICATOR_DAEMON_ASSISTANT_FILENAME);
		return true;
	} catch (IOException e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:paozhuanyinyu,项目名称:FreshMember,代码行数:15,代码来源:DaemonStrategy21.java

示例7: getDexParentDir

import android.content.Context; //导入方法依赖的package包/类
/**
 * 获取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);
    }
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:20,代码来源:PluginInfo.java

示例8: getNativeLibsDir

import android.content.Context; //导入方法依赖的package包/类
/**
 * 根据类型来获取SO释放的路径 <p>
 * 若为"纯APK"插件,则会位于app_p_n中;若为"p-n"插件,则会位于"app_plugins_v3_libs"中 <p>
 * 注意:仅供框架内部使用
 *
 * @return SO释放路径所在的File对象
 */
public File getNativeLibsDir() {
    // 必须使用宿主的Context对象,防止出现“目录定位到插件内”的问题
    Context context = RePluginEnv.getHostContext();
    File dir;
    if (isPnPlugin()) {
        dir = context.getDir(LOCAL_PLUGIN_DATA_LIB_DIR, 0);
    } else {
        dir = context.getDir(LOCAL_PLUGIN_APK_LIB_DIR, 0);
    }
    return new File(dir, makeInstalledFileName());
}
 
开发者ID:wangyupeng1-iri,项目名称:springreplugin,代码行数:19,代码来源:PluginInfo.java

示例9: initInternalFilePath

import android.content.Context; //导入方法依赖的package包/类
/**
 * 初始化内部存储目录路径
 *
 * @param context
 */
private static void initInternalFilePath(Context context) {
    final File dir = context.getDir(PACKAGE_NAME_DEFAULT, Context.MODE_PRIVATE);
    if (dir != null) {//优先存在 data/data/packagename/luaview
        PACKAGE_NAME = PACKAGE_NAME_DEFAULT;
        BASE_FILECACHE_PATH = dir.getPath() + File.separator;
    } else {
        PACKAGE_NAME = PACKAGE_NAME_DEFAULT;
        BASE_FILECACHE_PATH = context.getCacheDir() + File.separator;
    }
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:16,代码来源:LuaScriptManager.java

示例10: TorPlugin

import android.content.Context; //导入方法依赖的package包/类
TorPlugin(Executor ioExecutor, Context appContext,
		LocationUtils locationUtils, DevReporter reporter,
		SocketFactory torSocketFactory, Backoff backoff,
		DuplexPluginCallback callback, String architecture, int maxLatency,
		int maxIdleTime) {
	this.ioExecutor = ioExecutor;
	this.appContext = appContext;
	this.locationUtils = locationUtils;
	this.reporter = reporter;
	this.torSocketFactory = torSocketFactory;
	this.backoff = backoff;
	this.callback = callback;
	this.architecture = architecture;
	this.maxLatency = maxLatency;
	this.maxIdleTime = maxIdleTime;
	if (maxIdleTime > Integer.MAX_VALUE / 2)
		socketTimeout = Integer.MAX_VALUE;
	else socketTimeout = maxIdleTime * 2;
	connectionStatus = new ConnectionStatus();
	torDirectory = appContext.getDir("tor", MODE_PRIVATE);
	torFile = new File(torDirectory, "tor");
	geoIpFile = new File(torDirectory, "geoip");
	configFile = new File(torDirectory, "torrc");
	doneFile = new File(torDirectory, "done");
	cookieFile = new File(torDirectory, ".tor/control_auth_cookie");
	Object o = appContext.getSystemService(POWER_SERVICE);
	PowerManager pm = (PowerManager) o;
	wakeLock = pm.newWakeLock(PARTIAL_WAKE_LOCK, "TorPlugin");
	wakeLock.setReferenceCounted(false);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:31,代码来源:TorPlugin.java

示例11: loadLibrary

import android.content.Context; //导入方法依赖的package包/类
public void loadLibrary(String jarpath, Context context) {
    this.context = context;

    File jarfile = new File(jarpath);
    if(!jarfile.exists())
        throw new IllegalArgumentException("Could not find library: " + jarpath);


    this.jarpath = jarpath;

    File optimizedLibrarypath = context.getDir("dex", 0);

    File cachedDex = new File(optimizedLibrarypath.getPath() + "/" + jarpath.replace("jar", "dex"));
    Log.d(TAG, "Checking for cached version in " + optimizedLibrarypath.getAbsolutePath());

    File files[] = optimizedLibrarypath.listFiles();
    for (int i = 0;i < files.length; i++) {
        Log.d(TAG, "File: " + files[i].getName());

        if (files[i].getName().equals(jarfile.getName().replace("jar", "dex"))) {
            Log.d(TAG, "A cached " + files[i].getName() + " exists in " + optimizedLibrarypath.getAbsolutePath() + ". Removing it");
            files[i].delete();
        }
    }

    dexClassLoader = new DexClassLoader(jarpath, optimizedLibrarypath.getAbsolutePath(),
            null, context.getClassLoader());

}
 
开发者ID:charslab,项目名称:Android-Hotpatch,代码行数:30,代码来源:Hotpatch.java

示例12: loadLibrary

import android.content.Context; //导入方法依赖的package包/类
public void loadLibrary(String jarpath, Context context) {
    this.context = context;

    File jarfile = new File(jarpath);
    if(!jarfile.exists())
        throw new IllegalArgumentException("Could not find library: " + jarpath);

    this.jarpath = jarpath;

    File optimizedLibrarypath = context.getDir("dex", 0);

    dexClassLoader = new DexClassLoader(jarpath, optimizedLibrarypath.getAbsolutePath(),
                                        null, context.getClassLoader());

}
 
开发者ID:charslab,项目名称:Android-Hotpatch,代码行数:16,代码来源:Hotpatch.java

示例13: initAndroid

import android.content.Context; //导入方法依赖的package包/类
public static void initAndroid(Context context) {
    homeDir = context.getDir("apktool", Context.MODE_PRIVATE);
    sAndroidAssets = context.getAssets();
}
 
开发者ID:imkiva,项目名称:AndroidApktool,代码行数:5,代码来源:AndroidApktool.java


注:本文中的android.content.Context.getDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。