var ConnectMgr = Class.create({ initialize:function() { this.connected = 0; this._checkConnection(); }, _checkConnection : function() { try { var controller = Mojo.Controller.stageController.activeScene(); controller.serviceRequest('palm://com.palm.connectionmanager/', { method: 'getstatus', parameters: { subscribe: true }, onSuccess: this._checkSuccess.bind(this), onFailure: this._checkFailure.bind(this) }); } catch (e) { Mojo.Log.error('ConnectMgr -', e); } }, _checkSuccess:function(response) { Mojo.Log.info('ConnectMgr - _checkSuccess', response.isInternetConnectionAvailable); this.connected = response.isInternetConnectionAvailable; }, _checkFailure:function(response) { Mojo.Log.error('ConnectMgr - Connection Check Error:', response.errorText, '(Code', response.code, ')'); } });
使用方式:
activate : function(event) { // Check connection status connmgr = new ConnectMgr(); }
if (!connmgr.connected) { Mojo.Controller.errorDialog('Request cannot be processed without a network connection.'); return; }