Last active
November 21, 2018 23:32
-
-
Save lukeduncan-scot/9e8f7f380e72d32fd9cbc022e78e26fb to your computer and use it in GitHub Desktop.
Activity that loads a URL into a WebView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| package="***"> | |
| // This is required | |
| <uses-permission android:name="android.permission.INTERNET"/> | |
| <application | |
| android:allowBackup="true" | |
| android:icon="@mipmap/ic_launcher" | |
| android:label="@string/app_name" | |
| android:roundIcon="@mipmap/ic_launcher_round" | |
| android:supportsRtl="true" | |
| android:theme="@style/AppTheme"> | |
| <activity android:name=".MainActivity"> | |
| <intent-filter> | |
| <action android:name="android.intent.action.MAIN"/> | |
| <category android:name="android.intent.category.LAUNCHER"/> | |
| </intent-filter> | |
| </activity> | |
| <activity android:name=".WebActivity"/> | |
| </application> | |
| </manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class WebActivity extends AppCompatActivity { | |
| private static final String KEY_URL = WebActivity.class.getSimpleName() + "_URL"; | |
| public static Intent createIntent(Context context, URL url) { | |
| return new Intent(context, WebActivity.class) | |
| .putExtra(KEY_URL, url); | |
| } | |
| @Override | |
| protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_web); | |
| WebView webView = findViewById(R.id.webView); | |
| // Keep this line if you want to open in your app, otherwise it opens in Chrome | |
| webView.setWebViewClient(new WebViewClient()); | |
| final URL url = (URL) getIntent().getSerializableExtra(KEY_URL); | |
| webView.loadUrl(url.toString()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment