Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
742dfbef
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
742dfbef
编写于
10月 22, 2020
作者:
C
chunhtai
提交者:
GitHub
10月 22, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support uri intent launcher in android (#21275)
* support uri intent launcher in android * fix comment
上级
3d27fd5b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
83 addition
and
11 deletion
+83
-11
shell/platform/android/io/flutter/embedding/android/FlutterActivity.java
...android/io/flutter/embedding/android/FlutterActivity.java
+8
-3
shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java
...embedding/android/FlutterActivityAndFragmentDelegate.java
+21
-5
shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java
...io/flutter/embedding/android/FlutterFragmentActivity.java
+8
-3
shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java
...dding/android/FlutterActivityAndFragmentDelegateTest.java
+46
-0
未找到文件。
shell/platform/android/io/flutter/embedding/android/FlutterActivity.java
浏览文件 @
742dfbef
...
...
@@ -774,13 +774,18 @@ public class FlutterActivity extends Activity
*
* If both preferences are set, the {@code Intent} preference takes priority.
*
* <p>If none is set, the {@link FlutterActivityAndFragmentDelegate} retrieves the initial route
* from the {@code Intent} through the Intent.getData() instead.
*
* <p>The reason that a {@code <meta-data>} preference is supported is because this {@code
* Activity} might be the very first {@code Activity} launched, which means the developer won't
* have control over the incoming {@code Intent}.
*
* <p>Subclasses may override this method to directly control the initial route.
*
* <p>If this method returns null, the {@link FlutterActivityAndFragmentDelegate} retrieves the
* initial route from the {@code Intent} through the Intent.getData() instead.
*/
@NonNull
public
String
getInitialRoute
()
{
if
(
getIntent
().
hasExtra
(
EXTRA_INITIAL_ROUTE
))
{
return
getIntent
().
getStringExtra
(
EXTRA_INITIAL_ROUTE
);
...
...
@@ -792,9 +797,9 @@ public class FlutterActivity extends Activity
Bundle
metadata
=
activityInfo
.
metaData
;
String
desiredInitialRoute
=
metadata
!=
null
?
metadata
.
getString
(
INITIAL_ROUTE_META_DATA_KEY
)
:
null
;
return
desiredInitialRoute
!=
null
?
desiredInitialRoute
:
DEFAULT_INITIAL_ROUTE
;
return
desiredInitialRoute
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
return
DEFAULT_INITIAL_ROUTE
;
return
null
;
}
}
...
...
shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java
浏览文件 @
742dfbef
...
...
@@ -9,6 +9,7 @@ import static android.content.ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.view.LayoutInflater
;
...
...
@@ -362,18 +363,21 @@ import java.util.Arrays;
// So this is expected behavior in many cases.
return
;
}
String
initialRoute
=
host
.
getInitialRoute
();
if
(
initialRoute
==
null
)
{
initialRoute
=
getInitialRouteFromIntent
(
host
.
getActivity
().
getIntent
());
}
Log
.
v
(
TAG
,
"Executing Dart entrypoint: "
+
host
.
getDartEntrypointFunctionName
()
+
", and sending initial route: "
+
host
.
getInitialRoute
()
);
+
initialRoute
);
// The engine needs to receive the Flutter app's initial route before executing any
// Dart code to ensure that the initial route arrives in time to be applied.
if
(
host
.
getInitialRoute
()
!=
null
)
{
flutterEngine
.
getNavigationChannel
().
setInitialRoute
(
host
.
getInitialRoute
()
);
if
(
initialRoute
!=
null
)
{
flutterEngine
.
getNavigationChannel
().
setInitialRoute
(
initialRoute
);
}
String
appBundlePathOverride
=
host
.
getAppBundlePath
();
...
...
@@ -388,6 +392,14 @@ import java.util.Arrays;
flutterEngine
.
getDartExecutor
().
executeDartEntrypoint
(
entrypoint
);
}
private
String
getInitialRouteFromIntent
(
Intent
intent
)
{
Uri
data
=
intent
.
getData
();
if
(
data
!=
null
&&
!
data
.
toString
().
isEmpty
())
{
return
data
.
toString
();
}
return
null
;
}
/**
* Invoke this from {@code Activity#onResume()} or {@code Fragment#onResume()}.
*
...
...
@@ -622,8 +634,12 @@ import java.util.Arrays;
void
onNewIntent
(
@NonNull
Intent
intent
)
{
ensureAlive
();
if
(
flutterEngine
!=
null
)
{
Log
.
v
(
TAG
,
"Forwarding onNewIntent() to FlutterEngine."
);
Log
.
v
(
TAG
,
"Forwarding onNewIntent() to FlutterEngine
and sending pushRoute message
."
);
flutterEngine
.
getActivityControlSurface
().
onNewIntent
(
intent
);
String
initialRoute
=
getInitialRouteFromIntent
(
intent
);
if
(
initialRoute
!=
null
&&
!
initialRoute
.
isEmpty
())
{
flutterEngine
.
getNavigationChannel
().
pushRoute
(
initialRoute
);
}
}
else
{
Log
.
w
(
TAG
,
"onNewIntent() invoked before FlutterFragment was attached to an Activity."
);
}
...
...
shell/platform/android/io/flutter/embedding/android/FlutterFragmentActivity.java
浏览文件 @
742dfbef
...
...
@@ -646,13 +646,18 @@ public class FlutterFragmentActivity extends FragmentActivity
*
* If both preferences are set, the {@code Intent} preference takes priority.
*
* <p>If none is set, the {@link FlutterActivityAndFragmentDelegate} retrieves the initial route
* from the {@code Intent} through the Intent.getData() instead.
*
* <p>The reason that a {@code <meta-data>} preference is supported is because this {@code
* Activity} might be the very first {@code Activity} launched, which means the developer won't
* have control over the incoming {@code Intent}.
*
* <p>Subclasses may override this method to directly control the initial route.
*
* <p>If this method returns null, the {@link FlutterActivityAndFragmentDelegate} retrieves the
* initial route from the {@code Intent} through the Intent.getData() instead.
*/
@NonNull
protected
String
getInitialRoute
()
{
if
(
getIntent
().
hasExtra
(
EXTRA_INITIAL_ROUTE
))
{
return
getIntent
().
getStringExtra
(
EXTRA_INITIAL_ROUTE
);
...
...
@@ -664,9 +669,9 @@ public class FlutterFragmentActivity extends FragmentActivity
Bundle
metadata
=
activityInfo
.
metaData
;
String
desiredInitialRoute
=
metadata
!=
null
?
metadata
.
getString
(
INITIAL_ROUTE_META_DATA_KEY
)
:
null
;
return
desiredInitialRoute
!=
null
?
desiredInitialRoute
:
DEFAULT_INITIAL_ROUTE
;
return
desiredInitialRoute
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
return
DEFAULT_INITIAL_ROUTE
;
return
null
;
}
}
...
...
shell/platform/android/test/io/flutter/embedding/android/FlutterActivityAndFragmentDelegateTest.java
浏览文件 @
742dfbef
...
...
@@ -15,6 +15,7 @@ import static org.mockito.Mockito.when;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.net.Uri
;
import
androidx.annotation.NonNull
;
import
androidx.lifecycle.Lifecycle
;
import
io.flutter.FlutterInjector
;
...
...
@@ -43,6 +44,7 @@ import org.junit.runner.RunWith;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.RuntimeEnvironment
;
import
org.robolectric.android.controller.ActivityController
;
import
org.robolectric.annotation.Config
;
@Config
(
manifest
=
Config
.
NONE
)
...
...
@@ -426,6 +428,50 @@ public class FlutterActivityAndFragmentDelegateTest {
.
onRequestPermissionsResult
(
any
(
Integer
.
class
),
any
(
String
[].
class
),
any
(
int
[].
class
));
}
@Test
public
void
itSendsInitialRouteFromIntentOnStartIfnoInitialRouteFromActivity
()
{
Intent
intent
=
FlutterActivity
.
createDefaultIntent
(
RuntimeEnvironment
.
application
);
intent
.
setData
(
Uri
.
parse
(
"http://myApp/custom/route"
));
ActivityController
<
FlutterActivity
>
activityController
=
Robolectric
.
buildActivity
(
FlutterActivity
.
class
,
intent
);
FlutterActivity
flutterActivity
=
activityController
.
get
();
when
(
mockHost
.
getActivity
()).
thenReturn
(
flutterActivity
);
when
(
mockHost
.
getInitialRoute
()).
thenReturn
(
null
);
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate
delegate
=
new
FlutterActivityAndFragmentDelegate
(
mockHost
);
// --- Execute the behavior under test ---
// The FlutterEngine is setup in onAttach().
delegate
.
onAttach
(
RuntimeEnvironment
.
application
);
// Emulate app start.
delegate
.
onStart
();
// Verify that the navigation channel was given the initial route message.
verify
(
mockFlutterEngine
.
getNavigationChannel
(),
times
(
1
))
.
setInitialRoute
(
"http://myApp/custom/route"
);
}
@Test
public
void
itSendsPushRouteMessageWhenOnNewIntent
()
{
// Create the real object that we're testing.
FlutterActivityAndFragmentDelegate
delegate
=
new
FlutterActivityAndFragmentDelegate
(
mockHost
);
// --- Execute the behavior under test ---
// The FlutterEngine is setup in onAttach().
delegate
.
onAttach
(
RuntimeEnvironment
.
application
);
Intent
mockIntent
=
mock
(
Intent
.
class
);
when
(
mockIntent
.
getData
()).
thenReturn
(
Uri
.
parse
(
"http://myApp/custom/route"
));
// Emulate the host and call the method that we expect to be forwarded.
delegate
.
onNewIntent
(
mockIntent
);
// Verify that the navigation channel was given the push route message.
verify
(
mockFlutterEngine
.
getNavigationChannel
(),
times
(
1
))
.
pushRoute
(
"http://myApp/custom/route"
);
}
@Test
public
void
itForwardsOnNewIntentToFlutterEngine
()
{
// Create the real object that we're testing.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录