Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Push Your MIDlets to Do a Lot More with MIDP 2.0 PushRegistry : Page 2

Learn how to push your MIDlets up to first-class status on a range of mobile devices using the PushRegistry.


advertisement
Static Registration
To statically declare a push connection, a connection string must be specified in the Java Application Descriptor (JAD) file or the JAR manifest (depending on how the platform supports the application descriptor). Connections declared in the application descriptor follow the format:

MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>

The first element, MIDlet-Push-<n>, simply labels the entry as a push connection. Multiple push connection entries are supported. Each entry must be numbered in sequence starting at 1. For example:

MIDlet-Push-<1> MIDlet-Push-<2>

The next element, <ConnectionURL> is a connection string of the type that you would pass to a Connector.open() statement, such as datagram://:444 or socket://:111. The type of connection must be supported by the device and must be available to push connections. Note that the two connection availabilities are not the same. Just because a device supports datagrams does not mean it supports datagrams in the PushRegistry. There are no explicit requirements stated by the MIDP 2.0 specification as to what types of push connections must be supported. As a result, the availability of push can vary between devices. We'll talk about how to handle this later on in this article.



The next element is <MIDletClassName>. This is where you associate a MIDlet to the inbound connection declared by <ConnectionURL>. This must be a fully qualified MIDlet class name, such as com.gearworks.PushExample and the MIDlet must be declared as part of the MIDlet suite in the same application descriptor. For example, there must be a MIDlet declaration that specifies the same class, such as the following:

MIDlet-1: PushExample, PushExample.png, com.gearworks.PushExample

The name of the MIDlet is not what is important here. What's important is the fully qualified class name that correlates the MIDlet with a connection string. Also, not just any class can be specified here, it must be a class inheriting from javax.microedition.midlet.MIDlet so that the AMS can start the MIDlet when an incoming connection is received and call the startApp() method.

The last parameter, <AllowedSender>, is a filter mechanism that provides a way to restrict incoming connections to a specific IP address, address range, or subnet. For example, the com.gearworks.PushExample MIDlet could register for datagrams pushed only from 12.23.101.02 by declaring the following connection string:

MIDlet-Push-1: datagram://:444, com.gearworks.PushExample, 12.23.101.02

To restrict inbound connections to a range of IP addresses or to a subnet, two wildcard characters may be used: "*" and "?". The "*"matches any string, including the empty string. The "?" matches any single character. The following examples show how these wildcards may be used.
  • 12.23.???.02 (specify 3 characters at the 3rd position)
  • 12.23.*.02 (specify 0 to 3 characters at the 3rd position)
  • 12.23.???.* (specify 3 characters at the 3rd position and 0 to 3 at the 4th position )
  • 12.23.??.* (specify 2 characters at the 3rd position and 0 to 3 at the 4th position )
Dynamic Registration
Dynamic registration of push connections requires the same elements as static registration but they are specified as parameters in a call to PushRegistry.registerConnection(). The following example dynamically registers a datagram connection and is identical to the static example shown previously.

PushRegistry.registerConnection("datagram://:444", "com.gearworks.PushExample", "12.23.101.02").

Once an application registers a connection in the PushRegistry, the registration will remain on the device until the MIDlet suite is removed or the suite itself unregisters the connection.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date