第十一篇- 实现APK打开文件功能
MainActivity.java
package com.example.aimee.aimeetest3; import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu; import java.io.File;
import java.util.Locale; public class MainActivity extends AppCompatActivity {
private static final String[][] MIME_MapTable={
//{后缀名,MIME类型}
{"txt","text/plain"},
{"xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}
}; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} private void openFile(File file){
Intent intent=new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type=getMIMEType(file);
intent.setDataAndType(Uri.fromFile(file),type);
startActivity(intent);
}
private String getMIMEType(File file){
String type="*/*";
String fName=file.getName();
int dotIndex=fName.lastIndexOf(".");
if(dotIndex<0){
return type;
}
String end=file.getName().substring(dotIndex+1,fName.length()).toLowerCase(Locale.getDefault());
if(end.equals(""))
return type;
for(int i=0;i<MIME_MapTable.length;i++){
if(end.equals(MIME_MapTable[i][0]))
type=MIME_MapTable[i][1];
}
return type;
}
}
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aimee.aimeetest3"> <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content"/>
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application> </manifest>
第十一篇- 实现APK打开文件功能的更多相关文章
- iOS 用其他应用程序打开文件功能
先摘抄一段我抄别人用的. <key>CFBundleDocumentTypes</key> <array> <dict> ...
- android无后缀二进制执行文件替代apk实现程序功能
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha android无后缀二进制执行文件替代apk实现程序功能 实现将data/Android ...
- UWP入门(十一)--使用选取器打开文件和文件夹
原文:UWP入门(十一)--使用选取器打开文件和文件夹 很漂亮的功能,很有趣 重要的 API FileOpenPicker FolderPicker StorageFile 通过让用户与选取器交互来访 ...
- Python基础【第十一篇】文件操作(file()、open()方法和fileinput模块)
一.file/open 内置函数 file函数的方法: 注:file 和 open的用法和功能相同这里只对file进行分析 file(‘filename’,’mode’) file(‘filename ...
- APK扩展文件介绍、功能及用法
APK扩展文件介绍 Android Market (Google Play Store)中每一个APK文件的最大限制是50MB.假设您的程序中包括大量的数据文件,曾经您仅仅能把这些数据文件放到自己的s ...
- 任意文件夹下打开cmd功能的设置(win10)
win10中打开cmd的方法: 1."运行"中输入CMD打开,也可以按住win+R 2.选择命令行工具中"开始-->>所有应用-->>Window ...
- 关闭vscode打开新文件自动关闭预览文件功能
经常碰到这个问题,我打开文件就是有用的,每次给我自动关闭了我还得去打开. 当然这个问题可以双击文件,接触那个文件的预览状态就可以解决了.不过还有一个更懒的方法,直接修改vscode配置就好了. // ...
- python学习之【第十一篇】:Python中的文件操作
1.前言 在Python中,对文件的操作主要遵循以下流程: 打开文件,得到文件句柄并赋值给一个变量 通过文件句柄对文件进行操作 关闭文件 2.打开文件 使用open函数,可以打开一个已经存在的文件,或 ...
- 第十一篇 SQL Server代理维护计划
本篇文章是SQL Server代理系列的第十一篇,详细内容请参考原文 在这一系列的上一篇,我们看了使用代理帐户模仿Windows安全上下文完成作业步骤的工作.大多数子系统支持代理账户,同时子系统限制代 ...
随机推荐
- 我和我的小伙伴们都惊呆了!基于Canvas的第三方库Three.js
What is Three.js three + js 表示运行在浏览器上的3D程序 javascript的计算能力因为google的V8引擎得到了迅猛提升 做服务器都没问题了 更别说3D了 哈哈 ...
- python try except else finally
python try except else finally 实例 class AError(Exception): """AError---exception&quo ...
- Python——Flask框架——Web表单
一.框架Flask-WTF 安装: pip install flask-wtf 需要程序设置一个密钥 app = Flask(__name__) app.config['SECRET_KEY'] = ...
- Lodop打印控件 打印‘接下一页’‘以下空白’
Lodop打印控件中,超文本超过设置的打印项高度 或超过纸张,就会自动分页,纯文本通过设置为多页项也可以根据打印项高度自动分页,Lodop中还提供了许多手动分页的方法,对于多页文档中(自动分页或手动分 ...
- 11.ingress服务
kubernetes 的service服务我们提到过.service 可以用nodePort的方式和调用公有云LBAAS服务 来对于集群外的client提供服务访问,但是service是工作的osi ...
- User Authentication with Angular and ASP.NET Core
User authentication is a fundamental part of any meaningful application. Unfortunately, implementing ...
- spring 在容器中一个bean依赖另一个bean 需要通过ref方式注入进去 通过构造器 或property
spring 在容器中一个bean依赖另一个bean 需要通过ref方式注入进去 通过构造器 或property
- windows 动态库的封装以及调用
1.一个程序从源文件编译生成可执行文件的步骤:预编译 --> 编译 --> 汇编 --> 链接(1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开.处 ...
- Idea中JavaWeb项目部署
1. 添加应用服务器tomcat 2. 将tomcat配置添加到项目中 artifacts配置:添加deploy, 添加artifacts,选择Web Application: Exploded &g ...
- robotframework测试用例加入注释
*** Variables ***${HOST} 192.168.132.135${USER} username*** Test Cases ***Simple [Documentation] Sim ...