-
Notifications
You must be signed in to change notification settings - Fork 559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android WebViews documentation update #904
Open
martinhorvath
wants to merge
7
commits into
apache:master
Choose a base branch
from
martinhorvath:patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6dc8836
Update webview.md
martinhorvath a22eff8
GH-884 android: Embedding Android WebView doc looks broken
martinhorvath 7110826
GH-884 android: Embedding Android WebView doc looks broken
martinhorvath 177b713
Update www/docs/en/dev/guide/platforms/android/webview.md
janpio 3445588
Update www/docs/en/dev/guide/platforms/android/webview.md
janpio 2a3aeba
Update www/docs/en/dev/guide/platforms/android/webview.md
janpio f390b41
Update www/docs/en/dev/guide/platforms/android/webview.md
janpio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,97 +38,56 @@ legacy `CordovaActivity` component that pre-dates the 1.9 release. | |
[cordova.apache.org](http://cordova.apache.org) and unzip its | ||
Android package. | ||
|
||
1. Navigate to the Android package's `/framework` directory and run | ||
`ant jar`. It creates the Cordova `.jar` file, formed as | ||
`/framework/cordova-x.x.x.jar`. | ||
|
||
1. Copy the `.jar` file into the Android project's `/libs` directory. | ||
|
||
1. Add the following to the application's `/res/xml/main.xml` file, | ||
with the `layout_height`, `layout_width` and `id` modified to suit | ||
the application: | ||
|
||
<org.apache.cordova.CordovaWebView | ||
android:id="@+id/tutorialView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
|
||
1. Modify the activity so that it implements the `CordovaInterface`. | ||
It should implement the included methods. You may wish to copy | ||
them from `/framework/src/org/apache/cordova/CordovaActivity.java`, | ||
or else implement them on your own. The following code fragment | ||
shows a basic application that relies on the interface. Note how | ||
the referenced view id matches the `id` attribute specified in the | ||
XML fragment shown above: | ||
|
||
public class CordovaViewTestActivity extends Activity implements CordovaInterface { | ||
CordovaWebView cwv; | ||
/* Called when the activity is first created. */ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.main); | ||
cwv = (CordovaWebView) findViewById(R.id.tutorialView); | ||
Config.init(this); | ||
cwv.loadUrl(Config.getStartUrl()); | ||
} | ||
|
||
1. If the application needs to use the camera, implement the | ||
following: | ||
|
||
@Override | ||
public void setActivityResultCallback(CordovaPlugin plugin) { | ||
this.activityResultCallback = plugin; | ||
} | ||
/** | ||
* Launch an activity for which you would like a result when it finished. When this activity exits, | ||
* your onActivityResult() method is called. | ||
* | ||
* @param command The command object | ||
* @param intent The intent to start | ||
* @param requestCode The request code that is passed to callback to identify the activity | ||
*/ | ||
public void startActivityForResult(CordovaPlugin command, Intent intent, int requestCode) { | ||
this.activityResultCallback = command; | ||
this.activityResultKeepRunning = this.keepRunning; | ||
|
||
// If multitasking turned on, then disable it for activities that return results | ||
if (command != null) { | ||
this.keepRunning = false; | ||
} | ||
|
||
// Start activity | ||
super.startActivityForResult(intent, requestCode); | ||
} | ||
|
||
@Override | ||
/** | ||
* Called when an activity you launched exits, giving you the requestCode you started it with, | ||
* the resultCode it returned, and any additional data from it. | ||
* | ||
* @param requestCode The request code originally supplied to startActivityForResult(), | ||
* allowing you to identify who this result came from. | ||
* @param resultCode The integer result code returned by the child activity through its setResult(). | ||
* @param data An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). | ||
*/ | ||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { | ||
super.onActivityResult(requestCode, resultCode, intent); | ||
CordovaPlugin callback = this.activityResultCallback; | ||
if (callback != null) { | ||
callback.onActivityResult(requestCode, resultCode, intent); | ||
} | ||
} | ||
|
||
1. Finally, remember to add the thread pool, otherwise plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, not sure if this still applicable. I can look into this when I work on the plugin for the native-to-cordova-bridge |
||
have no threads on which to run: | ||
|
||
@Override | ||
public ExecutorService getThreadPool() { | ||
return threadPool; | ||
} | ||
1. Follow [these instructions](https://cordova.apache.org/docs/en/latest/guide/cli/index.html) to build your first Cordova app | ||
|
||
1. Copy Cordova framework files | ||
|
||
* `platforms/android/CordovaLib/src/.*` to `<AndroidAppRoot>/app/main/java/` | ||
* `platforms/android/src/*` to `<AndroidAppRoot>/app/main/java/` | ||
|
||
1. Modify the layout file of the activity that shall host the Cordova view e.g. | ||
``` | ||
<LinearLayout android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<org.apache.cordova.engine.SystemWebView | ||
android:id="@+id/cordovaWebView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
</LinearLayout | ||
``` | ||
1. Modify your activity so that the class extends `CordovaActivity` (found at `app/main/java/org/apache/cordova/CordovaActivity.java`) | ||
``` | ||
public class TestActivity extends CordovaActivity { | ||
|
||
} | ||
``` | ||
|
||
1. Override `onCreate`, `makeWebView` and `createViews` to use your defined layout | ||
``` | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_test); // layout file for your activity | ||
super.init(); | ||
loadUrl(launchUrl); | ||
} | ||
|
||
@Override | ||
protected CordovaWebView makeWebView() { | ||
SystemWebView appView = (SystemWebView) findViewById(R.id.cordovaWebView); // id for the SystemWebView in previous step | ||
return new CordovaWebViewImpl(new SystemWebViewEngine(appView)); | ||
} | ||
|
||
@Override | ||
protected void createViews() { | ||
// leave empty so the layout is used | ||
} | ||
``` | ||
|
||
1. Copy the application's HTML and JavaScript files to the Android | ||
project's `/assets/www` directory. | ||
|
||
1. Copy the `config.xml` file from `/framework/res/xml` to the | ||
1. Copy the `config.xml` file from `/res/xml` to the | ||
project's `/res/xml` directory. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still apply?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config.getStartUrl() is marked as deprecated and has changed. I didn't touch the camera but assume it has changed as well.