关于javascript:APICloudApp开发中加入系统分享功能案例源码分享

最近做一个在app中退出零碎分享的性能,分享一下本人踩坑的记录和成绩。

安卓能够退出零碎相册和文件管理器的分享菜单中,iOS目前只做到了退出在其余利用里调起零碎分享的菜单,零碎相册还有一些问题没有解决,欢送各位开发者指出,一起学习。

1.Android先配置config.xml ,iOS先配置Info.plist

//config.xml: android.intent.action.SEND你app承受的单文件,mimeType是文件格式,能够本人去参考安卓官网查问

<intent-filter> 
 <action name="android.intent.action.SEND"/> 
 <category name="android.intent.category.DEFAULT"/> 
 <data mimeType="image/*" path="/"/> 
</intent-filter>
<intent-filter> 
 <action name="android.intent.action.SEND_MULTIPLE"/> 
 <category name="android.intent.category.DEFAULT"/> 
 <data mimeType="image/*" path="/"/> 
</intent-filter>

//Info.plist:记得肯定要配置CFBundleTypeName字段,之前因为上架不配置此字段包无奈上传,同理 LSItemContentTypes 是你app反对的文件类型。

<key>CFBundleDocumentTypes</key>
<array>
 <key>CFBundleTypeName</key>
 <string>A6026753217901</string>
 <key>LSItemContentTypes</key>
 <array>
 <string>com.microsoft.word.doc</string>
 </array>
</array>

2.监听利用被其余利用调起

api.addEventListener({
 name : 'appintent'
 }, function(ret, err) {
 if(api.systemType === 'android'){

//点击零碎分享菜单分享到本人app时,这里监听返回的参数是content://格局的,这个就是零碎传过来的门路,不能间接应用,须要原生Uri对象转换
//不会原生本人封装模块的,我这边曾经封装好了fileScan模块的streamToAbsolutePath

 if(appParam['android.intent.extra.STREAM']){

//大家仔细观察下这个返回的参数,不像数组,两头还有个暗藏的空格字符,所以这里须要手动转换下,去掉中括号,去空格,转成以逗号分隔的模式。

 var endPath =appParam['android.intent.extra.STREAM'].replace(/[|]/g,'')
 var filePath =filePath.replace(/s+/g,'')
 var fileScan =api.require('fileScan')
 var param ={
 streamPath:filePath
 }
 fileScan.streamToAbsolutePath(param,function(ret,err){

//这里就曾经胜利拿到绝对路径了

 alert(JSON.stringify(ret.data))
 })
 }
 }
 if(api.systemType === 'ios'){

//ios能够间接返回绝对路径,这里不做多说

 if(ret.iosUrl&&ret.iosUrl.indexOf('/') === 0){

//拿到文件绝对路径

 var filePath =ret.iosUrl
 }
 }
});

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理