当我使用此代码时,我的phonegap应用程序没有响应/ timout窗口焦点问题/ appwindowtoken等。基本上,应用程序加载,但我有黑屏,一切都冻结。
也许我在主要活动中处理的很多。我正在尝试提取文件。
我该如何解决这个问题。
代码赞赏。提前感谢,
杰里米
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import org.apache.cordova.*;
public class tester extends DroidGap
{
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
super.loadUrl(Config.getStartUrl());
//super.loadUrl("file:///android_asset/www/index.html")
File extStore = Environment.getExternalStorageDirectory();
File file = new File(extStore.getAbsolutePath()+"/mysoundboard/com.test.dsoundfxboard/1.dat");
if(! file.exists())
{
boolean test = noiser.extractZip(extStore.getAbsolutePath()+"/mysoundboard/mydsoundfxboard.zip", extStore.getAbsolutePath()+"/mysoundboard/com.test.dsoundfxboard/");
FileOutputStream fOut = null;
OutputStreamWriter osw = null;
if(test == true)
{
try {
fOut openFileOutput(extStore.getAbsolutePath()+"/mysoundboard/com.test.dsoundfxboard/1.dat",MODE_WORLD_READABLE);
osw = new OutputStreamWriter(fOut);
osw.write('1');
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
osw.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
osw.close();
fOut.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
private static boolean extractZip(String pathOfZip,String pathToExtract)
{
int BUFFER_SIZE = 1024;
int size;
byte[] buffer = new byte[BUFFER_SIZE];
try {
File f = new File(pathToExtract);
if(!f.isDirectory()) {
f.mkdirs();
}
ZipInputStream zin = new ZipInputStream(new BufferedInputStream(new FileInputStream(pathOfZip), BUFFER_SIZE));
try {
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
String path = pathToExtract +"/"+ ze.getName();
if (ze.isDirectory()) {
File unzipFile = new File(path);
if(!unzipFile.isDirectory()) {
unzipFile.mkdirs();
}
}
else {
FileOutputStream out = new FileOutputStream(path, false);
BufferedOutputStream fout = new BufferedOutputStream(out, BUFFER_SIZE);
try {
while ( (size = zin.read(buffer, 0, BUFFER_SIZE)) != -1 ) {
fout.write(buffer, 0, size);
}
zin.closeEntry();
}catch (Exception e) {
Log.e("Exception", "Unzip exception 1:" + e.toString());
}
finally {
fout.flush();
fout.close();
}
}
}
}catch (Exception e) {
Log.e("Exception", "Unzip exception2 :" + e.toString());
}
finally {
zin.close();
}
return true;
}
catch (Exception e) {
Log.e("Exception", "Unzip exception :" + e.toString());
}
return false;
}
}