2012-04-09 46 views

回答

1

嘗試下面的代碼,請注意,

這是對設備的工作只能在模擬器不測試

import java.util.Enumeration; 

import net.rim.device.api.system.ApplicationDescriptor; 
import net.rim.device.api.system.CodeModuleGroup; 
import net.rim.device.api.system.CodeModuleGroupManager; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.UiApplication; 
import net.rim.device.api.ui.component.LabelField; 
import net.rim.device.api.ui.container.MainScreen; 

public class StartUp extends UiApplication{ 
    public static void main(String[] args) { 
     StartUp up=new StartUp(); 
     up.enterEventDispatcher(); 
    } 
    public StartUp() 
    { 
     MainScreen screen=new MainScreen(); 
     CodeModuleGroup cmg = null; 
      CodeModuleGroup[] allGroups = CodeModuleGroupManager.loadAll(); 
      String moduleName = ApplicationDescriptor.currentApplicationDescriptor().getModuleName(); 
      for (int i = 0; i < allGroups.length; i++) { 
       if (allGroups[i].containsModule(moduleName)) { 
        cmg = allGroups[i]; 
        break; 
       } 
      } 
      if (cmg == null) { 
       screen.add(new LabelField("not able to fetch properties")); 
      } else { 
       double size=0; 
       for (Enumeration e = cmg.getPropertyNames(); e 
         .hasMoreElements();) { 
        String name = (String) e.nextElement(); 
        String value = cmg.getProperty(name); 
        System.out.println(name+" : "+value); 
        screen.add(new LabelField(name+" : "+value,Field.FOCUSABLE)); 
       } 
      } 
     UiApplication.getUiApplication().pushScreen(screen); 

    } 

} 
+0

讓我知道它是否工作? – 2012-04-09 10:21:46

+0

cmg總是返回null,因此無法檢索屬性 – 1001 2012-04-09 13:45:25

+0

您在設備或模擬器上測試過嗎?您應該僅在設備上測試 – 2012-04-10 04:14:04