Cook Your Wireless Application

Initiate developers towards Wirefree Solutions …

Logging in Blackberry

Where to write logs in native blackberry applications ?

The easiest way to write logs in blackberry is 

1. EventLogger - is simple and ultimate answer to logging in blackberry native applications.

   Steps to write logs in Blackberry Native Application.

// UID of logger, this has to be unique for every registered logger.

public static final long GUID = 0×9c805919999654d6L;

// First register Logging handler in main class  ….
EventLogger.register(GUID, “MyAccount”,EventLogger.VIEWER_STRING);

// Then set minimum logging level.
EventLogger.setMinimumLevel(EventLogger.INFORMATION);
// you would like to see logs in string format in log viewer

EventLogger.logEvent( GUID, “MyAccount :: main”.getBytes(), EventLogger.ALWAYS_LOG );

// Once EventLogger is registered in any application, it can be used in any class in that application using same GUID as shown below.
EventLogger.logEvent( GUID, “MyAccount :: main Background “.getBytes(), EventLogger.ALWAYS_LOG );

   How to View Logs.

- From the BlackBerry Home Screen, hold down the alt key and press LGLG. This will launch the BlackBerry Event Log;

Reference http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/system/EventLogger.html

Location based Services in Mobiles (GPS/AGPS)

Location based services in Mobiles (GPS/AGPS)

 

One of the most important features in today’s mobile phones is LBS (location based services). Service that let you find the device’s current location. This includes technologies like GPS/AGPS.

 

What is GPS and AGPS?

These are two ways through which device can calculate its current location. GPS means Global positioning System and AGPS means Assisted Global positioning System.

 

How location is expressed on electronic MAP?

Latitude, longitude and Altitude are the values to express location.

 

How GPS calculates devices location?

There are different ways GPS can calculates devices location.  These are also called GPS Modes. The GPS modes that the application uses to retrieve location information can affect the initial speed of the GPS Fix and level of accuracy. GPS Modes includes.

 

-       Autonomous

-       Assisted.

-       Cell Cite.

 

1.     Autonomous -> This mode mainly relies on GPS positioning satellites. Example of autonomous GPS system are , Car navigation systems.

 

2.     Assisted -> This mode relies on GPS positioning satellites and servers on the wireless network. AGPS is basically a technology that provides additional function to full blown GPS Chipset.  Example of AGPS systems is “Modern Mobile handsets based GPS. (Google’s navigation application for android based handsets.)”

 

3.     Cell cite. There are ways location can be calculated from mobile cell sites ID as well. Google has web based API available that can calculates location based on Cell Site of the handset.

 

1. Autonomous GPS->

There are factors that play its role in location calculation.

 GPS Status Image

First Fix -> . As shown in the image below. Status screen of GPS satellites’ Status screen shows 2 circles with numbers seemingly located at random over the top of them. These numbers represents the expected locations for satellites at your location and time. Knowing the approximate location and satellite number for the expected satellites aids in determining your first fix. This implies that unit must already think it knows your approximate location and approximate time.

        The approximate location of all the satellites is stored in the machine in what is called Almanac. The Almanac provides the data you see on the screen and aids the GPS by letting it know which satellites are likely to be available. The almanac data is usually good for 3 months and updated automatically when unit is on.

 

 

Cold Start -> First time you turn on the GPS unit, it must perform a cold start. To perform a successful cold start it must have current almanac (a reasonable expectation of its current location and reasonable idea of current time). Given the data the only thing it need in order to calculate a fix is 3 or 4 satellite. The data it needs is called ephemeris data and this data is transmitted every 30 second from the satellite in consultation. It takes 18 seconds to download this information because it is only being downloaded at 50bps.

 

Warm Start -> If you turn your GPS unit off and turn it back again, you will notice that it is able to compute a fix much quicker than it first calculated. The ephemeris data is valid for 4 hrs. considering that sattelite makes a full orbit in 12 hrs and earth is moving underneath.

 

 

2.  Assisted AGPS -> In Assisted GPS mode GPS system takes assistance from network servers to determine location. Please follow the image AGPS Picture.

 

