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); 

 
}
原创粉丝点击