Ad
Showing posts with label Emulator. Show all posts
Showing posts with label Emulator. Show all posts
Monday, May 10, 2010
To disable Chinese / Japanese auto-Characters – Android Emulator
Sometimes, when you are using the emulator, even if you type English characters, the emulator will be suggesting based on some Chinese /Japanese characters (I do not know the difference between the two). To disable this you need to go to Phone Settings in the emulator menus and remove the Japanese IME Settings. The path to that is in the main screen, click on the up-arrow (seen at the bottom) to see the menu. Select “settings”, navigate to “Language & Keyboard Settings”, and uncheck “Japanese IME”. You will be back to English suggestions / keyboard.
Monday, October 26, 2009
Simulate Location Change in Android Emulator
Start the Emulator
Start a command prompt
Start telnet
Then, type, o localhost 5554
This connects the telnet client to the android emulator (assuming emulator is running locally listening on port 5554. Else this connection fails)
Now type
geo fix 79.000000 13.000000 (or your latitude and longitude)
This sends the location change signal to the emulator.
NOTE: This is useful for applications built using Location APIs in Android and need to work with changes in location
Sunday, October 11, 2009
Android - Simulating an Incoming call on Emulator
On windows XP, open a command console.
Type “telnet”. The telnet client starts.
Then, type, o localhost 5554
This connects the telnet client to the android emulator (assuming emulator is running locally listening on port 5554. Else this connection fails)
Now type
gsm call 123456
The last parameter could be any number.
This simulates a call to the emulator.
Tuesday, October 6, 2009
Broadcast Receivers | Android Developer Tutorial (Part 11)
The concept of Broadcast Receivers, one of the fundamental blocks of Android, is very simple. These are applications that will respond to any intent that is broadcast by other applications. Provided the broadcast intent matches the intent specified against the receiver in the AndroidManifest.xml
This goes to automatically imply that many activities, events, services or the like can broadcast intents expecting the appropriate action to be automatically taken. So, to begin with, let us see the various Broadcast events that are given by the platform itself. Here is a standard list obtained from the android documentation:
· ACTION_TIME_TICK
· ACTION_TIME_CHANGED
· ACTION_TIMEZONE_CHANGED
· ACTION_BOOT_COMPLETED
· ACTION_PACKAGE_ADDED
· ACTION_PACKAGE_CHANGED
· ACTION_PACKAGE_REMOVED
· ACTION_PACKAGE_RESTARTED
· ACTION_PACKAGE_DATA_CLEARED
· ACTION_UID_REMOVED
· ACTION_BATTERY_CHANGED
· ACTION_POWER_CONNECTED
· ACTION_POWER_DISCONNECTED
· ACTION_SHUTDOWN
For details on when each of these intents get broadcasted, please see the android documentation. I have chosen the BROADCAST event ACTION_TIME_CHANGED as I can simulate a time change in the emulator. How to simulate the time change from adb shell is given at the end of this tutorial.
Now let us get on to the example of a broadcast receiver. You can download the complete code here.
Any activity that intends to respond to broadcasts has to extend the android.content.BroadcastReceiverclass and implement the single method onReceive().
In my example, I just notify on the status bar that the time has changed and the moment the user clicks on the status bar and sees the details, clicks on the details, the notification is removed from the status bar.
When the user clicks on the detailed portion, I take the user to the contacts application, just for anything better. Ideally this should take to an activity relevant to the application. So, if you see the onReceive()method, it is nothing but a notification example. That is all.
private NotificationManager mNotificationManager;
private int SIMPLE_NOTFICATION_ID;
@Override
public void onReceive(Context context, Intent intent) {
mNotificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notifyDetails = new Notification(R.drawable.android,"Time Reset!",System.currentTimeMillis());
PendingIntent myIntent = PendingIntent.getActivity(context, 0, new Intent(Intent.ACTION_VIEW, People.CONTENT_URI), 0);
notifyDetails.setLatestEventInfo(context, "Time has been Reset", "Click on me to view Contacts", myIntent);
notifyDetails.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);
Log.i(getClass().getSimpleName(),"Sucessfully Changed Time");
}
Once this class is ready, start the android emulator in eclipse. Then, simulate a time changed from the command prompt as given below. You will see the notification come up.
Simulating a time change in the emulator:
To start the adb shell type (in windows, assuming the path has been set to the tools folder of android sdk installation):
C:\> adb shell
#date –- 2009-10-01 14:24:59
20070325.123456
#date –s 20070325.123456
The first step date –-gives the time in seconds since Jan 1st 1970. Take the result and give it as a parameter to date –s, the time is reset in adb and within a minute on the android emulator. This broadcasts the event that time has been changed in the emulator and kicks off the Broadcast Receiver program that has been executed.
Subscribe to:
Posts (Atom)