将资产移动到 /data/data/APP_NAME/files
快速参考我所读过的内容 http://thedevelopersinfo.com/2009/11/17/using- Android 中的资产/
http://www.wiseandroid .com/post/2010/06/14/Android-Beginners-Intro-to-Resources-and-Assets.aspx
还有更多,但作为新手只能发帖2.
在我的应用程序中,有一个按钮,如果用户决定在 root 设备上执行此操作,则将重新启动到引导加载程序。我有一个名为“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 后,“文件”中没有显示任何内容,“文件甚至也没有显示。
Quick reference on what I have read
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
There are more but as a newb can only post 2.
In my app there is a button the will a reboot into the bootloader if the user decides to do so on rooted devices. I have a reboot binary called "reboot" that will allow the commmand to run and it is in /assets/. Using the methods above I can not seem to get "reboot" to move or even create the directory "files" in /data/data/ of my apk. My question is, is there a better guide to school me in the subject or are these the best and I am just to thick headed to understand it. Or if you have some other sample codes I can read through and try and understand would be perfect. Thank you.
Added sample of what I am doing
$ 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();
Upon running the apk nothing shows up in the "Files" nor does "Files even show up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
doug,
看起来您的“outFileName”将不包含一个好的文件名。
尝试使用 getExternalFilesDir() 获取 SDRAM 的路径。
请参阅: http://developer.android .com/reference/android/content/Context.html#getExternalFilesDir%28java.lang.String%29
编辑...
doug,这是我
使用它的实现,请执行以下操作:
doug,
it looks like your "outFileName" won't contain a good filename.
Try using getExternalFilesDir() to obtain a path to SDRAM.
see: http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir%28java.lang.String%29
EDIT...
doug, this is my implementation
to use it, do this: