Skip to content

Commit 962b47b

Browse files
graycreateclaude
andcommitted
feat: improve Vshare WebView with intent URL support and status bar padding
This commit addresses two UX issues in the Vshare WebView: 1. **Intent URL Support**: Fixed handling of intent:// URLs (e.g., Google Play Store links) - Added handleUrlLoading() method to intercept and process special URL schemes - Supports intent://, market://, and other app-specific schemes (mailto:, tel:, etc.) - Includes fallback mechanisms for better user experience - Displays appropriate error messages when apps are not available 2. **Status Bar Padding**: Added paddingTop to prevent content from being hidden - Added android:fitsSystemWindows="true" to WebView - Ensures content is properly displayed below the status bar in edge-to-edge mode Changes made: - VshareWebActivity.java: Added URL scheme handling logic with comprehensive fallback support - activity_vshare_web.xml: Added fitsSystemWindows attribute to WebView 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent f0d1619 commit 962b47b

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package me.ghui.v2er.module.vshare;
22

33
import android.annotation.SuppressLint;
4+
import android.content.ActivityNotFoundException;
45
import android.content.Context;
56
import android.content.Intent;
67
import android.graphics.Bitmap;
8+
import android.net.Uri;
79
import android.os.Bundle;
10+
import android.util.Log;
811
import android.view.View;
912
import android.webkit.WebChromeClient;
1013
import android.webkit.WebResourceRequest;
1114
import android.webkit.WebSettings;
1215
import android.webkit.WebView;
1316
import android.webkit.WebViewClient;
1417
import android.widget.ProgressBar;
18+
import android.widget.Toast;
1519

1620
import androidx.appcompat.app.AppCompatActivity;
1721

@@ -26,6 +30,7 @@
2630
*/
2731
public class VshareWebActivity extends AppCompatActivity {
2832

33+
private static final String TAG = "VshareWebActivity";
2934
private static final String VSHARE_BASE_URL = "https://v2er.app/vshare";
3035

3136
@BindView(R.id.webview)
@@ -114,8 +119,12 @@ private void setupWebView() {
114119
mWebView.setWebViewClient(new WebViewClient() {
115120
@Override
116121
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
117-
// Let the WebView handle the navigation
118-
return false;
122+
return handleUrlLoading(request.getUrl().toString());
123+
}
124+
125+
@Override
126+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
127+
return handleUrlLoading(url);
119128
}
120129

121130
@Override
@@ -149,6 +158,88 @@ public void onProgressChanged(WebView view, int newProgress) {
149158
});
150159
}
151160

161+
/**
162+
* Handle URL loading for WebView
163+
* Returns true if the URL was handled externally, false if WebView should load it
164+
*/
165+
private boolean handleUrlLoading(String url) {
166+
if (url == null) {
167+
return false;
168+
}
169+
170+
Uri uri = Uri.parse(url);
171+
String scheme = uri.getScheme();
172+
173+
// Handle intent:// URLs (e.g., Google Play Store links)
174+
if ("intent".equals(scheme)) {
175+
try {
176+
Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
177+
178+
// Check if there's an app that can handle this intent
179+
if (getPackageManager().resolveActivity(intent, 0) != null) {
180+
startActivity(intent);
181+
return true;
182+
}
183+
184+
// Fallback: Try to open the browser_fallback_url if available
185+
String fallbackUrl = intent.getStringExtra("browser_fallback_url");
186+
if (fallbackUrl != null) {
187+
mWebView.loadUrl(fallbackUrl);
188+
return true;
189+
}
190+
191+
// Last resort: Try to open in Google Play if it's a Play Store intent
192+
String packageName = intent.getPackage();
193+
if (packageName != null) {
194+
Intent marketIntent = new Intent(Intent.ACTION_VIEW,
195+
Uri.parse("market://details?id=" + packageName));
196+
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
197+
if (getPackageManager().resolveActivity(marketIntent, 0) != null) {
198+
startActivity(marketIntent);
199+
return true;
200+
}
201+
}
202+
} catch (Exception e) {
203+
Log.e(TAG, "Error handling intent URL: " + url, e);
204+
Toast.makeText(this, "Unable to open app", Toast.LENGTH_SHORT).show();
205+
}
206+
return true;
207+
}
208+
209+
// Handle market:// URLs (Google Play Store)
210+
if ("market".equals(scheme)) {
211+
try {
212+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
213+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
214+
startActivity(intent);
215+
return true;
216+
} catch (ActivityNotFoundException e) {
217+
Log.e(TAG, "Google Play Store not found", e);
218+
// Fallback to web version
219+
String webUrl = url.replace("market://", "https://play.google.com/store/apps/");
220+
mWebView.loadUrl(webUrl);
221+
return true;
222+
}
223+
}
224+
225+
// Handle other app-specific schemes (e.g., mailto:, tel:, etc.)
226+
if (!"http".equals(scheme) && !"https".equals(scheme)) {
227+
try {
228+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
229+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
230+
startActivity(intent);
231+
return true;
232+
} catch (ActivityNotFoundException e) {
233+
Log.e(TAG, "No app found to handle scheme: " + scheme, e);
234+
Toast.makeText(this, "No app found to open this link", Toast.LENGTH_SHORT).show();
235+
return true;
236+
}
237+
}
238+
239+
// Let WebView handle normal http/https URLs
240+
return false;
241+
}
242+
152243
@Override
153244
public void onBackPressed() {
154245
// Handle back navigation in WebView

app/src/main/res/layout/activity_vshare_web.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
<WebView
88
android:id="@+id/webview"
99
android:layout_width="match_parent"
10-
android:layout_height="match_parent" />
10+
android:layout_height="match_parent"
11+
android:fitsSystemWindows="true" />
1112

1213
<ProgressBar
1314
android:id="@+id/progress_bar"

0 commit comments

Comments
 (0)