AGPS Picture.

 

 

This is mainly used in mobile phones, This is more reliable then autonomous GPS. Location is calculated faster then autonomous. Some AGPS devices work even beyond network range. but most of then just cease working. Advantages of AGPS over normal GPS.

 - Faster location acquisition.

 - Less processing power required of device.

 - Saves battery.

 - Location acquisition indoors, or in non optimal environments. e.g. in tall buildings or in cloudy situations.

 

 3.Cell Cite -> location can be calculated from Cell cites id. there is google api available for calculating location from cell id, an example of this is given below. This is best suited for devices those doesnt have GPS receiver in them.

 

 

It was little bit about location. How it is calculated and what are the factors affecting in calculation of location in various modes. Now in mobiles there are various platforms in which location can be calculated.

1. J2me -> cellid , and LBS - JSR 179 .

2. RIM -> cellid, JSR 179

3. Google Android -> cellid, Google Location manger, Google map api.

 

 

1. Location Calculation in J2ME

 

   // Method for Location calculation in JSR 179.

  public void checkLocation() throws Exception {
String string;
Location l;
LocationProvider lp;
Coordinates c;
// Set criteria for selecting a location provider:
// accurate to 500 meters horizontally
Criteria cr= new Criteria();
cr.setHorizontalAccuracy(5000);
cr.setVerticalAccuracy(5000);

// Get an instance of the provider
lp= LocationProvider.getInstance(cr);

// Request the location, setting a one-minute timeout
l = lp.getLocation(120);
c = l.getQualifiedCoordinates();

if(c != null ) {
// Use coordinate information
double lat = c.getLatitude();
double lon = c.getLongitude();
string = “\nLatitude : ” + lat + “\nLongitude : ” + lon;
new GetData(midlet,lat,lon).start();
} else {
string =”Location API failed”;
}
formRunning.append(”Obtained coordinates…”);
midlet.displayString(string);
}

Geocoding or reverse geocoding examples / service can be found at following link . 

 

 

 2. Method for location calculation in RIM (Blackberry platform)

 

You can get location in blackberry using following methods. In Blackberry devices JSR 179 is available from 4.0.2 onwards and from5.0 onwards JSR 179 extension is also abailable.That provides certain extra features.

/* JSR 179 */ 
Criteria myCriteria = new Criteria();
/* JSR 179 extension */
BlackBerryCriteria myBlackBerryCriteria = new BlackBerryCriteria(…);

/** Single location fix*/
/* JSR 179 */
Location myLoc = myProvider.getLocation(…);
/* JSR 179 extension */ 
 BlackBerryLocation myBlackBerryLoc = myBlackBerryProvider.getLocation(…);
/** Continuous location fixes  */
/* JSR 179 */ 
myProvider.setLocationListener(…);
/* JSR 179 extension */ 
myBlackBerryProvider.setLocationListener(…);
/* JSR 179 */ 
double lat = myLoc.getQualifiedCoordinates().getLatitude();
double lng = myLoc.getQualifiedCoordinates().getLongitude(); 
double alt = myLoc.getQualifiedCoordinates().getAltitude();  
/* JSR 179 extension */ 
double lat = myBlackBerryLoc.getQualifiedCoordinates().getLatitude(); 
double lng = myBlackBerryLoc.getQualifiedCoordinates().getLongitude(); 
double alt = myBlackBerryLoc.getQualifiedCoordinates().getAltitude();


 

 http://www.blackberry.com/developers/docs/6.0.0api/lbs-summary.html#GPS

 

3. Method for location calculation in Android

 

 In Android location capabilities can be added into application using package android.location. The main component of location framework is LocationManager a system service. As other system services locationmanager can not be directly instantiated.  We can request an instance from system by calling getSystemService(Context.LOCATION_SERVICE).

 

                // Get the location manager
		locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

		// List all providers:
		List<String> providers = locationManager.getAllProviders();
		for (String provider : providers) {
			printProvider(provider);
		}

		Criteria criteria = new Criteria();
		bestProvider = locationManager.getBestProvider(criteria, false);
		output.append(”nnBEST Provider:n”);
		printProvider(bestProvider);

		output.append(”nnLocations (starting with last known):”);
		Location location = locationManager.getLastKnownLocation(bestProvider);

 

 http://developer.android.com/guide/topics/location/obtaining-user-location.html

