Autostarting MIDlets in JP-7 phones using PushRegistry

Autostarting MIDlets in JP-7 phones using PushRegistry

In Sony Ericsson Java Platform 7 (JP-7) phones, such as the K610 or W850, a new push functionality is introduced. PushRegistry Alarm and PushRegistry SMS are supported throughout the Java Platforms, with JP-4 adding PushRegistry CBS and now JP-7 includes PushRegistry auto start.

Note: the auto start functionality is not supported by the first released K610 and K800 JP-7 phones. Please use the phone's upgrade service to ensure that you are using the latest firmware version.

The auto start functionality can be set static by including it in the .jad file or it can be set dynamically in the code. Two example MIDlets are included as an example of this.

Download the source code and examples here>>

To enable the auto start functionality in the .jad file include the line:
// MIDlet-Push-<n>: <ConnectionURL>, <MIDletClassName>, <AllowedSender>
MIDlet - Push - 1 : autostart: // :, AutoStartStatic, *


To make the MIDlet auto start from the source code the following methods can be used to register and un-register the MIDlet.
// Registers the pushRegistry
public   void  Register(){
        
//  List of registered push connections.
        String connections[];
        
//  Check to see if the connection has been registered.
        
//  This is a dynamic connection allocated on first
        
//  time execution of this MIDlet.
        connections  =  PushRegistry.listConnections( false );
        
if  (connections.length  ==   0 ) {
                
try  {
                        
// Register so the MIDlet will wake up when phone is started.
                        PushRegistry.registerConnection( " autostart://: " " AutoStartDyn " " * " );
                        sDisplayString 
=   " MIDlet is registered " ;
                } 
catch  (Exception ex) {
                        System.out.println(
" Exception:  "   +  ex);
                        sDisplayString 
=   " Fail:  "   +  ex;
                }
        } 
else  {
                sDisplayString 
=   " Already registered " ;
        }
        displayForm.deleteAll();
        displayForm.append(sDisplayString);
}
 
// Unregisters the pushRegistry
public   void  Unregister(){
        
if  (PushRegistry.unregisterConnection( " autostart://: " )){
                System.out.println(
" The pushRegistry is unregistered " );
                sDisplayString 
=   " MIDlet is unregistered. " ;
        }
else {
                System.out.println(
" There is no pushRegistry to unregister " );
                sDisplayString 
=   " No MIDlet to unregister or failed to unregister " ;
        }
        displayForm.deleteAll();
        displayForm.append(sDisplayString);
}



To find out if the MIDlet is started via pushRegistry or manually you can inspect the connections registered by pushRegistry. Below is a small example of how to handle pushRegistry autostart or manual startup.
     private   void  handlePushActivation() {
        String[] connections 
=  PushRegistry.listConnections( true );
        
if  (connections  !=   null   &&  connections.length  >   0 ) {
            
for  ( int  i  =   0 ; i  <  connections.length; i ++ ) {
                
if  (connections[i].startsWith( " autostart " )) {
                    alert(
" Application autostarted " );
                }
            }
        } 
else  {
            alert(
" User started the application " );
        }
    }

你可能感兴趣的:(Autostarting MIDlets in JP-7 phones using PushRegistry)