2013-06-05 101 views
0

我打算去的场景如下:Android应用程序外部配置

  1. Android应用(APK),即“通用”,即我不想用不同的资源
  2. APK将重新编译“预安装”在设备上,因此不会成为“市场”应用程序
  3. 应用程序需要一个自定义配置文件,用文本等对其进行自定义,这对每次安装都可能不同。 (配置文件需要在相同的位置具有相同名称)
  4. 在应用程序启动时的配置文件被读取和配置应用程序根据配置文件中

本质上的数据,这将是一个配置应用程序的方式,以便它根据配置文件呈现特定的外观和感觉,而无需重新编译。能够加载自定义图像文件,文本数据等。

问题是,配置文件需要轻松更新并“复制”到没有SD卡的非根设备。因此,我需要访问可通过USB连接轻松访问的非应用程序特定位置,并且该APK可以在运行时访问。看来SharedPreferences和Android文件IO仅限于/ data/data/pkg/...下的私人应用程序目录或外部存储。任何想法将不胜感激。谢谢。

回答

0

只是想我会更新至少部分答案。至少我的一些问题与我的Razr Maxx的调试模式下的测试有关。当我通过USB调试连接时,创建新文件的调用失败,如下所示:

06-06 10:04:30.512:W/System.err(2583):java.io.IOException:打开失败: EACCES(拒绝) 10月6日至6日:04:305.12:W/System.err的(2583):在java.io.File.createNewFile(File.java:940)

当我运行的应用程序的独立在我的设备或模拟器上,然后它按预期工作。不确定这是否与Razr Maxx或其他问题有关?

我的代码工作是(来源:Write a file in external storage in Android):

private void writeToSDFile(){ 

    // Find the root of the external storage. 
    // See http://developer.android.com/guide/topics/data/data- storage.html#filesExternal 

    File root = android.os.Environment.getExternalStorageDirectory(); 
    mStatusTV.append("\nExternal file system root: "+root); 

    // See https://stackoverflow.com/questions/3551821/android-write-to-sd-card-folder 

    File dir = new File (root.getAbsolutePath() + "/download"); 
    dir.mkdirs(); 
    File file = new File(dir, "myData.txt"); 


    try { 
     file.createNewFile(); 

     FileOutputStream f = new FileOutputStream(file); 
     PrintWriter pw = new PrintWriter(f); 
     pw.println("Hi , How are you"); 
     pw.println("Hello"); 
     pw.flush(); 
     pw.close(); 
     f.close(); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
     Log.i(TAG, "******* File not found. Did you" + 
       " add a WRITE_EXTERNAL_STORAGE permission to the manifest?"); 
     mStatusTV.append("Write File 1: " + e.getMessage()); 
    } catch (IOException e) { 
     e.printStackTrace(); 
     mStatusTV.append("Write File 2: " + e.getMessage()); 
    } 
    mStatusTV.append("\n\nFile written to "+file); 
}