Tool for android Views and Layout.

“hierarchyviewer”

e.g. Usage

$ hierarchyviewer

A GUI tool will appear that will show devices on left hand side and running packages on right hand side. TO see how the View hierarchy looks like select Device first. then what package you are interested in and finally Load View Hierarchy  button. It might take 3- 5 seconds to appear.

Working with ADB shell.

ADB — (Android Debug Bridge)

As the name says, its a complete tool for ondevice debugging. It provides access to device data.

- let it be accessing different databases on device those are created by different applications. Imp for accessing data/data directory on Device your device has to be dev rooted.

e.g. for accessing databases on android, One need to go to data

From command line

> adb shell

you are in a android shell.

> cd data/data

>cd application.package.name

cd databases

then use sqlite3 utility for opening xxx.db

e.g. > sqlite3  xxx.db

SQLite version 3.5.9
Enter “.help” for instructions

If you want to see tables in the xxx.db
sqlite> .tables;

- A good source of adb command and its usage is

http://android-dls.com/wiki/index.php?title=ADB

How to Use MapActivity in Android

Getting Map View to work. A Five Step process …


1. use java “keytool” to generate Test Application RSA certificate.

Windows: Mac: Terminal
$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -validity 10000

Now Generate MD5 Entry — with following Line …

$ keytool -list -keystore my-release-key.keystore

It will give result in this form
alias_name, Dec 14, 2009, keyEntry,
Certificate fingerprint (MD5): DC:00:83:C0:8A:A5:D4:DB:E9:CE:C6:25:6A:E2:70:EB

2. Now we need to put our key in following link

http://code.google.com/android/maps-api-signup.html

The key will be generated in this format on this webpage…
e.g. Your key is:    0ui8F2Ff_e83ArP9HG9JjCeLcRm6WzJu3z7rnGQ

The above generated key would be good for all apps signed with your certificate whose fingerprint is:

DC:00:83:C0:8A:A5:D4:DB:E9:CE:C6:25:6A:E2:70:EB

3. Create Following XML-UI

<com.google.android.maps.MapView
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:apiKey=”0ui8F2Ff_e83ArP9HG9JjCeLcRm6WzJu3z7rnGQ”
/>

4. Manifest entry for MapView Activity.

<uses-library android:name=”com.google.android.maps” />

<activity android:name=”.MAPViewActivity” android:label=”@string/app_name”>
<intent-filter>
<action android:name=”android.intent.action.DEFAULT” />
<category android:name=”android.intent.category.VIEW” />
</intent-filter>
</activity>

5. Finally  MapViewActivity

public class MAPViewActivity <ZoomButtonsController> extends MapActivity{

public static String TAG = “MAPViewActivity”;

MapView         myMapView       = null;
MapController   myMC            = null;
GeoPoint        geoPoint        = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Make sure On this page there will be no window title …
requestWindowFeature(Window.FEATURE_NO_TITLE);

activity = this;
setContentView(R.layout.viewmap);

myMapView = (MapView)this.findViewById(R.id.mymapview);
// Get your zoom controler ui through xml ….

myMapView.setBuiltInZoomControls(true);

Bundle bndl  = activity.getIntent().getExtras();

Double latitude  = (Double)bndl.get(ApplicationContants.KEY_ID_TO_LATITUDE);
Double longitude  = (Double) bndl.get(ApplicationContants.KEY_ID_TO_LONGITUDE);
int lat = latitude.intValue();
int lon = longitude.intValue();

GeoPoint point = new GeoPoint(lat,lon);

MapController mc = myMapView.getController();

mc.animateTo(point);

mc.setZoom(17);

List<Overlay> mapOverlays = myMapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);

// This helps using
MAPOverlayObject itemizedoverlay = new MAPOverlayObject(drawable,this);

