- 浏览: 53414 次
- 性别:
- 来自: 武汉
最新评论
-
Stark_Summer:
很好 顶顶
android 面试题经典 -
fff32165:
LZ好牛啊!膜拜ing
activity与service的交互
import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.net.Uri.Builder; import java.io.File; import android.content.Intent;
//自定义android Intent类, //可用于获取打开以下文件的intent //PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO
示例:
//这个不行,可能是因为PDF.apk程序没有权限访问其它APK里的asset资源文件,又或者是路径写错? //Intent it = getPdfFileIntent("file:///android_asset/helphelp.pdf"); //下面这些都OK //Intent it = getHtmlFileIntent("/mnt/sdcard/tutorial.html");//SD卡主目录 //Intent it = getHtmlFileIntent("/sdcard/tutorial.html");//SD卡主目录,这样也可以 Intent it = getHtmlFileIntent("/system/etc/tutorial.html");//系统内部的etc目录 //Intent it = getPdfFileIntent("/system/etc/helphelp.pdf"); //Intent it = getWordFileIntent("/system/etc/help.doc"); //Intent it = getExcelFileIntent("/mnt/sdcard/Book1.xls") //Intent it = getPptFileIntent("/mnt/sdcard/download/Android_PPT.ppt");//SD卡的download目录下 //Intent it = getVideoFileIntent("/mnt/sdcard/ice.avi"); //Intent it = getAudioFileIntent("/mnt/sdcard/ren.mp3"); //Intent it = getImageFileIntent("/mnt/sdcard/images/001041580.jpg"); //Intent it = getTextFileIntent("/mnt/sdcard/hello.txt",false);
startActivity( it );
public class MyIntent {
//android获取一个用于打开HTML文件的intent public static Intent getHtmlFileIntent( String param ) { Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build(); Intent intent = new Intent("android.intent.action.VIEW"); intent.setDataAndType(uri, "text/html"); return intent; }
//android获取一个用于打开图片文件的intent public static Intent getImageFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "image/*"); return intent; }
//android获取一个用于打开PDF文件的intent public static Intent getPdfFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/pdf"); return intent; }
//android获取一个用于打开文本文件的intent public static Intent getTextFileIntent( String param, boolean paramBoolean)
{
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (paramBoolean)
{
Uri uri1 = Uri.parse(param );
intent.setDataAndType(uri1, "text/plain");
}
else
{
Uri uri2 = Uri.fromFile(new File(param ));
intent.setDataAndType(uri2, "text/plain");
}
return intent;
}
//android获取一个用于打开音频文件的intent public static Intent getAudioFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("oneshot", 0); intent.putExtra("configchange", 0); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "audio/*"); return intent; }
//android获取一个用于打开视频文件的intent public static Intent getVideoFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("oneshot", 0); intent.putExtra("configchange", 0); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "video/*"); return intent; }
//android获取一个用于打开CHM文件的intent public static Intent getChmFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/x-chm"); return intent; }
//android获取一个用于打开Word文件的intent public static Intent getWordFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/msword"); return intent; }
//android获取一个用于打开Excel文件的intent public static Intent getExcelFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/vnd.ms-excel"); return intent; }
//android获取一个用于打开PPT文件的intent public static Intent getPptFileIntent( String param ) { Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); Uri uri = Uri.fromFile(new File(param )); intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); return intent; }
} |
发表评论
-
hydra框架中js与java互调原理
2019-06-10 17:18 0本文档主要阐述hydra框架中js与java是如何实现相互 ... -
自定义gradle插件
2019-09-02 11:25 3541.Gradle插件 Gradle可以认为是一个框 ... -
Rxjava2使用
2019-04-24 17:46 0Rxjava是一个基于观察者模式,通过可观察对象发送数据流 ... -
android NDK cmake
2019-04-19 16:00 0CMake是一个跨平台的安 ... -
504 Unsatisfiable Request 问题解决
2019-04-15 11:09 0问题出现背景及描述:在业务中使用Retrofit2网络工具库进 ... -
adb 命令操作
2019-04-11 16:46 0解决ANR还得需要trace.txt ... -
Android Framework之常用类介绍
2012-05-17 09:10 0WindowManagerService 窗口调度服务 ... -
application私有文件访问
2012-05-16 23:13 0首先内部存储路径为/data/data/youPackageN ... -
BroadcastReceiver的使用
2011-12-15 09:47 790使用广播接收器有两种方法,一种是建立一个BroadcastRe ... -
android:gravity 与 layout_gravity的区别
2011-10-27 16:04 660android:gravity 本view内部信息的排列方式对 ... -
activity与service的交互
2011-07-31 13:16 1528Activity访问service有两种方式,第一种是通过Ib ... -
Android源码学习之六——ActivityManager框架解析
2011-07-06 22:46 908ActivityManager在操作系统中有重要的作用,本文利 ... -
Android Application Task Activities的关系
2011-07-05 22:11 777什么是Android Application ... -
Android的PackageManager和ActivityManager的功能简介
2011-07-05 21:56 943Android系统为应用管理功能提供了大量的API。根据功能的 ... -
Android 对话框(Dialog)大全
2011-06-30 20:38 720Android 对话框(Dialog)大全 建立你自己的对 ... -
android 开发环境搭建
2011-06-19 15:15 7011.jdk安装及环境变量配置 以jdk1.4 ... -
[Android]正确地访问网络资源----Proxy的使用
2011-05-27 15:15 2455天朝有很多独特的东西,今天要涉及到的是CMWAP与CMNET。 ... -
指定浏览器访问指定页面(支持UC、Opera、QQ、Dolphin、Skyfire、Steel、Google)
2011-05-27 14:32 1282/*先看一下系统浏览器com.android.browser ... -
android:webView总结
2011-05-27 10:02 1086在Android手机中内置了一款高性能webkit内核浏览器, ... -
android 发送短信
2011-05-25 17:56 745要使用手机短信服务,在AndroidManifest.xml中 ...
相关推荐
android用于打开各种文件的intent.pdf
android用于打开各种文件的intent.docx
//android获取一个用于打开HTML文件的intent public static Intent getHtmlFileIntent( String param ) { Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme...
本文实例讲述了Android实现打开各种文件的intent方法。分享给大家供大家参考,具体如下: import android.app.Activity; import Android.content.Intent; import android.net.Uri; import android.net.Uri.Builder;...
它提供了易于使用的Dart API,可用于启动各种Android活动您可以查看/创建文档从文档树中选择文档打开默认的辅助活动执行网页搜索请求将特定字符串的定义发送给默认辅助活动打开图像进行编辑/查看分享文字/多媒体到...
一个Android文件管理器APP源码,类似于360手机助手的功能,可以记录文件使用次数,... 本SD卡扫描程序还自定义了android Intent类,可用于获取打开以下文件的intent:PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO。
Android 的 App Market 模式,软件开发者获得 7 成收入, 3 成用于系统维护。难点在于位置营销。 设备商通过卖设备、内置特色应用来获得盈利。也可以兼职专业软件开发者进行赢利。 Google 自身通过基于统一平台为...
是一个轻量级的开发包,用于实现 Android 上的异步任务和操作 UI 元素,可让 Android 应用开发更加简单、容易,更有趣。 16、Android-Universal-Image-Loader 为了实现异步的网络图片加载,支持多线程异步加载。 ...
android大作业-安卓音乐播放器+源代码+文档说明+演示视频 ...项目里包含了登陆注册的实现、音乐的识别播放暂停等功能、数据库的创建及使用...下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。
基于Android Studio的一个医疗系统,安卓期末大作业... 主要有以下几个模块: ...下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 -------- ----------------------------
打开 Android 设备上的终端模拟器,在里面依次运行命令: su setprop service.adb.tcp.port 5555 找到 Android 设备的 IP 地址。 一般能在「设置」-「关于手机」-「状态信息」-「IP地址」找到,也可以使用下文里 ...
布局比较简单,MainActviivty的布局文件只有两个按钮,一个是读取图库的,另一个是打开摄像头的,另外ResultActivity的布局只有一个ImageView,用于显示所选择的图片或者所拍摄的图片。 二、读取图库 由于需要打开...
- 使用Android内置Intent系统从assets目录打开pdf文件。 - 使用活动助手模式。 该应用程序有一个 14 的最小 sdk 版本(冰淇淋三明治,但如果你想支持旧版本,只需添加 ActionBarSherlock,一切都会像魅力一样工作...
<项目介绍> - 基于Android Studio的一个医疗系统,安卓期末大作业... 主要有以下几个模块: Login and Register ...下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 --------
android计步器的实现,自定义的一个弧形进度条,记步通过手机的传感器来实现,也就是说不支持传感器的机子(应该很老的了吧)就没有效果。看看效果图: 这里写图片描述这里写图片描述 自定义View public class ...
现在一般的android软件都是需要不断更新的,当你打开某个app的时候,如果有新的版本,它会提示你有新版本需要更新。该小程序实现的就是这个功能。 该小程序的特点是,当有更新时,会弹出一个提示框,点击确定,则在...
Android的Intent.ACTION_GET_CONTENT Windows Windows.Storage.Pickers 需要Android 5.0以上版本和iOS 10以上版本 安装 npm i --save react-native-document-picker OR yarn add react-native-document-picker ...