Android: problem with debugging javascript in webview - android

I have some javascript running in WebView, and I want to receive console messages about errors in JS.
In accordance with the instructions at http://developer.android.com/guide/webapps/debugging.html I overrided methods
WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)
and
WebChromeClient.onConsoleMessage(ConsoleMessage cm),
redirecting messages to logcat. In android 2.1 it works well, but in android 2.2 none of this methods are called.
What I am doing wrong?
Thanks.

It seems that HTC disabled console.log on Android 2.2 devices. check out this post:
How to display console.log() output in PhoneGap app using Eclipse and HTC Desire HD?

I just tested on 2.2 (level 8). It's working fine. Not sure why you're not seeing it. I would validate the setting of ChromeClient.
js contains...
console.log("Hello World");
console.error("Serious");
ChromeClient contains
#Override
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
// TODO Auto-generated method stub
Log.v("ChromeClient", "invoked: onConsoleMessage() - " + sourceID + ":"
+ lineNumber + " - " + message);
super.onConsoleMessage(message, lineNumber, sourceID);
}
#Override
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.v("ChromeClient", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
Log contains
03-16 15:53:12.309: VERBOSE/ChromeClient(595): Hello World -- From line 24 of file:///android_asset/base.js
03-16 15:53:12.309: VERBOSE/ChromeClient(595): Serious -- From line 25 of file:///android_asset/base.js

Related

The sample of Android's MultiClientInputMethod cannot properly work

I follow Google's official instructions to use the example of MultiClientInputMethodManagerService(https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/inputmethod/multi-client-ime.md)
The AOSP11 emulator with perDisplayFocus has been built, the screenshot you can see that
enter image description here
But the ime's window only shows on main display, and can only input on the main displayenter image description here
I have added some log to see the multi input window , it seems like has shown
#Override
public void onShowSoftInput(int flags, ResultReceiver resultReceiver) {
if (DEBUG) {
Log.v(TAG, "onShowSoftInput clientId=" + mClientId + " flags=" + flags);
}
final SoftInputWindow window =
mSoftInputWindowManager.getSoftInputWindow(mSelfReportedDisplayId);
if (window == null) {
return;
}
if (mClientId != window.getClientId()) {
Log.w(TAG, "onShowSoftInput() from a background client is ignored."
+ " windowClientId=" + window.getClientId()
+ " clientId=" + mClientId);
return;
}
window.show();
Log.v(TAG, "is showing"+window.isShowing());
}
The logcat of AndroidStudio enter image description here
I search on Google and has not found relevant questions for a long time.Has anyone used this ,thank you very much for the experienced answerers
i had solved it , anyone who sees this problem can refer to my solution https://github.com/Superpengun/MultiDisplayInput
The jar used in the project is extracted from the aosp12 compiled classed.jar ,the keyboardview is a dialog,maybe there is a difference of dialog's Multi-screen display. In the github's project i rebuild the jar for hidden api of AOSP12 and verfied it

Why is NoSuchFieldException: ON_STOP thrown on Android 5.0.2?

I am using android.arch.lifecycle extension to detect when the app moves in background or foreground:
#OnLifecycleEvent(Lifecycle.Event.ON_STOP)
private void onAppBackgrounded() {
Log.i(this.getClass().getName(), "onAppBackgrounded()");
}
The extension works fine except on a device running on Android 5.0.2 (SDK 21) on which I get the following exception:
Caused by java.lang.NoSuchFieldException: ON_STOP
at java.lang.Class.getDeclaredField + 929(Class.java:929)
at libcore.reflect.AnnotationAccess.decodeValue + 685(AnnotationAccess.java:685)
at libcore.reflect.AnnotationAccess.toAnnotationInstance + 663(AnnotationAccess.java:663)
at libcore.reflect.AnnotationAccess.toAnnotationInstance + 641(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation + 170(AnnotationAccess.java:170)
at java.lang.reflect.Method.getAnnotation + 301(Method.java:301)
at android.arch.lifecycle.ClassesInfoCache.createInfo + 124(ClassesInfoCache.java:124)
at android.arch.lifecycle.ClassesInfoCache.hasLifecycleMethods + 59(ClassesInfoCache.java:59)
at android.arch.lifecycle.Lifecycling.resolveObserverCallbackType + 137(Lifecycling.java:137)
at android.arch.lifecycle.Lifecycling.getObserverConstructorType + 119(Lifecycling.java:119)
at android.arch.lifecycle.Lifecycling.getCallback + 57(Lifecycling.java:57)
at android.arch.lifecycle.LifecycleRegistry$ObserverWithState.(LifecycleRegistry.java:2)
at android.arch.lifecycle.LifecycleRegistry.addObserver + 162(LifecycleRegistry.java:162)

Android AWS S3 SDK 2.2.16 TransferListener receiving incorrect onProgressChanged Data

The issue is with AWS S3 upload process, when I try to upload a file sometimes I am receiving more bytesCurrent than bytesTotal which is making the progress calculation to go more than 100%. But when I checked the size of photo on device, S3 storage and the logs which show bytesTotal for that file all of them to be same. Have someone else seen this issue with onProgressChanged. Please let me know.
#Override
public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
// Calculate percentage here.
Log.d("Upload Status", "file id: " + id + ", bytesCurrent: " + bytesCurrent + ", bytesTotal: " + bytesTotal);
}
This is a known bug, but it's fixed in v2.2.19. See release notes. Please upgrade the SDK.

as3 _ctx is null pozirk android in app purchases ANE

I googled _ctx is Null and I was shocked to find nothing relating to Android. I am hoping this pose will help someone if we find the right answer.
Here is a link to the ANE I am using: https://github.com/pozirk/AndroidInAppPurchase
I have no idea where to go from here. It once worked now its not. :(
I am trying to use Pozirk's InAppPurchase.ane - which I have used before but suddenly its not working. I am not sure what changed. It may be, the ANE, or something in google play. Not sure but now its not working and I keep on getting this error:
_ctx is null.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.pozirk.payment.android::InAppPurchase/init()[C:\Users\blah\blah\Android\com\pozirk\payment\android\InAppPurchase.as:46]
at hereWeGo_fla::MainTimeline/fl_MouseClickHandler()[hereWeGo_fla.MainTimeline::frame1:97]
import com.pozirk.payment.android.InAppPurchase;
import com.pozirk.payment.android.InAppPurchaseEvent;
import flash.display.MovieClip;
/**
* ...
* #author Ben Barnard
*/
var _iap:InAppPurchase;
_iap = new InAppPurchase();
_iap.addEventListener(InAppPurchaseEvent.INIT_SUCCESS, onInitSuccess);
_iap.addEventListener(InAppPurchaseEvent.INIT_ERROR, onInitError);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_SUCCESS, onPurchaseSuccess);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_ALREADY_OWNED, onPurchaseSuccess);
_iap.addEventListener(InAppPurchaseEvent.PURCHASE_ERROR, onPurchaseError);
_iap.addEventListener(InAppPurchaseEvent.CONSUME_SUCCESS, onConsumeSuccess);
_iap.addEventListener(InAppPurchaseEvent.CONSUME_ERROR, onConsumeError);
_iap.addEventListener(InAppPurchaseEvent.RESTORE_SUCCESS, onRestoreSuccess);
_iap.addEventListener(InAppPurchaseEvent.RESTORE_ERROR, onRestoreError);
// Liscense Key
function onRestoreError(e:InAppPurchaseEvent):void
{
trace("Restore Error - " + e.toString());
outputField.text = "Restore Error - " + e.toString() + e.data.toString();
}
function onConsumeError(e:InAppPurchaseEvent):void
{
trace("Consume Error - " + e.toString());
outputField.text = "Consume Error - " + e.toString() + e.data.toString();
}
function onConsumeSuccess(e:InAppPurchaseEvent):void
{
trace("Consume Success - " + e.toString());
outputField.text = "Consume Success - " + e.toString();
// ------------------------------- THIS LINE PROMPTS THE USER TO PURCHASE THE ITEM ------------------------------- //
_iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
}
function onPurchaseError(e:InAppPurchaseEvent):void
{
trace("Purchase Error - " + e.toString());
outputField.text = "Purchase Error - " + e.toString();
}
function onRestoreSuccess(e:InAppPurchaseEvent):void
{
trace("Restore Success - " + e.toString());
// ------------------------------- THIS LINE CONSUMES THE "TEST" ITEM ------------------------------- //
_iap.consume("android.test.purchased");
}
function onPurchaseSuccess(e:InAppPurchaseEvent):void
{
trace("Purchase Successful - " + e.data.toString());
outputField.text = "Purchase Successful - " + e.data.toString();
}
function onInitError(e:InAppPurchaseEvent):void
{
trace("Init Error - " + e.toString());
outputField.text = "Init Error - " + e.toString();
}
function onInitSuccess(e:InAppPurchaseEvent):void
{
trace("Init Success - " + e.toString());
outputField.text = "Init Success - " + e.toString();
// ------------------------------- THIS LINE RESTORES ALL PURCHASED ITEMS ------------------------------- //
//_iap.restore(InAppPurchase.TYPE_INAPP);
}
init.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
_iap.init("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiM0Lpjf/S5JQOh0L5c3IQNawziFTT9WeJ9fAmQl5nXJdfVnRK9+mMCnHJlKz8omt9RljlrtLpOV4iy+/KUFgtZ/SCvF+Brpk9lAEe+SbifT2mNGNKgF3tCXSHTXX2Xuq9kw1CR0bDy0Jf36LE04zBo4jYV4RcWQ66ViS2JbTEXAugG5S71z+CJXo6o5uYG/mRZlHFRJkpp1ufDFg4dp8r2ApN3RXhMv9Rl3NCcwTk3R0/rmwCc80Uy94kX7hkgeBuj/AViFZMbzYzY8YLdx80cYYHPc/ofecXmCl6OorJiBC+GiMs/vBoyjr4EGeIqfp1WdZrxeaJzMzAWPNoY4mSwIDAQAB");
}
purchase.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.purchase("android.test.purchased", InAppPurchase.TYPE_INAPP);
}
consume.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);
function fl_MouseClickHandler_3(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.consume("android.test.purchased");
}
restore.addEventListener(MouseEvent.CLICK, rLove);
function rLove(event:MouseEvent):void
{
//_iap.restore(InAppPurchase.TYPE_INAPP);
_iap.restore(InAppPurchase.TYPE_INAPP);
}
You did not add ANE file to your project properly.
This question was already asked and answered:
http://inside.pozirk.com/2013/02/18/adobe-air-in-app-purchase-native-extensions/#comment-87
http://inside.pozirk.com/2013/02/18/adobe-air-in-app-purchase-native-extensions/#comment-89
My checklist, after tinkering FlashBuilder for 2 hours:
1) "project" > Properties > ActionScript Build Path > Native Extensions > Add ANE > "add InAppPurchase.ane"
2) "project" > Properties > ActionScript Build Packaging > Google Android > Native Extensions > "select package InAppPurchase.ane"
3) ... AS3 code uses the in-app-purchase API ...
4) The ANE seems to fail if you try to use it in debug mode; an exported APK should be used instead.
5) FlashBuilder > Project > Export Release Build:
Verify that the ANE is included in the package (Native Extensions)
Verify that your are using the correct signing certificate.
6) Copy the created APK to the Android device.
7) Install the APK using a file explorer.
8) The app finally runs, instead of crashing/hanging at startup.

Webview does not show onConsoleMessage in android

I have used webview
with the reference http://developer.android.com/guide/webapps/debugging.html
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient() {
public boolean onConsoleMessage(ConsoleMessage cm) {
Log.d("MyApplication", cm.message() + " -- From line "
+ cm.lineNumber() + " of "
+ cm.sourceId() );
return true;
}
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
Log.d("MyApplication", message + " -- From line "
+ lineNumber + " of "
+ sourceID);
}
});
but still m not get log Logcat
Please help me out
It appears some devices (HTC Desire and some others) with specific OS (mine had 2.3.3) do not display messages in Logcat window and it seems console.log does not work for them. I found a nice workaround using JavaScript Interface to overcome the issue: Android Console via JS interface
In my case (I have Samsung Note 4 running Android 6.0), onConsoleMessage is called only if I set
myWebView.setWebContentsDebuggingEnabled(true);
and when I open the Chrome remote device debugger to inspect the webview. But obviously this is not quite helpful since I can already see the console output on the debugger window.

Categories

Resources