Is it possible to lock the orientation on android through JavaScript? - android

Is that even possible? I doubt it, but want to make sure.

If you're not allowed to write any Java code to perform this "orientation lock", then, no, it's not possible to lock the orientation of the app from JavaScript.
You could simulate 'locking' if you detected the orientation change as mentioned in the Detect rotation of Android phone in the browser with javascript link and readjusted your HTML accordingly. But that seems like a lot of work.
If you can use Java, then you can expose a Java object through the WebView.addJavascriptInterface method and write some JavaScript to get/set the orientation using the Activity.setRequestedOrientation and Activity.getRequestedOrientation methods.

Why not? There's some simple trick coming to my mind... from Javascript you call the document.open() method with some custom url. On shouldOverrideUrlLoading view,url) you catch that call with your custom url, and so you do whatever you want.
Maybe I'm missing something... but I would try.
And well, I assume you already know that, but you have to use a WebView to embed some sort of web browser within your application.
==== EDIT ====
Well it seems I was missing something, and there is a much more classy way to do it. There is this tutorial (section Binding JavaScript code to Android code) which shows you how to add a JavaScriptAndroid interface, something related with what you want, if I'm not wrong. I haven't tried it, but it doesn't seem too difficult.

At my work place, we had a similar issue with orientation changes in the device browser. We simply popped a modal window when the orientation changed. It informed the user to rotate the device back to continue. Seemed to work well on all our tested devices.

Related

Redirect without invoke onPageStarted

It a sample question, can i redirect to another URL without make onPageStarted invoked?, without edit my java code
it will help me to test my app's security, i hope any one have idea if it possible :).
Thanks
You can try using <iframe> because onPageStarted will not be called when the contents of an embedded frame changes. If this is not a choice for you, I'm afraid there is no way to stop calling onPageStarted.
Another possible way (maybe this is my imagination) is to modify Android source code. To achieve this, you can follow the steps mentioned there. Basically, you need to download Android source, build it, and modify some code (maybe delete onPageStarted). This can be complicated and I'm not sure whether this can work.

is it possible to detect/modify input from softkeyboard

I'm currently working on android service. One of its task is to read the input data entered by user (and also modify it) .
The only possible way that till now, I've figured out is to make a custom keyboard and write methods in that custom keyboard. I don't want this .
Is their any other method for it?
Thanks
Edit: I need this to work across multiple applications. So I don't think TextWatcher can help here.
It can surely be observed by using an Accessibilityservice.
Check
http://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html
specially typeViewTextChanged and typeWindowContentChanged
This will not completly check all key hooks but you can check for changedtext in the focused window. With a little workaround you will be able to do what you want to do.

IME and catching (touch) events

Im currently trying to get my diploma in psychology and i want to write about different types of keyboards for smartphones. To research this area i need a tool that measures times. As Im new to Android programming, my friend is helping me, but we got stuck.
Here is what we need, and what we tried. Id really appreciate any help =)
We need a way to call a function before user input in IME begins and after user input in IME ends. (We need this only for timelogging, we dont need the actual input.)
We also need to call a function before user input for chosing autocorrection starts/ends.
We need to do this for all kinds of IMEs especially keyboards
like Swype, Swiftkey etc (though one of them working is enough)
We tried:
TextWatcher via addTextChangedListener
- seems to be unreliable to get the times beforeTextChanged/afterTextChanged is randomly called, even within a gesture
or multiple times within a gesture
subclassing EditText implementing OnTouchListener,
using onTouch()
- didnt seem to get called at all when using swype, so either we did it wrong or ime/swpye consumes those events,
also tried it with onKeyPreIme, wasnt called either
Ideal would be:
a way of catching the "touch" events before they are passed to the IME to log the current time via System.currentTimeMillis()
the same "after" the gesture ends i.e. when the finger is released from display
we dont need actual code, a link to the right command/documentation/widget would be sweet.
You get bonus cookies if you are ever in berlin and need a place to ... get cookies :)
Not sure if this is much of an answer, but...
Is your plan to write this in an Android application that you can distribute and run on anybody's device?
Sounds like whatever you do on the EditText or your application may not be enough because the IME is a separate module in Android, so you would not be able to get any information about auto correct or prediction or things like that (different IME have different of such features). You would only be able to get the text entered (or removed) from the text entry.
The best I can think of is for you to develop your own IME, then you can log anything you like in there.
To go about that, I would suggest, you first checkout this article from Android Developer:
http://developer.android.com/guide/topics/text/creating-input-method.html
And then you can check out the source code for the default Latin IME there:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/inputmethod/latin/LatinIME.java
Although this one has probably much more than you need and has (I think) some links into the Android framework itself, so you cannot really build it as a separate module the way it is now.
Hope that helps

How to Initiate Call from Android Web App

I'm developing a web app for android phones and I'm curious if it is possible to initiate call to a user from web interface. So basically, I want to call someone when clicking on their phone number on the web page.
While testing on Samsung GT-I9103, I've noticed that it has this functionality: on a web page, when a user clicks on a number, screen for initiating phone call gets shown. So, there is a way to do what I want. But, this functionality doesn't exist on Sony Ericsson, what makes me believe this really depends on the manufacturer. Am I right?
Also, I've checked phonegap documentation (http://docs.phonegap.com/en/2.2.0/index.html), but can't find what I need.
So, is it possible to do this?
Thanks.
Yes, it is slightly functional through JavaScript, from what I have read.
Refer to:
http://developer.android.com/guide/webapps/webview.html
Section: Binding JavaScript code to Android code

How to enable the haptic feedback (vibration) within a WebView?

I've been having a look to the built-in haptic feedback you can enable trough the KickBack setting on the Accesibility menu. It works like I expected on most of UI elements.
For those who are not aware of what haptic feedback is, it's very simple, just vibrate slighty as the user presses any button/key/field.
Well, my problem is about enabling that feaure on a WebView interface. I made sure to enable it by calling WebView.setHapticFeedbackEnabled(true), but it wouldn't work. I also tried using the native Android Web Browser, but the haptic feedback is not enabled on there either.
I was wondering if someone has some tip on how to manually set that feedback for the WebView, cause I've been having a look to the API, and can't get any idea.
PD: I'm developing for FroYo on a Nexus One with 2.2.1.
Regards!
This is currently not possible since the default WebView control is not accessible. This will be fixed in Android 3.0, according to this blog entry If you must get accessibility working for web content displayed in your app take a look at IDEAL Web Reader It's open source so you may be able to use some of their code or ideas in your own application.

Categories

Resources