第十一篇- 实现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安全上下文完成作业步骤的工作.大多数子系统支持代理账户,同时子系统限制代 ...
随机推荐
- Linux用户权限指令, 定时任务等指令
一. 网卡配置详解 网络配置文件: /etc/sysconfig/network 网络接口配置文件: /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NA ...
- 如何抓取电商的数据 & Python
如何抓取电商的数据 & Python https://www.zhihu.com/question/40720286 https://www.zhihu.com/question/382455 ...
- vs code安装
vs code是一款文本编辑器,开源,是前端界的vs,而Dreamweaver适合入门. user版本的一些系统分区文件夹无法创建,可能存在语言显示问题.一般用户建议使用system版. 下载链接:h ...
- 11.ingress服务
kubernetes 的service服务我们提到过.service 可以用nodePort的方式和调用公有云LBAAS服务 来对于集群外的client提供服务访问,但是service是工作的osi ...
- MySQL数据库安装配置
1,下载MySQL 打开MySQL的官网www.mysql.com,发现有一个DOWNLOADS 点击它,进入到MySQL的下载页面,在页面的底部有一个MySQL Community Edition, ...
- .net core 2.0 数据访问-迁移
将用于进行迁移的 Entity Framework Core NuGet包 添加到`.csproj`文件 <ItemGroup> <DotNetCliToolReference In ...
- java Builder模式创建不可变类
package com.geostar.gfstack.operationcenter.logger.manager.common; /** * Created by Nihaorz on 2017/ ...
- ng-click 发两次ajax请求的原因及解决方法
http://blog.csdn.net/anmo/article/details/17083125
- BZOJ2142礼物——扩展卢卡斯
题目描述 一年一度的圣诞节快要来到了.每年的圣诞节小E都会收到许多礼物,当然他也会送出许多礼物.不同的人物在小E 心目中的重要性不同,在小E心中分量越重的人,收到的礼物会越多.小E从商店中购买了n件礼 ...
- Codeforces Round #445 Div. 1
A:每次看是否有能走回去的房间,显然最多只会存在一个,如果有走过去即可,否则开辟新房间并记录访问时间. #include<iostream> #include<cstdio> ...