コメント |
@DIV
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
// **************************************
// WebView 上で実行される場合
// console.log は Android 側で表示
// **************************************
if ( typeof androidObject !== 'undefined' ) {
window.console.log = function(message){
androidObject.logcat(message);
}
}
function getWebPageData(scode) {
// ***************************************
// Android WebView の中のこのページ
// より、サーバへアクセスします
// ***************************************
$.get("dbdata_json.php?scode="+scode,function( data ){
if ( typeof androidObject !== 'undefined' ) {
// サーバから受け取った application/json データ
// を文字列に変換して Android に渡します
androidObject.toAndroid(JSON.stringify(data));
}
else {
// 通常のブラウザではこちらが実行されます
console.log(JSON.stringify(data,null," "));
}
})
}
</script>
</head>
<body>
<pre>
<?php
// Android の呼び出しテスト
?>
<input type="button" value="logcat test" onclick="androidObject.logcat('OK')">
<?php
// サーバからのデータで Android の呼び出しテスト
?>
<input type="button" value="toAndroid test" onclick="getWebPageData('0001')">
</pre>
</body>
</html>
@END |