Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
ShareExtend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李增强
ShareExtend
Commits
4e42bd9e
Commit
4e42bd9e
authored
Jan 21, 2020
by
zhouteng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add share panel title for android and subject for both android and ios
parent
c339e7be
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
19 deletions
+34
-19
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
...d/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
+13
-9
example/lib/main.dart
example/lib/main.dart
+6
-2
ios/Classes/ShareExtendPlugin.m
ios/Classes/ShareExtendPlugin.m
+6
-4
lib/share_extend.dart
lib/share_extend.dart
+9
-4
No files found.
android/src/main/java/com/zt/shareextend/ShareExtendPlugin.java
View file @
4e42bd9e
...
...
@@ -30,6 +30,8 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
private
final
Registrar
mRegistrar
;
private
List
<
String
>
list
;
private
String
type
;
private
String
sharePanelTitle
;
private
String
subject
;
public
static
void
registerWith
(
Registrar
registrar
)
{
MethodChannel
channel
=
new
MethodChannel
(
registrar
.
messenger
(),
CHANNEL
);
...
...
@@ -50,22 +52,24 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
throw
new
IllegalArgumentException
(
"Map argument expected"
);
}
// Android does not support showing the share sheet at a particular point on screen.
share
((
List
)
call
.
argument
(
"list"
),
(
String
)
call
.
argument
(
"type"
));
list
=
call
.
argument
(
"list"
);
type
=
call
.
argument
(
"type"
);
sharePanelTitle
=
call
.
argument
(
"sharePanelTitle"
);
subject
=
call
.
argument
(
"subject"
);
share
(
list
,
type
,
sharePanelTitle
,
subject
);
result
.
success
(
null
);
}
else
{
result
.
notImplemented
();
}
}
private
void
share
(
List
<
String
>
list
,
String
type
)
{
private
void
share
(
List
<
String
>
list
,
String
type
,
String
sharePanelTitle
,
String
subject
)
{
if
(
list
==
null
||
list
.
isEmpty
())
{
throw
new
IllegalArgumentException
(
"Non-empty list expected"
);
}
this
.
list
=
list
;
this
.
type
=
type
;
Intent
shareIntent
=
new
Intent
();
shareIntent
.
addFlags
(
Intent
.
FLAG_GRANT_READ_URI_PERMISSION
);
shareIntent
.
putExtra
(
Intent
.
EXTRA_SUBJECT
,
subject
);
if
(
"text"
.
equals
(
type
))
{
shareIntent
.
setAction
(
Intent
.
ACTION_SEND
);
...
...
@@ -101,11 +105,11 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
shareIntent
.
putParcelableArrayListExtra
(
Intent
.
EXTRA_STREAM
,
uriList
);
}
}
startChooserActivity
(
shareIntent
);
startChooserActivity
(
shareIntent
,
sharePanelTitle
);
}
private
void
startChooserActivity
(
Intent
shareIntent
)
{
Intent
chooserIntent
=
Intent
.
createChooser
(
shareIntent
,
null
/* dialog title
optional */
);
private
void
startChooserActivity
(
Intent
shareIntent
,
String
sharePanelTitle
)
{
Intent
chooserIntent
=
Intent
.
createChooser
(
shareIntent
,
sharePanelTitle
/* dialog subject
optional */
);
if
(
mRegistrar
.
activity
()
!=
null
)
{
mRegistrar
.
activity
().
startActivity
(
chooserIntent
);
}
else
{
...
...
@@ -126,7 +130,7 @@ public class ShareExtendPlugin implements MethodChannel.MethodCallHandler, Plugi
@Override
public
boolean
onRequestPermissionsResult
(
int
requestCode
,
String
[]
perms
,
int
[]
grantResults
)
{
if
(
requestCode
==
CODE_ASK_PERMISSION
&&
grantResults
.
length
>
0
&&
grantResults
[
0
]
==
PackageManager
.
PERMISSION_GRANTED
)
{
share
(
list
,
type
);
share
(
list
,
type
,
sharePanelTitle
,
subject
);
}
return
false
;
}
...
...
example/lib/main.dart
View file @
4e42bd9e
...
...
@@ -35,7 +35,9 @@ class _MyAppState extends State<MyApp> {
children:
<
Widget
>[
RaisedButton
(
onPressed:
()
{
ShareExtend
.
share
(
"share text"
,
"text"
);
ShareExtend
.
share
(
"share text"
,
"text"
,
sharePanelTitle:
"share text title"
,
subject:
"share text subject"
);
},
child:
Text
(
"share text"
),
),
...
...
@@ -44,7 +46,9 @@ class _MyAppState extends State<MyApp> {
File
f
=
await
ImagePicker
.
pickImage
(
source
:
ImageSource
.
gallery
);
if
(
f
!=
null
)
{
ShareExtend
.
share
(
f
.
path
,
"image"
);
ShareExtend
.
share
(
f
.
path
,
"image"
,
sharePanelTitle:
"share image title"
,
subject:
"share image subject"
);
}
},
child:
Text
(
"share image"
),
...
...
ios/Classes/ShareExtendPlugin.m
View file @
4e42bd9e
...
...
@@ -12,6 +12,7 @@
NSDictionary
*
arguments
=
[
call
arguments
];
NSArray
*
array
=
arguments
[
@"list"
];
NSString
*
shareType
=
arguments
[
@"type"
];
NSString
*
subject
=
arguments
[
@"subject"
];
if
(
array
.
count
==
0
)
{
result
(
...
...
@@ -31,7 +32,7 @@
}
if
([
shareType
isEqualToString
:
@"text"
])
{
[
self
share
:
array
atSource
:
originRect
];
[
self
share
:
array
atSource
:
originRect
withSubject
:
subject
];
result
(
nil
);
}
else
if
([
shareType
isEqualToString
:
@"image"
])
{
NSMutableArray
*
imageArray
=
[[
NSMutableArray
alloc
]
init
];
...
...
@@ -39,14 +40,14 @@
UIImage
*
image
=
[
UIImage
imageWithContentsOfFile
:
path
];
[
imageArray
addObject
:
image
];
}
[
self
share
:
imageArray
atSource
:
originRect
];
[
self
share
:
imageArray
atSource
:
originRect
withSubject
:
subject
];
}
else
{
NSMutableArray
*
urlArray
=
[[
NSMutableArray
alloc
]
init
];
for
(
NSString
*
path
in
array
)
{
NSURL
*
url
=
[
NSURL
fileURLWithPath
:
path
];
[
urlArray
addObject
:
url
];
}
[
self
share
:
urlArray
atSource
:
originRect
];
[
self
share
:
urlArray
atSource
:
originRect
withSubject
:
subject
];
result
(
nil
);
}
}
else
{
...
...
@@ -55,7 +56,7 @@
}];
}
+
(
void
)
share
:(
NSArray
*
)
sharedItems
atSource
:(
CGRect
)
origin
{
+
(
void
)
share
:(
NSArray
*
)
sharedItems
atSource
:(
CGRect
)
origin
withSubject
:(
NSString
*
)
subject
{
UIActivityViewController
*
activityViewController
=
[[
UIActivityViewController
alloc
]
initWithActivityItems
:
sharedItems
applicationActivities
:
nil
];
UIViewController
*
controller
=
[
UIApplication
sharedApplication
].
keyWindow
.
rootViewController
;
...
...
@@ -64,6 +65,7 @@
if
(
!
CGRectIsEmpty
(
origin
))
{
activityViewController
.
popoverPresentationController
.
sourceRect
=
origin
;
}
[
activityViewController
setValue
:
subject
forKey
:
@"subject"
];
[
controller
presentViewController
:
activityViewController
animated
:
YES
completion
:
nil
];
}
...
...
lib/share_extend.dart
View file @
4e42bd9e
...
...
@@ -21,11 +21,14 @@ class ShareExtend {
}
static
Future
<
void
>
share
(
String
text
,
String
type
,
{
Rect
sharePositionOrigin
})
{
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
=
""
})
{
assert
(
text
!=
null
);
assert
(
text
.
isNotEmpty
);
List
<
String
>
list
=
[
text
];
return
_shareInner
(
list
,
type
,
sharePositionOrigin:
sharePositionOrigin
);
return
_shareInner
(
list
,
type
,
sharePositionOrigin:
sharePositionOrigin
,
sharePanelTitle:
sharePanelTitle
,
subject:
subject
);
}
/// method to share with system ui
...
...
@@ -36,11 +39,13 @@ class ShareExtend {
/// [sharePositionOrigin] only supports ios
///
static
Future
<
void
>
_shareInner
(
List
<
String
>
list
,
String
type
,
{
Rect
sharePositionOrigin
})
{
{
Rect
sharePositionOrigin
,
String
sharePanelTitle
,
String
subject
})
{
assert
(
list
!=
null
&&
list
.
isNotEmpty
);
final
Map
<
String
,
dynamic
>
params
=
<
String
,
dynamic
>{
'list'
:
list
,
'type'
:
type
'type'
:
type
,
'sharePanelTitle'
:
sharePanelTitle
,
'subject'
:
subject
};
if
(
sharePositionOrigin
!=
null
)
{
params
[
'originX'
]
=
sharePositionOrigin
.
left
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment