I have here an Android device with a build in hardware barcode scanner module with a hardware scan button. I never developed an android app. but i checked the SDK of the device. The sample app uses a BroadcastReceiver to get the result of successful barcode scans.
private BroadcastReceiver mScanReceiver = new BroadcastReceiver() {
....
}
....
protected void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction(SCAN_ACTION);
registerReceiver(mScanReceiver, filter);
}
Because i'm not familiar with java I don't want to develop an app to use this device. I want to use the scanner in chrome browser instead, to work with HTML5, pouchDB & javascript.
So my questions are:
Can I listen for such android Broadcasts in the chrome browser? (how?)
If this is not possible, i think about building a simple app which opens "Chrome Custom Tabs". Is it possible to pass messages from the app to its Chrome custom tabs?
Or is there another way to solve this?
I'm working on Rails app and I need to detect if I'm on Firefox private session using Javascript code or some JS plugin.
I'm testing on Firefox 43.
I was trying using Components.classes but this is undefined. The problem is like Firefox on private session uses Tracking protected, this is not loading some JS files and I need to know if I'm on private session (then Protected Tracking is enabled), and then, I'm not going to load this tracking JS files.
Thanks in advance.
I saw some posts to check if we are in private session on Chrome and Safari and these work well on these browsers but don't work on Firefox!
I believe that there is no truly reliable way to detect private browsing. That said, I've used this in the past, and it worked quite well for me!
I have created/published an app to Google Play using the Phonegap framework and Eclipse. My question most likely has a simple answer, but after some unsuccessful research, I've reached an impasse. There are a few iframes that are supposed to access SoundCloud mp3 files online. The sound files are displaying (thus accessing the internet), but they will not play any music, rather once you click the play button, the iframe changes to a generic SoundCloud social media display. Additionally, there are a few links (target = _blank) that are still displaying within the app view rather than opening a browser window. This is a lesser issue for me, but I believe these two issues are inter-related, as I haven't really coded anything in Java except the necessary lines in onCreate in the Main Activity. Again, this app works, it's really just the nuances of debugging the internet access that I can't figure out. Here are some more salient pieces of information, and I thank you for your advice and feedback:
PhoneGap: Cordova 2.9
Permission: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Main Activity:
public class MainActivity extends DroidGap {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html", 3000);
}
}
You can use connection object (navigator.connection) to check for Internet connectivity.
Below is the link for further details-
http://docs.phonegap.com/en/2.9.0/cordova_connection_connection.md.html#Connection
If are you accessing it within i-frame you may need to use parent.window.navigator.connection
I am developing a android app using phonegap, it calls a website (http://siteaddress.com:8081) to get json encoded data. This is working fine on the emulator, then I built the android package .apk file using phonegap build but when i installed this package on my android phone and started the app, it force closes the application showing the error "The connection to the server was unsuccessful.(file:///android_asset/www/index.html)".
I have built the app using phonegap build, passed it the index.html as well as tried the .zip file package but still getting this error. I tried searching for this error and also included the below code in my app as suggested on some sites but still it is giving error.
super.setBooleanProperty("loadInWebView", true);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
Has this got something to do with the website that i am trying to call from my app? I tried opening that site in the mobile browser but it didn't opened but the website works fine on a desktop browser. Is there something wrong that i am doing?
I'm guessing its the port number your using. Have you tried using port 80 for your server rather than 8081? Its possible that port isn't open on your device.
The following code snippet solved my problem
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/home/index.html");
super.setIntegerProperty("loadUrlTimeoutValue", 10000);
I have added
super.setIntegerProperty("loadUrlTimeoutValue", 10000);
to the com.mypackage.xxx.java file
for 10 sec waiting time
*I had Same problem solved by referring * this link...
This error occurs bcoz of Server connection timeout so, Has mentioned in above post u can give 10 sec delay in that time put some splash screen..
I am new to phonegap and android development. May I know how can I debug javascript error on the emulator? I have heard about ADB may I know how can I use and install it on windows 7 system? I have an ajax called with jsonp but no response on emulator. However, I can call that ajax with browser on windows. May I know what went wrong?
Update Nov 2016: looks like this doesn't work anymore.
The easiest and one of the most powerful ways is using http://debug.phonegap.com (it uses Weinre in the background, if you care). You just
pick a random string, say r4nd0m,
inject <script src="http://debug.phonegap.com/target/target-script-min.js#r4nd0m"></script> into your index.html
visit http://debug.phonegap.com/client/#r4nd0m and you will instantly be debugging your mobile web app.
Things you can do (similar to Firebug or Web Inspector):
Viewing and changing the DOM
Editing CSS
Console for live debugging and running Javascript remotely.
Other stuff, like: storage, resources, timeline, profile, etc.
You could at least log debug stuff to the adb console by calling console.log() in JavaScript. Maybe that would suffice?
To view log output using adb, navigate to your SDK platform-tools/ directory and execute:
adb logcat
See logcat Command-line Tool
You can now use Chrome dev tools to remotely debug Android Phonegap apps! I wrote up instructions here: Remote debugging Phonegap apps with Chrome Dev Tools
Steps for Android emulator:
Navigate to chrome://inspect/ in Google Chrome on your desktop computer.
Locate Android emulator on Devices tab and click 'inspect' link
See also Get Started with Remote Debugging Android Devices
I'd recommend jsconsole. It lets you inject any JavaScript into the page and provides a basic console. There's a nice tutorial on remote debugging.
Yes, you have log errors with console.log and show the LogCat tab in Eclipse. There, Web Console messages (including JS errors) will show up. It's a little verbose so you have to filter to show just the Web Console tags but it works well. Described here: SHOWING CONSOLE CONSOLE.LOG OUTPUT AND JAVASCRIPT ERRORS WITH PHONEGAP ON ANDROID/ECLIPSE
I've found that this works for debugging javascript errors for Android/Phonegap when testing the app through Eclipse on Windows 7.
Simply go to Window > Show View > Other...
Then select LogCat under the Android folder.
The window/tab that just poped up is where the Android emulator will send its logs and error messages. You can detach this window and place it outside of the Eclipse IDE (I found this useful). You can also control the types of errors you see by selecting any of the 5 colored letters in the top right hand corner of the window.
To hide the useless information so you just see errors, make sure you only have (E) selected. Personally, I also like to have (W) warnings selected as well as (E) errors selected.
Hope that helps!
There is (finally) a tool available to allow proper JavaScript debugging for Android - http://www.jshybugger.org/
Features:
add/remove/enable/disable line breakpoints
watch expressions
step into/over/out
pause on exception
call stack navigation
local variable inspection
remote console
javascript syntax and runtime error reporting
view/edit/delete Local Storage items
view/edit/delete Session Storage items
view/edit/delete WebSQL Database records (watch Video)
view page resources (images, scripts, html)
remote console support enhanced (stacktrace)
Debugger: enhanced object inspection
Debugger: conditional breakpoints
Debugger: continue to here
I solved it easily on two steps.
Change the level of logging
In config.xml add this line
<log level="DEBUG"/>
Run the cordova Log
It's a bat file that you can just run and track all the log messages go to your phonegap project and navigate to \platforms\android\cordova then open log.bat you can now emulate your application using the command line
cordova emulate
and the log will be shown in the cmd which will be pop-uped when you open log.bat
If you are willing to set up NodeJS somewhere you can do some extended debugging with John Boxall's iBug, which although was designed for the iPhone I have tested on Android and it works fine. It's basically firebug lite for mobile devices. I'm pointing to my fork cause Node changed a lot and John's code wouldn't run on a modern nodeJS so I patched it to get it up and running on nodeJS 0.2.3, YMMV on more recent versions of nodeJS.
If you use console.log you can do simple print statements. Aswell as using adb to view them, you can use a log viewer on the device and view the logs there. More info: http://www.technomancy.org/android/javascript-debugging/
The best solution to catch exceptions and show in your console is this code:
window.onerror = function(msg, uri, line) {
console.log(msg + uri + line);
}
In Eclipse you can add an hook to the android emulator back button and inspect a value on the fly. Add the onBackPressed event manager and call the javascript console from there.
From the eclipse debug perspective you will change the value of a String variable to what you want to inspect, and pass it to your app by calling super.loadUrl.
See the code below.
Do not forget to enable the debugging of your application from DDMS view
public class MyActivity extends DroidGap {
private String js = "";
#Override
public void onBackPressed() {
//add a breakpoint to the follow line
//and change the value for "js" variable before continuing execution
super.loadUrl("javascript:console.log(" + js + ")");
return;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setBooleanProperty("keepRunning", false);
super.setIntegerProperty("splashscreen", R.drawable.splash);
super.loadUrl("file:///android_asset/www/index.html", 20000);
}
}
If you're using Phonegap Build and would like to debug using the Chrome console, here's a working solution. It's possible to debug WebViews using USB debugging (https://developer.chrome.com/devtools/docs/remote-debugging#debugging-webviews)
First, make sure your widget tag contains xmlns:android="http://schemas.android.com/apk/res/android"
<widget
xmlns="http://www.w3.org/ns/widgets"
xmlns:gap="http://phonegap.com/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="me.app.id"
version="1.0.0">
Then add the following
<gap:config-file platform="android" parent="/manifest">
<application android:debuggable="true" />
</gap:config-file>
It works for me on Nexus 5, Phonegap 3.7.0.
<preference name="phonegap-version" value="3.7.0" />
Build the app in Phonegap Build, install the APK, connect the phone to the USB, enable USB debugging on you phone then visit chrome://inspect.
Source:
https://www.genuitec.com/products/gapdebug/learning-center/configuration/
Phonegap debug still exists. the one I know of is in phonegap build found in the settings and tick the debug application option. It will then rebuild your app when you save it. A debug button will appear in the application page along with the rebuild options. (this service also uses a built in weinre)
Another option which I also find the fastest is jsconsole.com.
Its very easy to set up and requires almost no configuration compared to other methods of debugging where you need to install lots of things like drivers and SDKs.
NOTE!
In PhoneGap 10 when you build your app and any requests outside the app(as if there is no internet) fails,you will have to add this in your config.xml
<gap:plugin name="com.indigoway.cordova.whitelist.whitelistplugin" version="1.1.1" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />
I was pulling my hair out trying to get any remote debugging tool to work only to find out outside requests were blocked by default. this saved me.
Debugging PhoneGap / Apache Cordova Application is easy with GapDebug
Download & Install GapDebug from https://www.genuitec.com/products/gapdebug/
Run a GapDebug on You PC / Mac
Enable Developer Option & USB Debugging on your android device (Settings -> Developer Option (ON) -> USB Debugging (ON))
If Developer option is not found (Settings -> About Phone -> Click Build Number for 7 times)
You can Debug your application from your GapDebug
Refer
https://www.youtube.com/watch?v=QHTI-utHfEE
https://www.youtube.com/watch?v=AZJUSomFOwk
https://www.youtube.com/watch?v=XEeWFIsgtsU
https://www.youtube.com/watch?v=kiY03MBGkLo