我想将一个非常大的目录从我的应用程序的assets文件夹复制到第一次运行应用程序的数据文件夹.我怎么做?我已经尝试了一些例子,但没有任何效果,所以我没有任何东西.我的目标是Android 4.2.
谢谢,Yannik
我可以使用以下代码安装存储在SD卡上的apk文件:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/mnt/sdcard/downloads/Sample.apk")), "application/vnd.android.package-archive");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
如何安装存储在assets文件夹中的apk文件?可能吗?
我试图从android资源目录中的原始资源文件创建一个RandomAccessFile对象,但没有成功.
我只能从原始资源文件中获取输入流对象.
getResources().openRawResource(R.raw.file);
Run Code Online (Sandbox Code Playgroud)
是否可以从原始资产文件创建RandomAccessFile对象或者我是否需要坚持使用输入流?
我正在制作一个应用程序,我想在浏览器中打开一个本地html页面.我可以打开google.com.但是当我打开本地html文件时.但我得到以下错误
找不到请求文件.
以下是我的代码:
try
{
Intent i = new Intent(Intent.ACTION_VIEW);
File f=new File("file:///android_asset/www/trialhtml.html");
Uri uri = Uri.fromFile(f);
i.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
i.setData(uri);
startActivity(i);
}
catch(Exception e)
{
System.out.print(e.toString());
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Phonegap开发我的应用程序,所以我需要将CSS,JS,JS库,index.html打包到assets/www文件夹,以及
super.loadUrl("file:///android_asset/www/index.html",4000);
Run Code Online (Sandbox Code Playgroud)
但有没有办法更新我的CSS,JS,JS库,index.html而不更新我的应用程序(不是从商店或我们自己的服务器更新apk文件) - 这是因为我需要与本机和它(CSS/JS,index.html)可能需要更改.
声音愚蠢,但是有没有办法满足这个要求,iOS解决方案怎么样?
我从中读到:无法使用File API修改/ android_assets/www中的文件,无法从资产中获取文件对象
但是,我发现 资产中的副本文件为sdcard.
那么,我能以某种方式更新资产文件吗?或者这种愚蠢的方式(我不知道iOS解决方案):
1将其复制到sdcard
2更新css/js/index.html 3 super.loadUrl("/ mnt/sdcard/myapp/index.html",4000);
还有其他解决方案,THX?
我需要将文件从用户 sdcard 上的一个位置移动到 sdcard 上的另一个位置
目前我正在使用 File.renameTo
例如从 sdcard/test/one.txt 到 sdcard/test2/two.txt
一些用户报告文件移动功能不起作用。
我遇到了下面的链接:
那么将文件从 SD 卡上的一个目录移动到另一个目录的最佳方法是什么?
我的Android 4.0.4应用程序包含一个WebView,用户可以通过该视图查看资产目录中本地存储的多个页面.在页面中循环时,最终会触发以下错误并且应用程序崩溃:
这个问题似乎与这里报道的问题有关:
我使用了以下链接中给出的Memory Analyzer Tool插件说明来检查详细信息:
http://therockncoder.blogspot.ca/2012/09/fixing-android-memory-leak.html
结果显示如下(无法发布屏幕截图,因此文本必须执行):
MAT摘录
Class Name | Shallow Heap | Retained Heap | Percentage
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| | |
java.lang.Thread @ 0x40daa320 Thread-39775 Thread | 80 | 15,310,552 | 76.74%
|- byte[32768] @ 0x40d5a8d0 <!DOCTYPE html>.<html xml:lang="">.<head>. <title>Android Test-HTML5-480PX-Page 0</title>. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />. <meta name="viewport" content="width=360, height=480">. <!--. <meta name="viewport" co...| 32,784 | 32,784 | 0.16%
|- byte[32768] @ 0x40e25bb8 …Run Code Online (Sandbox Code Playgroud) 我正在检索这样的文件
String[] files = assetFiles.list("EngagiaDroid");
Run Code Online (Sandbox Code Playgroud)
我们如何知道它是文件还是目录?
我想遍历Assets文件夹中的目录,然后复制其所有内容。
我使用以下代码将特定目录及其内容复制到SD卡.该目录位于res/raw文件夹中.
以下是我使用的代码:
public class CopyActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
copyFilesToSdCard();
}
static String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
final static String TARGET_BASE_PATH = extStorageDirectory+"/Android/data/";
private void copyFilesToSdCard() {
copyFileOrDir("");
}
private void copyFileOrDir(String path) {
AssetManager assetManager = this.getAssets();
String assets[] = null;
try {
Log.i("tag", "copyFileOrDir() "+path);
assets = assetManager.list(path);
if (assets.length == 0) {
copyFile(path);
} else {
String fullPath = TARGET_BASE_PATH …Run Code Online (Sandbox Code Playgroud) java android filenotfoundexception android-assets android-layout
有一些例子,人们close()在finally写入文件时会调用它们,例如:
OutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(data);
out.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
但也有很多 更多的例子,包括Android官方文档,他们不这样做:
try {
OutputStream out = new FileOutputStream(file);
out.write(data);
out.close();
}
catch (IOException e) {
Log.e("Exception", "File write …Run Code Online (Sandbox Code Playgroud)