Android word /excel/ppt 显示
来源:互联网 发布:淘宝返红包怎么用 编辑:程序博客网 时间:2024/05/18 02:35
点击某个ListView中的某个Item,就从网上下载并打开某个word/excel/ppt
说明:url为资源的网络地址
public class xianshi extends BaseActivity{private ProgressDialog mProgressDialog; // 下载成功 public static final int DOWNLOAD_ERROR = 7; // 下载失败 public static final int DOWNLOAD_SUCCESS = 6; @Override protected void onCreate(Bundle arg0) { // TODO Auto-generated method stub super.onCreate(arg0); initView(); } private void initView() { // TODO Auto-generated method stub Intent intent = act.getIntent(); final String Strname = intent.getStringExtra("docurl"); mProgressDialog = new ProgressDialog(act); mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); mProgressDialog.show(); final File file1 = new File( Environment.getExternalStorageDirectory(), getFileName("office" + ".doc")); new Thread() { public void run() { File downloadfile = downLoad(Strname,file1.getAbsolutePath(),mProgressDialog); Message msg = Message.obtain(); if (downloadfile != null) { // 下载成功,安装.... msg.obj = downloadfile; msg.what = DOWNLOAD_SUCCESS; } else { // 提示用户下载失败. msg.what = DOWNLOAD_ERROR; } handler.sendMessage(msg); mProgressDialog.dismiss(); }; }.start(); } Handler handler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case DOWNLOAD_SUCCESS: File file = (File) msg.obj; Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive"); startActivity(intent); break; case DOWNLOAD_ERROR: break; default: break; } } }; public static File downLoad(String serverpath, String savedfilepath, ProgressDialog pd) { try { URL url = new URL(serverpath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); if (conn.getResponseCode() == 200) { int max = conn.getContentLength(); pd.setMax(max); InputStream is = conn.getInputStream(); File file = new File(savedfilepath); if (file.exists()) { return file; } FileOutputStream fos = new FileOutputStream(file); int len = 0; byte[] buffer = new byte[1024]; int total = 0; while ((len = is.read(buffer)) != -1) { fos.write(buffer, 0, len); total += len; pd.setProgress(total); } fos.flush(); fos.close(); is.close(); return file; } else { return null; } } catch (Exception e) { e.printStackTrace(); return null; } } public static String getFileName(String serverurl) { return serverurl.substring(serverurl.lastIndexOf("/") + 1); } }
FR:海涛高软(QQ技术群:386476712)
1 0
- Android word /excel/ppt 显示
- Android上展示word、excel、pdf、ppt~
- Word Excel PPT
- Winform中显示Office文档(word,EXCEL,PPT)
- Winform中显示Office文档(word,EXCEL,PPT)
- android打开pdf ppt word excel等文件
- Android应用内展示word、excel、pdf、ppt等文件
- POI pdf ppt word excel
- word、excel、PPT快捷键一览
- Intent打开ppt、word、Excel
- unity打开Excel/Word/PPT
- Word.Excel.ppt转html
- 浏览器预览Excel、PPT、Word
- excel、word和ppt使用
- Word Excel PPT在线预览
- 采用jacob读取并在网页中显示ppt、word、excel
- office新建word excel ppt时,图标显示异常的问题
- office 中解决ppt图标显示不正常问题(word,excel正常)
- 创建并排的框
- eclipse build path功能总结
- Android----让你的状态栏变色-----沉浸式状态栏解决方案
- Android文件(File)操作
- Rotate实现围绕中心旋转动画
- Android word /excel/ppt 显示
- <转>整合Kafka到Spark Streaming——代码示例和挑战
- Oracle INSERT 语句
- 二进制mysql2.7.16下载地址及安装步骤
- ioc和aop
- Android中HttpURLConnection与HttpClient的使用与封装
- ReactNative安装的点点滴滴
- recyclerview的notifyDataSetChang不刷新问题(转载)
- HTTP Status 500 - java.lang.IllegalStateException: No output folder