1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidで動くBASICでJSのconsole.logやエラーを表示する方法

1
Posted at

BASIC!は、Androidで動くBASIC インタープリタです。詳しくは以下をどうぞ。

BASIC!にはHTMLモードというモードがあり画面表示にHTML,javascript,cssを利用できますがJSのconsole.logやsyntaxエラーをAndroidの実機で表示する方法を見つけました。パソコン等と接続する必要はありません。

1.表示する方法の概要

BASIC!でOSコマンドが送り込めるsystem命令を使いlogcatを送り込み、結果から"chromium"を含む文字列を抽出するだけです。

2.コード

短いですがさっそくコードです。ポイントは以下

  • html.load.urlでHTMLファイルを開いて閉じます
  • syatem.witeでlogcatを発行
  • system.READ.READYでOS応答有無をチェック
  • system.READ.LINEでOS応答を行読込
  • is_in関数で"chromium"を含む行を抽出、print
  • console.saveで出力した内容をファイルへ出力
console.title "logcat"

! HTML MODE
html.open

html.load.url "jstest2.html"

pause 3000

html.close

pause 1000

PRINT "***logcat start***"

r$="logcat"

! os command mode
system.OPEN


! write the command
system.WRITE r$

! Give system time to respond
PAUSE 500

loop:

! check for a response
system.READ.READY ready

! if no input, do next command
IF !ready THEN GOTO loop

! read responses
DO
system.READ.LINE l$
!PRINT l$
if is_in("chromium",l$) > 0 then
   PRINT l$
endif
system.READ.READY ready
UNTIL !ready

pause 1000


PRINT "***logcat ended***"

console.save "logcat.txt"

end

3.実行結果の例

  • 16964はプロセス番号
  • 177,189,182は行番号
***logcat start***
I/chromium(16964): [INFO:CONSOLE(177)] "basicjslog001test console", source: file:///storage/emulated/0/rfo-basic/data/jstest2.html (177)
I/chromium(16964): [INFO:CONSOLE(179)] "basicjslog002test console part2", source: file:///storage/emulated/0/rfo-basic/data/jstest2.html (179)
I/chromium(16964): [INFO:CONSOLE(182)] "basicjslog003test console err", source: file:///storage/emulated/0/rfo-basic/data/jstest2.html (182)
***logcat ended***

4.まとめ、その他

  • パソコンと繋がなくてもconsole.logのチェックは可能
  • HTMLファイルを表示してlogcatを送り込むだけ
  • 非ルート端末でも実行可能
  • android5.1のタブレットで動作確認しました

以上です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?