pdf格式apk
来源:互联网 发布:辨别产品真假软件 编辑:程序博客网 时间:2024/05/17 22:46
package com.haipai.activity;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.FileUtils;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.webkit.WebView;
public class Specifications extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// WebView localWebView = new WebView(this);
// localWebView.getSettings().setJavaScriptEnabled(true);
// localWebView.loadUrl("file:///android_asset/Specifications.html");
// localWebView.getSettings().setSupportZoom(true);
// localWebView.getSettings().setBuiltInZoomControls(true);
// setContentView(localWebView);
String path0 = Environment.getExternalStorageDirectory().getAbsolutePath();
String path = "data/data/com.haipai.activity/databases/";
CopyAssets("pdf",path);
Intent localIntent = getPdfFileIntent(path+"/u879.pdf");
startActivity(localIntent);
finish();
}
public static Intent getPdfFileIntent(String paramString)
{
Intent localIntent1 = new Intent("android.intent.action.VIEW");
Intent localIntent2 = localIntent1.addCategory("android.intent.category.DEFAULT");
Intent localIntent3 = localIntent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri localUri = Uri.fromFile(new File(paramString));
Intent localIntent4 = localIntent1.setDataAndType(localUri, "application/pdf");
return localIntent1;
}
private void CopyAssets(String assetDir, String dir) {
String[] files;
try {
files = this.getResources().getAssets().list(assetDir);
} catch (IOException e1) {
return;
}
File mWorkingPath = new File(dir);
// if this directory does not exists, make one.
if (!mWorkingPath.exists()) {
if (!mWorkingPath.mkdirs()) {
}
}
for (int i = 0; i < files.length; i++) {
try {
String fileName = files[i];
// we make sure file name not contains '.' to be a folder.
if (!fileName.contains(".")) {
if (0 == assetDir.length()) {
CopyAssets(fileName, dir + fileName + "/");
} else {
CopyAssets(assetDir + "/" + fileName, dir + fileName
+ "/");
}
continue;
}
File outFile = new File(mWorkingPath, fileName);
if (outFile.exists())
outFile.delete();
InputStream in = null;
if (0 != assetDir.length()) {
in = getAssets().open(assetDir + "/" + fileName);
} else {
in = getAssets().open(fileName);
}
OutputStream out = new FileOutputStream(outFile);
setFilePermissionsFromMode(outFile.getPath(),MODE_WORLD_READABLE);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void setFilePermissionsFromMode(String name, int mode) {
int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
|FileUtils.S_IRGRP|FileUtils.S_IWGRP;
if ((mode&MODE_WORLD_READABLE) != 0) {
perms |= FileUtils.S_IROTH;
}
if ((mode&MODE_WORLD_WRITEABLE) != 0) {
perms |= FileUtils.S_IWOTH;
}
FileUtils.setPermissions(name, perms, -1, -1);
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.os.FileUtils;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.webkit.WebView;
public class Specifications extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// WebView localWebView = new WebView(this);
// localWebView.getSettings().setJavaScriptEnabled(true);
// localWebView.loadUrl("file:///android_asset/Specifications.html");
// localWebView.getSettings().setSupportZoom(true);
// localWebView.getSettings().setBuiltInZoomControls(true);
// setContentView(localWebView);
String path0 = Environment.getExternalStorageDirectory().getAbsolutePath();
String path = "data/data/com.haipai.activity/databases/";
CopyAssets("pdf",path);
Intent localIntent = getPdfFileIntent(path+"/u879.pdf");
startActivity(localIntent);
finish();
}
public static Intent getPdfFileIntent(String paramString)
{
Intent localIntent1 = new Intent("android.intent.action.VIEW");
Intent localIntent2 = localIntent1.addCategory("android.intent.category.DEFAULT");
Intent localIntent3 = localIntent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri localUri = Uri.fromFile(new File(paramString));
Intent localIntent4 = localIntent1.setDataAndType(localUri, "application/pdf");
return localIntent1;
}
private void CopyAssets(String assetDir, String dir) {
String[] files;
try {
files = this.getResources().getAssets().list(assetDir);
} catch (IOException e1) {
return;
}
File mWorkingPath = new File(dir);
// if this directory does not exists, make one.
if (!mWorkingPath.exists()) {
if (!mWorkingPath.mkdirs()) {
}
}
for (int i = 0; i < files.length; i++) {
try {
String fileName = files[i];
// we make sure file name not contains '.' to be a folder.
if (!fileName.contains(".")) {
if (0 == assetDir.length()) {
CopyAssets(fileName, dir + fileName + "/");
} else {
CopyAssets(assetDir + "/" + fileName, dir + fileName
+ "/");
}
continue;
}
File outFile = new File(mWorkingPath, fileName);
if (outFile.exists())
outFile.delete();
InputStream in = null;
if (0 != assetDir.length()) {
in = getAssets().open(assetDir + "/" + fileName);
} else {
in = getAssets().open(fileName);
}
OutputStream out = new FileOutputStream(outFile);
setFilePermissionsFromMode(outFile.getPath(),MODE_WORLD_READABLE);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void setFilePermissionsFromMode(String name, int mode) {
int perms = FileUtils.S_IRUSR|FileUtils.S_IWUSR
|FileUtils.S_IRGRP|FileUtils.S_IWGRP;
if ((mode&MODE_WORLD_READABLE) != 0) {
perms |= FileUtils.S_IROTH;
}
if ((mode&MODE_WORLD_WRITEABLE) != 0) {
perms |= FileUtils.S_IWOTH;
}
FileUtils.setPermissions(name, perms, -1, -1);
}
}
- pdf格式apk
- PDF 格式
- 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- word格式转pdf格式
- html格式转pdf格式
- PDF格式详解
- pdf格式转变
- jasperreport显示PDF格式
- PDF格式简单分析
- 制作pDF 格式电子书
- PDF格式详解
- pdg格式转pdf
- PDF - WORD 格式混乱
- PDF格式和工具
- PDF格式水很深
- word转换PDF格式
- proxy模式
- 《Java程序员上班那点事儿》自我小结1
- 【LeetCode OJ】Sum Root to Leaf Numbers
- !important
- 关于VS 2010 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏解决方案
- pdf格式apk
- chgrp命令
- hdu_2084数塔(动态规划--初步)
- dom4j修改xml
- 页面验证码
- chown命令
- 2014年仍会流行的HTML-CSS框架
- Webdriver学习笔记(二)浏览器的基本操作
- 第九周上机项目2:构造“菜单”。