Skip to content

Commit 5b63ed9

Browse files
committed
added intent receiver
1 parent f2aaeb6 commit 5b63ed9

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ I know, using a Wrapper-App to display a Website can feel a bit odd. But there a
2828
- Add your own _ic_appbar.png_ in the `drawables` folders. This is displayed in Android's _Recent Apps_ View on your app bar, so it should look nicely when placed on top of your primary color.
2929
- I recommend using [Android Asset Studio](https://romannurik.github.io/AndroidAssetStudio) to get the icons ready in no time
3030
- Change the package name in `app/build.gradle`, *applicationId*
31+
- Change `AndroidManifest.xml` -> `aplication` -> `activity` -> `intent-filter` to your own URLs/schemes/patterns/etc. or remove the `intent-filter` for `android.intent.action.VIEW` altogether
3132
- Check `Constants.java` for more options
3233
- Build App in Android Studio
3334

app/src/main/AndroidManifest.xml

+21
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@
2424
<action android:name="android.intent.action.MAIN" />
2525
<category android:name="android.intent.category.LAUNCHER" />
2626
</intent-filter>
27+
<intent-filter>
28+
<action android:name="android.intent.action.VIEW" />
29+
<category android:name="android.intent.category.DEFAULT" />
30+
<category android:name="android.intent.category.BROWSABLE" />
31+
<data
32+
android:host="leasingrechnen.at"
33+
android:pathPrefix="/"
34+
android:scheme="http" />
35+
<data
36+
android:host="www.leasingrechnen.at"
37+
android:pathPrefix="/"
38+
android:scheme="http" />
39+
<data
40+
android:host="leasingrechnen.at"
41+
android:pathPrefix="/"
42+
android:scheme="https" />
43+
<data
44+
android:host="www.leasingrechnen.at"
45+
android:pathPrefix="/"
46+
android:scheme="https" />
47+
</intent-filter>
2748
</activity>
2849

2950
<!--Support super wide screens-->

app/src/main/java/at/xtools/pwawrapper/Constants.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public class Constants {
44
public Constants(){}
55
// Root page
66
public static String WEBAPP_URL = "https://www.leasingrechnen.at/";
7-
7+
public static String WEBAPP_HOST = "leasingrechnen.at"; // used for checking Intent-URLs
8+
89
// User Agent tweaks
910
public static boolean POSTFIX_USER_AGENT = true; // set to true to append USER_AGENT_POSTFIX to user agent
1011
public static boolean OVERRIDE_USER_AGENT = false; // set to true to use USER_AGENT instead of default one

app/src/main/java/at/xtools/pwawrapper/MainActivity.java

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package at.xtools.pwawrapper;
22

3+
import android.content.Intent;
4+
import android.net.Uri;
35
import android.support.v7.app.AppCompatActivity;
46
import android.os.Bundle;
57

@@ -10,6 +12,7 @@ public class MainActivity extends AppCompatActivity {
1012
// Globals
1113
private UIManager uiManager;
1214
private WebViewHelper webViewHelper;
15+
private boolean intentHandled = false;
1316

1417
@Override
1518
protected void onCreate(Bundle savedInstanceState) {
@@ -26,8 +29,30 @@ protected void onCreate(Bundle savedInstanceState) {
2629
webViewHelper.setupWebView();
2730
uiManager.changeRecentAppsIcon();
2831

29-
// Load up the Web App
30-
webViewHelper.loadHome();
32+
// Check for Intents
33+
try {
34+
Intent i = getIntent();
35+
String intentAction = i.getAction();
36+
// Handle URLs opened in Browser
37+
if (!intentHandled && intentAction != null && intentAction.equals(Intent.ACTION_VIEW)){
38+
Uri intentUri = i.getData();
39+
String intentText = "";
40+
if (intentUri != null){
41+
intentText = intentUri.toString();
42+
}
43+
// Load up the URL specified in the Intent
44+
if (!intentText.equals("")) {
45+
intentHandled = true;
46+
webViewHelper.loadIntentUrl(intentText);
47+
}
48+
} else {
49+
// Load up the Web App
50+
webViewHelper.loadHome();
51+
}
52+
} catch (Exception e) {
53+
// Load up the Web App
54+
webViewHelper.loadHome();
55+
}
3156
}
3257

3358
@Override

app/src/main/java/at/xtools/pwawrapper/webview/WebViewHelper.java

+10
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,14 @@ public boolean goBack() {
243243
public void loadHome() {
244244
webView.loadUrl(Constants.WEBAPP_URL);
245245
}
246+
247+
// load URL from intent
248+
public void loadIntentUrl(String url) {
249+
if (!url.equals("") && url.contains(Constants.WEBAPP_HOST)) {
250+
webView.loadUrl(url);
251+
} else {
252+
// Fallback
253+
loadHome();
254+
}
255+
}
246256
}

0 commit comments

Comments
 (0)