【发布时间】:2011-05-02 15:13:34
【问题描述】:
我所读内容的快速参考 http://thedevelopersinfo.com/2009/11/17/using-assets-in-android/
http://www.wiseandroid.com/post/2010/06/14/Android-Beginners-Intro-to-Resources-and-Assets.aspx
还有更多,但作为新手只能发2个。
在我的应用程序中有一个按钮,如果用户决定在有根设备上这样做,它将重新启动到引导加载程序。我有一个名为“reboot”的重启二进制文件,它将允许命令运行,它位于 /assets/ 中。使用上述方法,我似乎无法“重新启动”来移动甚至在我的 apk 的 /data/data/ 中创建目录“文件”。我的问题是,是否有更好的指导来指导我学习这门学科,或者这些是最好的,我只是头脑清醒地理解它。或者,如果您有其他一些示例代码,我可以通读并尝试理解将是完美的。谢谢。
添加了我在做什么的示例
$ public static String moveReboot = "/data/data/com.DPE.MuchSuck/Files";
public static String reboot = "file:///android_asset/reboot";
public static Context myContext;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
moveFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
$ public void moveFile() throws IOException {
AssetManager assetManager = getAssets();
InputStream myInput = assetManager.open(reboot);
String outFileName = moveReboot + reboot;
OutputStream myOutput = new FileOutputStream(outFileName);
byte[] buffer = new byte [1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
在运行 apk 时,“文件”中没有任何显示,“文件甚至没有显示。
【问题讨论】:
标签: android import device assets