Android recognize cell phone with keyboard or not? - java

In my android app, I want to detect the user's device if the device has keyboard(like motorola milestone) and then show corresponding user interface. How do I do that?

http://developer.android.com/reference/android/content/res/Configuration.html
public int keyboard
The kind of keyboard attached to the device. One of: KEYBOARD_NOKEYS, KEYBOARD_QWERTY, KEYBOARD_12KEY.

If you're asking if there is a mechanism to allow detection of physical keyboard?
yes, Android does have the capability to notify applications of a keyboard open/close event.
You'll have to add detection of configuration changes to your activities. I believe there is a notification that is posted to the activity currently displayed that will indicate the keyboard state (or device configuration change).
http://developer.android.com/guide/topics/manifest/activity-element.html might give more insight in to what you're looking for.

Related

Android: Prevent on-screen keyboard from hiding on Button click or on IME action

By default, Android dismisses the on-screen keyboard when a user presses Send on the keyboard or clicks on a Button on the UI. However, I am building a messaging app, and would like to keep the soft keyboard on the screen even if a user clicks Send or any other button on the UI. This is the standard behavior for messaging apps (Facebook's messages functionality, for example, or Google Hangouts), so I know it can be done.
I have tried the suggestions here (returning true from the onEditorAction method of OnEditorActionListener) and here (InputMethodManager.SHOW_FORCED). The first seems to work on API 2.3, but was unsuccessful on 4.2. The latter didn't work at all.
Any suggestions would be appreciated.

Detecting whether the camera button has been pressed using J2ME

I am trying to develop an application in which I want to know when the camera button(if the phone has one),has been pressed for feature phones like Series60 using J2ME.I dont want to take a snapshot or take a video.I just want to know when the hardware button has been pressed.
I have been unable to find a proper way for this.Your help is greatly appreciated.
Create a canvas, listen for keypresses and output all events to the screen. If no event occurs when you press the camera key then you can't do it.

Android capturing volume up/down key presses in broadcast receiver?

I'm trying to make an application where the user can override the default behaviour of the volume up/down buttons (as well as the screen on/off button - is this possible?). Anyways, using some code along the lines of the following I can do this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
super.onKeyUp(keyCode, event);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
//this is where I can do my stuff
return true; //because I handled the event
}
return false; //otherwise the system can handle it
}
But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.
Thanks for any help.
as well as the screen on/off button - is this possible?
Fortunately, no.
But I would like it to be possible even when the application is not open, hence why I'd like to set up a broadcast receiver or maybe stick something in a service to make this possible.
This is not possible for the volume buttons.
For example, AndroSS allows you to override the camera hardware button to take a screenshot.
That is the camera button. If the foreground activity does not consume a camera button click, that gets turned into a broadcast Intent, which other applications can listen for. This behavior is unique to the camera and media buttons and is not used with any other hardware buttons.
this isn't a very good idea. this means every time you press the volume up/down keys you're going to capture it regardless of where you are. what if i want to change my ringer volume? media volume? app that uses the rockers for other uses? it just won't work well and just aggravate people. plus, i'm not sure if its doable.
This is not (easily) possible, because the "onKeyDown" method is overriding Activity.onKeyDown(). For this reason, you have to have a foreground activity to receive these function calls.
I don't have any experience doing this, but you would have to dig a bit deeper into writing your own hardware key intercept/handler functions, since you wouldn't be able to access the one from the activity class.
This probably won't do what you want, but if you make an IME, the IME can capture the volume +/- buttons, and do whatever it wants, like remap to other button presses. For instance, I have modified a Gingerbread-style IME to turn volume +/- buttons to do page up/down in the Kindle and Overdrive apps.

How to create notification icon badge on Android apps (like iPhone)

I am very new to programming and would like to know what is the best way to go about creating a notification icon badge similar to the ones on the iPhone apps. This would be basically for creating a badge for the notifications that end up in the notification bar.
This is actually an answer from Mark Murphy:
For most phones, you use the number field of the Notification object.
See here:
http://github.com/commonsguy/cw-android/tree/master/Notifications/Notify1/
Now, there are a few phones by one major device manufacturer that have
a bug, whereby the number field is ignored. I am working on getting
them to fix it. So you can't absolutely rely on that red bubble being
there, though it will be on most phones.
Are you talking about a graphical icon? I created a transparent PNG using the gimp and pass that drawable id as the 1st argument to the Notification constructor.
Notification notification = new Notification(R.drawable.someicon,title,System.currentTimeMillis())
I know this is very old question. May be this link is helpful is you are still looking for answer. https://github.com/leolin310148/ShortcutBadger

How Do I Minimize a J2ME App?

I need my J2ME app to run in the background and still allow the user to use his mobile without problem.
the app still needs to process some events in the background.
I would also like to allow the user to stop the app if he wants to.
How can I accomplish this?
Running a midlet in the background but still processing is not specified in the j2me standard i think. Normaly at the moment your midlet is moved to background the paused method should be called.
But not every vendor implements it that way. Symbian keeps your program running as if there was no change when minimized. At least on the N80 and N90.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices. For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And foreground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But Be aware that every device not supports that features.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).
This is not always supported, but on the handsets that do, the command is:
Display.getDisplay(theMidlet).setCurrent(null);
If you app is in background then it doesn't receive any events. So I don't know how it can process any event in the background. If its a preload J2ME app then you can work with the handset manufacturer and obtain certain jad attributes to put your midlet in background. You can thus not allow the user to exit the app. You may want to think this use case through.
On the other hand you can do all these in Blackberry apps.
MIDlet.notifyPaused()

Categories

Resources