OverlayItem overlayitem = new OverlayItem(point, “Ola !”, “I’m in Richmond VA!”);
// Add Overlay to ItemizedOverlay and ItemizedOverlay to mapOverlay …
itemizedoverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedoverlay);

myMapView.invalidate();

}
@Override
protected boolean isRouteDisplayed() {
return false;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_I) {
myMapView.getController().setZoom(myMapView.getZoomLevel() + 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_O) {
myMapView.getController().setZoom(myMapView.getZoomLevel() - 1);
return true;
} else if (keyCode == KeyEvent.KEYCODE_S) {
myMapView.setSatellite(true);
return true;
} else if (keyCode == KeyEvent.KEYCODE_M) {
myMapView.setSatellite(false);
return true;
}
super.onKeyDown(keyCode, event);
return false;
}

@Override
public void onStart(){
super.onStart();
}

@Override
public void onDestroy(){
super.onDestroy();
}

@Override
protected void onResume() {
super.onResume();

}

}

Reference: -http://mobiforge.mobi/developing/story/using-google-maps-android?dm_switcher=true

Using GPS features in your Android Application

Little Bit of Background to run GPS example in android device.

1. To add GPS Functionality in your Android application, you will have to add the ACCESS_FINE_LOCATION permission to the androidManifest.xml

e.g.

<?xml version=”1.0″ encoding=”utf-8″?>

<manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”net.learn2develop.GPS”> <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />

<application android:icon=”@drawable/icon” android:label=”@string/app_name”>

<activity android:name=”.GPS” android:label=”@string/app_name”>

<intent-filter>

<action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

</activity>

</application>

</manifest>

2. In Android, Loc based services are provided by the

LocationManager class in android.location package.

Your device can obtain periodic updates of the device’s geographical locations. Android application fires intent when it enters the proximity of a certain location.

3. Connect to android console to give commands to androids host (e.g. Emulator or device)…

tools>telnet

telnet> 0 localhost 5554

(this will connect to the currently active device….)

geo fix -77.230488 38.916336

[Read the rest of this entry…]

MIT Courses


MIT Open course ware  is the right place for getting knowledge online.

 

http://ocw.mit.edu/OcwWeb/web/home/home/index.htm

 

There are many courses from all streams that could be of our potential interest.

I have interest in computer science and Alternative energy resources. And I found my world here. .. so don’t take time just go ahead and look for your horizon.

 

 

Amit

Little bit about Android…

I want to say enjoy your android walk through with these android notes …

Know How / Android Platform .. 

Dalvik virtual machine

 Android use DVM (Dalvik Virtual Machine.) Following are some points  on DVM and android relation….

1. byte code vm similar to JVM
2. .dex byte code files -> java class files got converted into .dex files.
3. In Every process run in it’s own Dalvik VM runtime.
4. Mobstr cpus are register based so dalvik cuts over head
.dex allows proicesses to share system classes saves memory
5. Integrating and Extending the existing components …
Integrating existing components –>
Fire Intent and pick one of the already available set of library which we need for
example    –> Gmail wants photo and it integrate picasa lib for picking photos …
6. Android has flushed issue tracker
http://code.google.com/p/android
Group for discussion ….
http://code.google.com/groups.html
7. Bluetooth API –> Is part of the Android API..

  Introduction to SDK

  Concepts …. Application building blocks , There are Four building blocks of every android application. Every android application can have one of these or all of these in it.

1. Activity –> UI Components …
2. Intent Receivers –> Pices of code responds to notifications or status changes
3. Services –> dont have UI and runs in backgrounds ..
4. Content Provider –> Provide Handel to Deal with Data.

Some More Detail on these Building blocks

    1/ Activity –>
1/ Can be faceless
2/ can be in a floating window
3/ Can return a value.
4/ Can be embedded.

Views - Used for building android screens…

1. TextView EditText, Button, Image View
CheckBox, Lists
2. Every activity has a tree of views
1. view can be in xml
2. view can be instantiated from code.
3. support xml based styles and themes.

Layouts

1.  FrameLayout
2.    Linear layout
3.    RelativeLayout
4.    TableLayout
5.    AbsoluteLayout view given specific layout

   2/ Intents and Intents Filers

