站内搜索: 请输入搜索关键词
当前页面: 图书首页 > Wireless Java Developing with J2ME, Second Edition

Permissions for Network Connections - Wireless Java Developing with J2ME, Second Edition

Previous Section Next Section

Permissions for Network Connections

MIDP 2.0 includes a security framework that is designed to prevent MIDlets from running up your phone bill by making unauthorized network connections. As I discussed in Chapter 3, network access in MIDP 2.0 is guarded by permissions and protection domains. Here are the permission names defined by MIDP 2.0:

  • javax.microedition.io.Connector.http

  • javax.microedition.io.Connector.https

  • javax.microedition.io.Connector.datagram

  • javax.microedition.io.Connector.datagramreceiver

  • javax.microedition.io.Connector.socket

  • javax.microedition.io.Connector.serversocket

  • javax.microedition.io.Connector.ssl

  • javax.microedition.io.Connector.comm

  • javax.microedition.io.PushRegistry

These permissions have names corresponding to the API that they protect. All of these permissions, except one, protect connection types, which are accessed via the javax.microedition.io.Connector class, hence the prefix on those permission names. The very last permission refers to the push registry and shares its name with the PushRegistry class.

When you run a MIDlet suite in the toolkit, it runs in the untrusted domain by default. In the untrusted domain, HTTP and HTTPS connections are allowed if the user grants permission. You can see this when you run a MIDlet that attempts a network connection. Figure 9-7 shows how the emulator asks the user for permission and allows the user to make the decision stick for the remainder of the session.


Figure 9-7: The emulator asks for the user's permission for network connections.

You can indicate the necessary and optional permissions used by your MIDlet suite by using the MIDlet-Permissions and MIDlet-Permissions-Opt descriptor attributes. (In the J2ME Wireless Toolkit, you can set permissions in the descriptor by choosing Settings, then clicking the Permissions tab.)


Previous Section Next Section