webservice和android之间的通信


Communication between webservice and android

我是android新手,我想把我的drupal7内容发送到android。我可以在这个PHP webservice中向android发送一个$ variable。我该怎么做呢?

在android中,你必须创建一个异步任务,以便与服务器通信。然后你可以从php脚本发送和接收变量。(在发送之前,需要在PHP服务中以json格式编码变量。)点击这个链接;http://www.sitepoint.com/lets-talk-1/

您可以使用services模块来完成此操作。您还需要安装rest服务器

安装此模块后,您可以在admin->structure-> services

中创建自己的端点

您可以使用services_views或在您的自定义模块中通过视图添加新的自定义rest服务。

  1. 创建自定义模块,然后编写以下代码手动创建REST服务。

//服务资源function YOURMODULE_services_resources() {

$resources = array(
    'ups' => array(
        'actions' => array(
            'yourservice' => array(
                'help' => t('Service details.'),
                'callback' => 'your_rest_api_callback_function',
                'args' => array(),
                'access arguments' => array('access content'),
                'access arguments append' => false,
                'args' => array(
                    array(
                        'name' => 'data',
                        'type' => 'array',
                        'description' => 'Arguments description.',
                        'source' => 'data',
                        'optional' => TRUE,
                    ),
                ),
            ),
        ),
    ),
);
return $resources;

}

function your_rest_api_callback_function($data) {
   // in $data you will get the passed arguments
   $returnarr = "this is the content you need to return"
    return $returnarr;
}

然后在admin->structure->services中创建的新api中启用这些服务

您可以在此模块配置中指定返回的数据格式。