第十一篇- 实现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安全上下文完成作业步骤的工作.大多数子系统支持代理账户,同时子系统限制代 ...
随机推荐
- hive安装详解
1.安装MYSQL simon@simon-Lenovo-G400:~$ sudo apt-get install mysql-server simon@simon-Lenovo-G400:~$ su ...
- git连接到github
基本流程如图 如何配置SSH key:在gitBash里执行. 1.检查电脑上是否生成过了,如果已经生成了,则需要删除后再操作 cd ~ cd .ssh 提示:No such file or dire ...
- Redis五大数据类型
首先说明下,Redis是:单线程+多路IO复用技术!!! string set > key + zset list hash 常用的几个命令: >keys * 查 ...
- python易混易乱(2)
字符串切割成列表: 以str为分隔符切片mystr,如果maxsplit有指定值,则仅分割maxsplit个字符串,得到maxsplit个字符串的列表 利用字符串的split() 方法 >> ...
- Js返回上一页,刷新页面,定时刷新,改变地址栏 等常用实用技巧
1. Javascript 返回上一页history.go(-1), 返回两个页面: history.go(-2); 2. history.back(). 3. window.history.forw ...
- 【python练习题】程序17
#题目:输入一行字符,分别统计出其中英文字母.空格.数字和其它字符的个数. s = input('请输入字符串:') alf = 0 space = 0 digi = 0 other = 0 for ...
- React 学习(四) ---- 生命周期函数
现在我们能修改状态,页面可以进行交互了,但是还有一种状态改变没有解决,那就是倒计时效果,时间一直在变化,组件状态也一直在改变,但我们什么都没有做,如果要实现这样的效果,需要怎么处理? 我们都知道,改变 ...
- Ubuntu18.04安装RabbitMQ
Ubuntu18.04安装RabbitMQ 2018年06月10日 19:32:38 dmfrm 阅读数:2492 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- FFmpeg 将YUV数据转RGB
只要开始初始化一次,结束后释放就好,中间可以循环转码 AVFrame *m_pFrameRGB,*m_pFrameYUV; uint8_t *m_rgbBuffer,*m_yuvBuffer; str ...
- [51Nod 1584] 加权约数和
Description 在整理以前的试题时,他发现了这样一道题目:"求 \(\sum\sigma(i)\),其中 \(1≤i≤N\),\(σ(i)\) 表示 \(i\) 的约数之和.&quo ...