Playlist MyTV untuk smart TV berserta intisari rancangan bermula RM4.99 sebulan. Selanjutnya →

Webview evalJS return null in Android 4.2.2

Khamis, 3 Oktober 2013, 6:52 pm0

I have a webview that points to external URL

var webview = Ti.UI.createWebView({
	url: 'http://example.com/test.html'
});

In test.html I have a global variable

<script type="text/javascript">
var myvar = JSON.stringify({ status: true });
</script>

On webview onload event, evalJS('myvar') return null, and inside log message got “Timeout waiting to evaluate JS”. After a few days try & error, test and compare, finally I found the culprit is within tiapp.xml file.

My tiapp.xml has a customized <android> section

<android xmlns:android="http://schemas.android.com/apk/res/android">
  <tool-api-level>17</tool-api-level>
  <manifest android:installLocation="auto" android:versionCode="1" android:versionName="1.0.0">
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
    <application>
      <activity android:configChanges="keyboardHidden" android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait"/>
    </application>
  </manifest>
  <services>
    <service type="standard" url="lib/service/clear.js"/>
</services> </android>

It turns out that <uses-sdk> part is the one causes this bug. Removing the line <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/> fix this bug and I can retrieve myvar values using evalJS() again.

Logcat

29 September 2013

Tulis komen: