PhoneGap fixes
or: Android device target Unknown, permissions & script injection
Recently I've upgraded my Smartphone (Nexus 5), and when trying to debug some Android Apps on it,
it seemed that the Android Device Chooser couldn't show much information about the device, namely:
Serial Number: ?????????????
AVG Name: N/A
Target: Unknown
This was odd, but I assumed (correctly) that ADB wasn't recognizing the device, and thus it wasn't an Eclipse problem - but the android debug bridge's problem. As soon as I restarted the adb (find adb first via "locate adb") via:
./adb kill-server
./adb start-server //might need to sudo this one
Check that your device is now visible and good via
./adb devices
If it still doesn't work, try disabling and enabling USB debugging on your phone.
Finally, if all those don't work, try and review this page.
Section 2: Never forget permissions.
Working with PhoneGap can be great, but sometimes you can get errors that have zero information about them on Google.
After getting a very odd bug from PhoneGap when trying to open an external page,
I came across this explanation.
Here I was under the impression that it might be the Cordova version (which I later figured was old because my PhoneGap version was old, all hail the new NPM support!).
Eventually I realized I was just silly and forgot to add the INTERNET permission, which is kind of important, even if ACCESS_NETWORK_STATE is already there.
Section 3: Injecting JavaScript into InAppBrowser
Finally I attempted to inject JS into an inAppBrowser window via
|
|
I was wonder at first why that didn't work, but executing code did.
|
|
After a relative small amount of information, and a big amount of debugging, I've realized it had something to do with the protocol (at least I think).
Because my InAppBrowser was pointing to a website (http://) as opposed to a local file (file://).
Finally I used an XMLHttpRequest to get the local file via JS, putting it inside a variable and executing the code:
|
|
This should solve the problem, until next time!