feat(browser): 支持外部应用调用传入网页地址
- 在 AndroidManifest.xml 为 MainActivity 添加 http/https 的 intent-filter - 设置 singleTask 启动模式以复用 Activity 实例 - BrowserFragment 新增 MSG_OPEN_URL 消息处理外部 URL 跳转 - MainActivity 实现 handleExternalUrl 方法,在 onCreate/onNewIntent 中捕获并加载网页
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Wed May 06 11:08:36 CST 2026
|
||||
#Wed May 06 11:16:28 CST 2026
|
||||
stageCount=27
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.26
|
||||
buildCount=16
|
||||
buildCount=18
|
||||
baseBetaVersion=15.11.27
|
||||
|
||||
@@ -37,7 +37,16 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true">
|
||||
android:exported="true"
|
||||
android:launchMode="singleTask">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="http"/>
|
||||
<data android:scheme="https"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cc.winboll.studio.winboll;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -44,6 +45,25 @@ public class MainActivity extends DrawerFragmentActivity {
|
||||
addFragment(mBrowserFragment);
|
||||
}
|
||||
showFragment(mBrowserFragment);
|
||||
handleExternalUrl(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
handleExternalUrl(intent);
|
||||
}
|
||||
|
||||
private void handleExternalUrl(Intent intent) {
|
||||
if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||
Uri uri = intent.getData();
|
||||
if (uri != null && mBrowserFragment != null && mBrowserFragment.getBrowserHandler() != null) {
|
||||
Message msg = Message.obtain();
|
||||
msg.what = BrowserFragment.MSG_OPEN_URL;
|
||||
msg.obj = uri.toString();
|
||||
mBrowserFragment.getBrowserHandler().sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendMessage(Message msg) {
|
||||
|
||||
@@ -44,7 +44,9 @@ public class BrowserFragment extends Fragment implements View.OnClickListener, W
|
||||
// 消息标识:跳转首页(winboll.cc)
|
||||
public static final int MSG_HOMEPAGE = 1001;
|
||||
// 跳转到历史记录位置
|
||||
public static final int MSG_HISTORY_POSITION = 1002;
|
||||
public static final int MSG_HISTORY_POSITION = 1002;
|
||||
// 打开外部应用传入的 URL
|
||||
public static final int MSG_OPEN_URL = 1003;
|
||||
// 自定义Handler(接收应用内其他页面发送的消息)
|
||||
private Handler mBrowserHandler;
|
||||
|
||||
@@ -148,6 +150,13 @@ public class BrowserFragment extends Fragment implements View.OnClickListener, W
|
||||
//showToast("已跳转至" + historyUrl);
|
||||
}
|
||||
break;
|
||||
case MSG_OPEN_URL:
|
||||
String openUrl = (String) msg.obj;
|
||||
if (openUrl != null && !openUrl.isEmpty()) {
|
||||
mWinBoLLView.loadUrlSafe(openUrl);
|
||||
mEtUrl.setText(openUrl);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user