Android Share 将图片或者文件分享到自己的APP 中
来源:互联网 发布:java物流管理项目描述 编辑:程序博客网 时间:2024/05/17 22:41
一般我们看到好看的图片或者文章时,就会将其分享到我们的微信朋友,或者朋友圈中,就像这样
这个呢,我们可以调用系统的分享,或者用第三方的SDK,如ShareSDK, 友盟都是可以的,但是,我们想要把文件分享到我们的APP 中呢。
一,我们需要在清单文件中进行一些信息配置,让它们可以检测到我们的APP。
<intent-filter android:label="@string/app_name" > <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="*/*" /> </intent-filter>
这个是任意的文件,没有指定文件类型。
PDF 文件
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="file" /> <data android:mimeType="*/*" /> <data android:pathPattern=".*\\.pdf" /> <data android:host="*" /> </intent-filter>
图片
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/jpeg" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/png" /> </intent-filter>
网址
<intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="text/html" /> </intent-filter>
二,接收数据
在起始的activity中做如下处理
Intent itnIn=getIntent(); Bundle extras = itnIn.getExtras(); String action = itnIn.getAction(); if (Intent.ACTION_SEND.equals(action)) { if (extras.containsKey(Intent.EXTRA_STREAM)) { try { // Get resource path from intent Uri uri2 = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);// 返回路径 String path = getRealPathFromURI(Activity_Logo_View.this, uri2); } catch (Exception e) { Log.e(this.getClass().getName(), e.toString()); }/** * 通过Uri获取文件在本地存储的真实路径 * @param act * @param contentUri * @return */ public String getRealPathFromURI(Activity act, Uri contentUri) {// can post image String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = act.managedQuery(contentUri, proj, // Which columns to return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) if (cursor==null) { String path = contentUri.getPath(); return path; } int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }
返回的path 就是我们需要的文件路径。
阅读全文
1 0
- Android Share 将图片或者文件分享到自己的APP 中
- 将图片和文件分享到自己的app中来
- Android | 将内容分享到自己的app
- android 将文件(图片,文本)保存到程序包名下自己建立的文件夹中
- android 关于将应用添加到系统的 分享.. 或者 发送到.. 中
- android 关于将应用添加到系统的 分享.. 或者 发送到.. 中
- android分享功能以及将自己的应用添加到分享列表中(2)
- 将自己的app加入到分享列表中,并适配锤子的one step功能
- 从其他APP分享图片到自己的APP指定界面内
- android中share文件
- Android -- 查询手机上所有的能分享图片或者文字的App packageName
- Android:添加自己的应用到“分享”->"发送文件"选项
- Android:添加自己的应用到“分享”->"发送文件"选项
- android中关于图片分享到QQ或者微信,朋友圈及其他(免SDK)
- 如何将自己的"本地连接"网络或者"无线网络"分享
- 将自己的网站分享到微信,qq,或者人人......
- android把自己的应用加入到系统分享中
- iOS App让自己的应用在其他应用中打开列表中显示、iOS把自己的应用添加到”活动“、将PDF文件Open In MyApp
- 记录篇 从零开始
- Python3 网络编程
- 点击RaidoGroup切换Fragment(Fragment中嵌套ViewPager)
- NSMutableDictionary操纵字典内容(Objective-C 开发范例)
- 模式开始第六天
- Android Share 将图片或者文件分享到自己的APP 中
- Django框架开发一个餐厅网站 架构
- 入门,入迷,行家,专家,大神
- Inconvertible types; cannot cast 'com.mplus.application.controller.serverPortTools.ServerPortToolsCo
- 乘法/除法与移位
- Centos 6.9搭建Hadoop分布式
- Java基础——虚拟机结构
- WhatWeb源码分析之lib/plugins.rb
- 微信小程序学习笔记(一)教程收集