Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
Flutter Inappwebview
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
李增强
Flutter Inappwebview
Commits
f80bf887
Commit
f80bf887
authored
Nov 08, 2019
by
Lorenzo Pichilli
Committed by
GitHub
Nov 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #183 from crazecoder/master
handle choose file callback in android
parents
31dc73cf
e18e6910
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
32 deletions
+44
-32
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
...utter_inappbrowser/InAppWebView/InAppWebChromeClient.java
+44
-32
No files found.
android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebChromeClient.java
View file @
f80bf887
package
com.pichillilorenzo.flutter_inappbrowser.InAppWebView
;
package
com.pichillilorenzo.flutter_inappbrowser.InAppWebView
;
import
android.annotation.TargetApi
;
import
android.content.ActivityNotFoundException
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
...
@@ -33,7 +35,10 @@ import java.util.Map;
...
@@ -33,7 +35,10 @@ import java.util.Map;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.MethodChannel
;
import
io.flutter.plugin.common.PluginRegistry
;
import
io.flutter.plugin.common.PluginRegistry
;
public
class
InAppWebChromeClient
extends
WebChromeClient
{
import
static
android
.
app
.
Activity
.
RESULT_CANCELED
;
import
static
android
.
app
.
Activity
.
RESULT_OK
;
public
class
InAppWebChromeClient
extends
WebChromeClient
implements
PluginRegistry
.
ActivityResultListener
{
protected
static
final
String
LOG_TAG
=
"IABWebChromeClient"
;
protected
static
final
String
LOG_TAG
=
"IABWebChromeClient"
;
private
PluginRegistry
.
Registrar
registrar
;
private
PluginRegistry
.
Registrar
registrar
;
...
@@ -56,18 +61,18 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -56,18 +61,18 @@ public class InAppWebChromeClient extends WebChromeClient {
this
.
inAppBrowserActivity
=
(
InAppBrowserActivity
)
obj
;
this
.
inAppBrowserActivity
=
(
InAppBrowserActivity
)
obj
;
else
if
(
obj
instanceof
FlutterWebView
)
else
if
(
obj
instanceof
FlutterWebView
)
this
.
flutterWebView
=
(
FlutterWebView
)
obj
;
this
.
flutterWebView
=
(
FlutterWebView
)
obj
;
registrar
.
addActivityResultListener
(
this
);
}
}
public
Bitmap
getDefaultVideoPoster
()
public
Bitmap
getDefaultVideoPoster
()
{
{
if
(
mCustomView
==
null
)
{
if
(
mCustomView
==
null
)
{
return
null
;
return
null
;
}
}
return
BitmapFactory
.
decodeResource
(
this
.
registrar
.
activeContext
().
getResources
(),
2130837573
);
return
BitmapFactory
.
decodeResource
(
this
.
registrar
.
activeContext
().
getResources
(),
2130837573
);
}
}
public
void
onHideCustomView
()
public
void
onHideCustomView
()
{
{
View
decorView
=
this
.
registrar
.
activity
().
getWindow
().
getDecorView
();
View
decorView
=
this
.
registrar
.
activity
().
getWindow
().
getDecorView
();
((
FrameLayout
)
decorView
).
removeView
(
this
.
mCustomView
);
((
FrameLayout
)
decorView
).
removeView
(
this
.
mCustomView
);
this
.
mCustomView
=
null
;
this
.
mCustomView
=
null
;
...
@@ -77,10 +82,8 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -77,10 +82,8 @@ public class InAppWebChromeClient extends WebChromeClient {
this
.
mCustomViewCallback
=
null
;
this
.
mCustomViewCallback
=
null
;
}
}
public
void
onShowCustomView
(
View
paramView
,
WebChromeClient
.
CustomViewCallback
paramCustomViewCallback
)
public
void
onShowCustomView
(
View
paramView
,
WebChromeClient
.
CustomViewCallback
paramCustomViewCallback
)
{
{
if
(
this
.
mCustomView
!=
null
)
{
if
(
this
.
mCustomView
!=
null
)
{
onHideCustomView
();
onHideCustomView
();
return
;
return
;
}
}
...
@@ -343,7 +346,7 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -343,7 +346,7 @@ public class InAppWebChromeClient extends WebChromeClient {
LinearLayout
.
LayoutParams
.
MATCH_PARENT
);
LinearLayout
.
LayoutParams
.
MATCH_PARENT
);
input
.
setLayoutParams
(
lp
);
input
.
setLayoutParams
(
lp
);
layout
.
setPaddingRelative
(
45
,
15
,
45
,
0
);
layout
.
setPaddingRelative
(
45
,
15
,
45
,
0
);
layout
.
addView
(
input
);
layout
.
addView
(
input
);
String
alertMessage
=
(
responseMessage
!=
null
&&
!
responseMessage
.
isEmpty
())
?
responseMessage
:
message
;
String
alertMessage
=
(
responseMessage
!=
null
&&
!
responseMessage
.
isEmpty
())
?
responseMessage
:
message
;
...
@@ -392,8 +395,7 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -392,8 +395,7 @@ public class InAppWebChromeClient extends WebChromeClient {
}
}
@Override
@Override
public
boolean
onCreateWindow
(
WebView
view
,
boolean
dialog
,
boolean
userGesture
,
android
.
os
.
Message
resultMsg
)
public
boolean
onCreateWindow
(
WebView
view
,
boolean
dialog
,
boolean
userGesture
,
android
.
os
.
Message
resultMsg
)
{
{
WebView
.
HitTestResult
result
=
view
.
getHitTestResult
();
WebView
.
HitTestResult
result
=
view
.
getHitTestResult
();
String
data
=
result
.
getExtra
();
String
data
=
result
.
getExtra
();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
...
@@ -405,7 +407,7 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -405,7 +407,7 @@ public class InAppWebChromeClient extends WebChromeClient {
}
}
@Override
@Override
public
void
onGeolocationPermissionsShowPrompt
(
final
String
origin
,
final
GeolocationPermissions
.
Callback
callback
)
{
public
void
onGeolocationPermissionsShowPrompt
(
final
String
origin
,
final
GeolocationPermissions
.
Callback
callback
)
{
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
Map
<
String
,
Object
>
obj
=
new
HashMap
<>();
if
(
inAppBrowserActivity
!=
null
)
if
(
inAppBrowserActivity
!=
null
)
obj
.
put
(
"uuid"
,
inAppBrowserActivity
.
uuid
);
obj
.
put
(
"uuid"
,
inAppBrowserActivity
.
uuid
);
...
@@ -415,19 +417,19 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -415,19 +417,19 @@ public class InAppWebChromeClient extends WebChromeClient {
public
void
success
(
Object
o
)
{
public
void
success
(
Object
o
)
{
Map
<
String
,
Object
>
response
=
(
Map
<
String
,
Object
>)
o
;
Map
<
String
,
Object
>
response
=
(
Map
<
String
,
Object
>)
o
;
if
(
response
!=
null
)
if
(
response
!=
null
)
callback
.
invoke
((
String
)
response
.
get
(
"origin"
),
(
Boolean
)
response
.
get
(
"allow"
),
(
Boolean
)
response
.
get
(
"retain"
));
callback
.
invoke
((
String
)
response
.
get
(
"origin"
),
(
Boolean
)
response
.
get
(
"allow"
),
(
Boolean
)
response
.
get
(
"retain"
));
else
else
callback
.
invoke
(
origin
,
false
,
false
);
callback
.
invoke
(
origin
,
false
,
false
);
}
}
@Override
@Override
public
void
error
(
String
s
,
String
s1
,
Object
o
)
{
public
void
error
(
String
s
,
String
s1
,
Object
o
)
{
callback
.
invoke
(
origin
,
false
,
false
);
callback
.
invoke
(
origin
,
false
,
false
);
}
}
@Override
@Override
public
void
notImplemented
()
{
public
void
notImplemented
()
{
callback
.
invoke
(
origin
,
false
,
false
);
callback
.
invoke
(
origin
,
false
,
false
);
}
}
});
});
}
}
...
@@ -518,25 +520,35 @@ public class InAppWebChromeClient extends WebChromeClient {
...
@@ -518,25 +520,35 @@ public class InAppWebChromeClient extends WebChromeClient {
public
boolean
onShowFileChooser
(
public
boolean
onShowFileChooser
(
WebView
webView
,
ValueCallback
<
Uri
[]>
filePathCallback
,
WebView
webView
,
ValueCallback
<
Uri
[]>
filePathCallback
,
FileChooserParams
fileChooserParams
)
{
FileChooserParams
fileChooserParams
)
{
if
(
mUploadMessageArray
!=
null
)
{
mUploadMessageArray
.
onReceiveValue
(
null
);
}
mUploadMessageArray
=
filePathCallback
;
mUploadMessageArray
=
filePathCallback
;
try
{
Intent
contentSelectionIntent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
Intent
contentSelectionIntent
=
new
Intent
(
Intent
.
ACTION_GET_CONTENT
);
contentSelectionIntent
.
addCategory
(
Intent
.
CATEGORY_OPENABLE
);
contentSelectionIntent
.
addCategory
(
Intent
.
CATEGORY_OPENABLE
);
contentSelectionIntent
.
setType
(
"*/*"
);
contentSelectionIntent
.
setType
(
"*/*"
);
Intent
[]
intentArray
;
Intent
[]
intentArray
;
intentArray
=
new
Intent
[
0
];
intentArray
=
new
Intent
[
0
];
Intent
chooserIntent
=
new
Intent
(
Intent
.
ACTION_CHOOSER
);
Intent
chooserIntent
=
new
Intent
(
Intent
.
ACTION_CHOOSER
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_INTENT
,
contentSelectionIntent
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_INTENT
,
contentSelectionIntent
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_TITLE
,
"Image Chooser"
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_TITLE
,
"Image Chooser"
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_INITIAL_INTENTS
,
intentArray
);
chooserIntent
.
putExtra
(
Intent
.
EXTRA_INITIAL_INTENTS
,
intentArray
);
((
inAppBrowserActivity
!=
null
)
?
inAppBrowserActivity
:
flutterWebView
.
activity
).
startActivityForResult
(
chooserIntent
,
FILECHOOSER_RESULTCODE
);
((
inAppBrowserActivity
!=
null
)
?
inAppBrowserActivity
:
flutterWebView
.
activity
).
startActivityForResult
(
chooserIntent
,
FILECHOOSER_RESULTCODE
);
}
catch
(
ActivityNotFoundException
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
true
;
return
true
;
}
}
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
public
boolean
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
requestCode
==
FILECHOOSER_RESULTCODE
&&
(
resultCode
==
RESULT_OK
||
resultCode
==
RESULT_CANCELED
))
{
mUploadMessageArray
.
onReceiveValue
(
WebChromeClient
.
FileChooserParams
.
parseResult
(
resultCode
,
data
));
}
return
false
;
}
private
MethodChannel
getChannel
()
{
private
MethodChannel
getChannel
()
{
return
(
inAppBrowserActivity
!=
null
)
?
InAppBrowserFlutterPlugin
.
inAppBrowser
.
channel
:
flutterWebView
.
channel
;
return
(
inAppBrowserActivity
!=
null
)
?
InAppBrowserFlutterPlugin
.
inAppBrowser
.
channel
:
flutterWebView
.
channel
;
}
}
...
...
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