To work with WEB resources, create the WebActivity application, which uses the web implemented in the RequestAPI unit.
Access to WEB resources is made as via proxy. The mobile platform server is used as an intermediary between a mobile device and WEB resources.
The application enables the user to address the Yandex search engine.
Before creating the WebActivity application:
Add the WEB data source with parameters:
Name: Yandex.
Host: yandex.ru.
Port: 80.
Protocol: HTTP.
Data transfer timeout: 40.
Import the WEB resource with parameters:
Mobile client name: Yandex.
Path: pathToAPI/userById/groupId.
GET parameters: query=some+search+query&limit=10.
Groups: ilm.
The WebActivity application includes one screen and buttons:
WEBGET. Get source code of Yandex start page.
WEBPOST. Get source view of Yandex start page with sending data as a JSON string.
To view application work results, use the interactive example:
Click any button
public class WebActivity extends AppCompatActivity {
private static final String MY_URL = "http://testmasterfmp.fsight.cloud/";
private static final VersionAPI MY_VERSION_API = VersionAPI.V_1;
private static final String MY_ENVIRONMENT = "ilm";
private static final String MY_PROJECT = "ilm";
private static final String MY_VERSION = "v1";
private static final String MY_LOGIN = "ilm";
private static final String MY_PASSWORD = "123123";
public static final String MY_WEB_RESOURCE = "yandex";
private HyperHive hyperHive;
TextView textViewActivityWeb;
private static final String TAG = "WebActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
textViewActivityWeb = findViewById(R.id.text_view_activity_web);
Handler uiHandler = new Handler();
hyperHive = new HyperHiveState(getApplicationContext())
.setHostWithSchema(MY_URL)
.setApiVersion(MY_VERSION_API)
.setEnvironmentSlug(MY_ENVIRONMENT)
.setProjectSlug(MY_PROJECT)
.setVersionProject(MY_VERSION)
.setHandler(uiHandler)
.buildHyperHive();
authentication();
}
public void authentication() {
boolean status = hyperHive.authAPI.auth(MY_LOGIN, MY_PASSWORD, true).execute().isOk();
Log.d(TAG, "authentication: " + status);
}
public void getWebGet(View view) {
String status = hyperHive.requestAPI.web(MY_WEB_RESOURCE).execute();
Log.d(TAG, "getWebGet: " + status);
textViewActivityWeb.setText(status);
}
public void getWebPost(View view) {
RequestCallParams requestCallParams = new RequestCallParams();
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Accept", "application/json");
requestCallParams.setHeaders(headers);
requestCallParams.setData("{}");
String status = hyperHive.requestAPI.request(MY_WEB_RESOURCE, requestCallParams).execute();
Log.d(TAG, "getWebPost: " + status);
textViewActivityWeb.setText(status);
}
}
See also: