1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
android:usesCleartextTraffic="true" package="io.dcloud.uni_modules.xShareS">
|
||||
<meta-data android:name="ScopedStorage" android:value="true" />
|
||||
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "21"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import Context from "android.content.Context";
|
||||
import Build from 'android.os.Build'
|
||||
import Uri from 'android.net.Uri';
|
||||
import Intent from 'android.content.Intent';
|
||||
import ContentResolver from 'android.content.ContentResolver'
|
||||
import FileProvider from 'androidx.core.content.FileProvider'
|
||||
import File from 'java.io.File';
|
||||
import Files from 'android.provider.MediaStore.Files';
|
||||
import InputStream from 'java.io.InputStream'
|
||||
import FileOutputStream from 'java.io.FileOutputStream'
|
||||
import MimeTypeMap from 'android.webkit.MimeTypeMap'
|
||||
import OpenableColumns from 'android.provider.OpenableColumns'
|
||||
import R from 'io.dcloud.uni_modules.xShareS.R'
|
||||
|
||||
|
||||
/**
|
||||
* title:分享的标题
|
||||
* minType:分享的内容格式
|
||||
* 文本:text/plain
|
||||
* 图片:image/*
|
||||
* 音频: audio/*
|
||||
* 视频: video/*
|
||||
* 任意文件: *//* ,注意不要//,只要单个/就行。编译器无法注释单个/
|
||||
*
|
||||
*/
|
||||
export function xShare(title : string, minType : string, content ?: string, path ?: string) {
|
||||
const context = UTSAndroid.getAppContext()!
|
||||
if (minType == 'text/plain') {
|
||||
let action = new Intent()
|
||||
action.setAction(Intent.ACTION_SEND)
|
||||
action.setType('text/plain')
|
||||
if(content!=null){
|
||||
action.putExtra(Intent.EXTRA_TEXT, content!)
|
||||
}
|
||||
UTSAndroid.getUniActivity()!.startActivity(Intent.createChooser(action, title))
|
||||
} else {
|
||||
if (path == null || minType == '') {
|
||||
console.error("类型或者路径为空")
|
||||
return;
|
||||
}
|
||||
let realfilepath = UTSAndroid.convert2AbsFullPath(path)
|
||||
|
||||
let file = new File(realfilepath)
|
||||
let action = new Intent()
|
||||
action.setAction(Intent.ACTION_SEND)
|
||||
action.setType(minType)
|
||||
let contentUri = FileProvider.getUriForFile(context, "xShareS.FileProvider", file);
|
||||
action.putExtra(Intent.EXTRA_STREAM, contentUri);
|
||||
UTSAndroid.getUniActivity()!.startActivity(Intent.createChooser(action, title))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-cache-path name="externalCachePath" path="." />
|
||||
<root-path name="apps" path="." />
|
||||
</paths>
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"x_library_s": "./lib/x_library_s.har"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { x_share } from "x_library_s";
|
||||
|
||||
/**
|
||||
* title:分享的标题
|
||||
* minType:分享的内容格式
|
||||
* 文本:text/plain
|
||||
* 图片:image/*
|
||||
* 音频: audio/*
|
||||
* 视频: video/*
|
||||
* 任意文件: *//* ,注意不要//,只要单个/就行。编译器无法注释单个/
|
||||
*
|
||||
*/
|
||||
export function xShare(title : string, minType : string, content ?: string, path ?: string) {
|
||||
const context = UTSHarmony.getCurrentWindow()!.getUIContext();
|
||||
x_share(context,{
|
||||
minType,
|
||||
title,
|
||||
content:content??"",
|
||||
path:path??""
|
||||
} as UTSJSONObject)
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "12"
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { UIActivity , UIActivityViewController , UIImage } from 'UIKit';
|
||||
import { CGRect } from 'CoreFoundation';
|
||||
import { URL , FileManager } from 'Foundation';
|
||||
/**
|
||||
* ios端如何要分享文本和图片之外的文件,可能需要对应的目标应用sdk,比如微信需要微信的sdk
|
||||
* 但很多应用不需要,比如我分享个pdf文件,大多应用是可以接收,但微信不行,必须要人家的sdk
|
||||
* 图片不需要,可以给任何应用
|
||||
* 文本不能微信,但其它应用可以,比如记事本,备忘录等等。
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* title:分享的标题
|
||||
* minType:分享的内容格式
|
||||
* 文本:text/plain
|
||||
* 图片:image/*
|
||||
* 音频: audio/*
|
||||
* 视频: video/*
|
||||
* 任意文件: *//* ,注意不要//,只要单个/就行。编译器无法注释单个/
|
||||
*
|
||||
*/
|
||||
export function xShare(title : string, minType : string, content ?: string, path ?: string) {
|
||||
let items = [] as any[];
|
||||
if(minType=='text/plain'){
|
||||
items = [content];
|
||||
}else if(minType=='image/*'&&path!=null){
|
||||
items = [new UIImage(contentsOfFile = path!)]
|
||||
}else{
|
||||
let pfh = path! as string;
|
||||
let filepath = UTSiOS.convert2AbsFullPath(pfh)
|
||||
let dataURL = new URL(fileURLWithPath = filepath)
|
||||
let data = UTSiOS.try(new Data(contentsOf = dataURL),"?")
|
||||
if(data==null) return;
|
||||
// items = [FileManager.default.contents(atPath =path!),new URL.init(fileURLWithPath=pfh)]
|
||||
items = [data,new URL.init(fileURLWithPath=filepath)]
|
||||
}
|
||||
DispatchQueue.main.async(execute=():void => {
|
||||
let activityViewController =new UIActivityViewController(activityItems = items,applicationActivities = nil)
|
||||
UTSiOS.getCurrentViewController().present(activityViewController, animated = true, completion = () => {
|
||||
console.log('分享成功。')
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user