Intents description what you want to do.        
- Moving from one screen to another screen (we can declare intents what will do following task…)
- Caller calles startActivity(myintent),
- System picks Activity whose IntentFilter best matches myIntent.
- New Activity is informed of the Intent.
Intent Receivers
- Respond to alarms and notifications
- Will wake up your process if necessary
- System can broadcast intents : data


connections, phone state changes, etc.
- Intent receivers can start Services for lengthy tasks(e.g downloading new data).
- IntentReceivers in AndroiidManifest.xml
- Can also attach Intent Receivers to other objects so they can receive notifications( Activities , Views etc.)

 3/ Services

- Faceless classes that run in the background.
- Music player , network download, etc.
- Services run in your applications process or their own process.
- your code can bind to Services in your process or another process.
- Once bound, you communicates with Services using a remotable interface defined in IDL.

 4/ Content Providers

- enabling data sharing across Applications .
- Query data (Returns Cursor)
- delete , Update , and insert rows.
- Hide underlaying implementation
- Work across processes.
- All content is rep by URI’s
- Convenience methods mean clients dont’ need to know syntax

 Application Life Cycle …

        - Applications run in their own processes.
- Processes are started and stopped as needed to run an app components Process.

         Life cycle Methods …   
onCreate() –> we can check revive all the states when we get back to here ….
onPause()  –> we would like to pause and save all of our states ….
onStop()    –> we like to close services or other system resources that we have acquired.

-  There is a limit for amt of computations in onCreate() or lifeCycle Methods So be careful while using them and decide  what to put what not to put …..

 

 Other API’s in Android

1. 2D Graphics ….
We can build custon graphics components ….

2. Location Manager
-    Applicationa can refister for notifications of current locations
-  Can register for app specific Intents to be fired based on proximity.
- We can register with location manager for particular loc so that we can get to know the location
- Track files …  lugia@mit.edu (Anh Nguyen) xml file containing lat long, or google earth file …
- Map view , MapActivity,

3. Media Support …
- Play back and record media files
- Audio , Pictures and video
- Codec’s still being decided (mp4, wma etc ….)

- Access through intents
Stream from a URL
Set MIME type to help decide action

- Also class level API
Embed playback
Recording.
- Streaming through RTP

4. XMPP Service –> we can use GTalk service ….
logged-in to Gtalk -> we can send messages to friends …

5. Application management services …

6. LowLevel H/W API’s
- API’s not yet available.
- Accessing Bluetooth.
- Accessing Wifi.

 

Microsoft Visiual studio plugin for Blackberry.

The BlackBerry® Plug-in for Microsoft® Visual Studio® allows Microsoft® based developer to develop wirelessly enable applications for BlackBerry® smartphones. Download the Plug-in.

Key benefits for developers include:

  • Familiar development experience — Plugs into an existing Microsoft Visual Studio 2005 development environment, providing a familiar experience for .NET developers to create rich client applications for the BlackBerry platform.
  • Seamless wireless connectivity — Leverages the inherent security and managed wireless connectivity of the BlackBerry® Enterprise Solution, allowing developers to seamlessly connect to back-end enterprise systems using .NET Web Services.
  • Simplified BlackBerry development — Provides a framework of re-useable BlackBerry application components that simplifies user interface design, data management and wireless connectivity of rich-client applications.
  • Enterprise-class security and manageability — Applications developed using the BlackBerry Plug-in for Microsoft Visual Studio will leverage the same secure, push-based technology and scalable architecture of BlackBerry® Enterprise Server. IT departments also benefit from simplified management and centralized control of their wireless deployments.

For downloading the plug-in developer needs to have plackberry developer community UID and password. For registration onto blackberry Developer community click.

Dowload the blackberry knowledge base. Click

–Amit
 

File Handling in J2me.

_________________________________________________________________________

||–|| File Handling Example ||–||

This example explains how we can use File handling API JSR 75 on J2me Handheld.I have used SonyEricsson Handset to test the Code. The following code does very simple job, It save the image in the File system of the phone. _________________________________________________________________________

Please click on more to see code ….

[Read the rest of this entry…]