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

27次阅读

共计 1578 个字符,预计需要花费 4 分钟才能阅读完成。

最近做一个在 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
 }
 }
});

正文完
 0