Android の web 表示
このガイドを大きな Android アプリケーション内コルドバ有効 WebView コンポーネントを埋め込む方法を示します。これらのコンポーネントが互いと通信できる方法については、アプリケーション ・ プラグインを参照してください。
人造人間に慣れていないしている場合する必要があります最初 Android プラットフォーム ガイドに慣れるお持ち、WebView を埋め込みのより珍しい開発オプションを実行する前にインストールされている最新の人造人間 SDK。 コルドバ 1.9 を皮切りに、人造人間プラットホームに依存している、 CordovaWebView
、従来のビルド コンポーネント CordovaActivity
1.9 リリース前コンポーネント。
これらの指示に従って、最新コルドバ分布があることを確認します。Cordova.apache.orgからダウンロードし、その Android パッケージを解凍します。
Android パッケージに移動
/framework
ディレクトリと実行ant jar
。Cordova が作成されます.jar
として形成されたファイル/framework/cordova-x.x.x.jar
.コピー、
.jar
Android プロジェクトにファイル/libs
ディレクトリ。次に、アプリケーションの追加
/res/xml/main.xml
ファイルと、layout_height
、layout_width
とid
、アプリケーションに合うように変更します。<org.apache.cordova.CordovaWebView android:id="@+id/tutorialView" android:layout_width="match_parent" android:layout_height="match_parent" />
アクティビティを変更して、それを実装する、
CordovaInterface
。 それは含まれているメソッドを実装する必要があります。 それらをコピーすることができます/framework/src/org/apache/cordova/CordovaActivity.java
、または他、自分でそれらを実装します。 次のコードは、基本的なアプリケーションのインターフェイスに依存している示しています。 参照先のビュー id と一致する方法に注意してください、id
上記のように XML フラグメントで指定された属性。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()); }
アプリケーションは、カメラを使用する必要がある場合、次を実装します。
@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); } }
最後に、スレッド プールを追加してください、それ以外の場合プラグインには実行するスレッドはありません。
@Override public ExecutorService getThreadPool() { return threadPool; }
アプリケーションの HTML や JavaScript ファイル Android プロジェクトをコピー
/assets/www
ディレクトリ。コピー、
config.xml
ファイルから/framework/res/xml
をプロジェクトの/res/xml
ディレクトリ。