[Huawei Developers] hakki.ozer:
Displaying the Cellular (LTE) Connection Values Obtained by HMS Wireless Kit and the Location Information Obtained Using the Location Kit on the Map Kit

​

Hello everyone,

In this article, I will explain what the cellular data values obtained using the Wireless Kit are, how they are used and how the Wireless Kit values obtained based on location can be displayed on the map using the Huawei Map kit and Location kit. Let’s start with the use of the Wireless Kit first.

Wireless Kit Integration and Use of Wireless Kit Data

First we are creating our Application Gallery Connect website project and integrating the HMS core into our application. You can learn the detailed information required for these procedures from the link.

https://developer.huawei.com/consumer/en/hms/huawei-wirelesskit/

Then we create the buttons of the application, which we will do in three stages in MainActivity as below.

​

We define the buttons we have created in the MainActivity class as below.

public class MainActivity extends AppCompatActivity {
private static final String TAG = "<!!!> MainActivity";
private TextView resultTextView;
private int textCounter = 0;
private NetworkQoeService networkQoeService;
private LocationService locationService;
private String networkData = null, qoeLevel = null;
private Location locationData = null;
private AlertDialog progressDialog;
@Override
protected void onDestroy() {
super.onDestroy();
networkQoeService.DestroyService();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
networkQoeService = new NetworkQoeService(this);
locationService = new LocationService(this);
resultTextView = findViewById(R.id.resultext);
resultTextView.setMovementMethod(new ScrollingMovementMethod());
Button callbackButton = findViewById(R.id.callbackbtn);
Button realTimeDataButton = findViewById(R.id.getrealtimebtn);
Button openMapButton = findViewById(R.id.openMapButton);
callbackButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getCallBackData();
}
});
realTimeDataButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getNetworkData();
}
});
openMapButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog = showProgressAlertDialog();
getNetworkData();
getLocationData();
}
});
}

We enter the necessary permissions as in the manifest file below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.wirelesskit_codelab">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.huawei.permission.SECURITY_DIAGNOSE"/>
<application
android:name=".wirelesskit.MapKitApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WirelessKitCodelab">
<activity android:name=".wirelesskit.activity.PermissionActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".wirelesskit.activity.MainActivity"
android:screenOrientation="portrait"/>
<activity android:name=".wirelesskit.activity.MapActivity"/>
<activity android:name=".wirelesskit.video.PlayActivity"
android:theme="@style/Theme.AppCompat.NoActionBar"
android:screenOrientation="landscape"/>
</application>
</manifest>

When we press the callbackButton, which is the first button we defined above, we call the getCallBackData method below and obtain your cellular (LTE) connection’s identifier, uplink latency, downlink latency, uplink bandwidth, downlink bandwidth, uplink rate, downlink rate, QoE level and uplink packet loss rate data respectively.

​

getCallBackData method can be viewed from the link below.

private void getCallBackData() {
Bundle data = NetworkQoeService.qoeInfo;
if(data != null)
{
int channelNum = 0;
if (data.containsKey("channelNum")) {
channelNum = data.getInt("channelNum");
}
String channelQoe = "channelNum: " + channelNum;
for (int i = 0; i < channelNum; i++) {
// channelQoe can be displayed on the user interface through EditText.
channelQoe += ",channelIndex: " + data.getInt("channelIndex" + i) + ",uLRtt: " + data.getInt("uLRtt" + i) + ",dLRtt: "
+ data.getInt("dLRtt" + i) + ",uLBandwidth: " + data.getInt("uLBandwidth" + i) + ",dLBandwidth: "
+ data.getInt("dLBandwidth" + i) + ",uLRate: " + data.getInt("uLRate" + i) + ",dLRate: "
+ data.getInt("dLRate" + i) + ",netQoeLevel: " + data.getInt("netQoeLevel" + i) + ",uLPkgLossRate: "
+ data.getInt("uLPkgLossRate" + i)+"\n";
}
updateText(channelQoe);
}else
{
Log.e(TAG, "callbackData else");
}
}

You can also look at the link below for detail information about the getCallBackData() method results.

https://developer.huawei.com/consum...eferences-V5/iqoecallback-0000001050986863-V5

Secondly, we call the getNetworkData() method using the realTimeDataButton button and get real-time NetworkQoe information of the application. In other words, we obtain the last second connection information.

​

We do this process using the networkQoeService.GetRealTimeData () command as in the code section below.

private void getNetworkData() {
Bundle data = networkQoeService.GetRealTimeData();
if(data != null) {
int channelNum = 0;
if (data.containsKey("channelNum")) {
channelNum = data.getInt("channelNum");
}
int index = channelNum - 1;
networkData = "Channel Number : " + channelNum + "\n" +
"Channel Index : " + data.getInt("channelIndex" + index) + "\n" +
"UpLink Latency : " + data.getInt("uLRtt" + index) + "\n" +
"DownLink Latency : " + data.getInt("dLRtt" + index) + "\n" +
"UpLink Bandwidth : " + data.getInt("uLBandwidth" + index) + "\n" +
"DownLink Bandwidth : " + data.getInt("dLBandwidth" + index) + "\n" +
"UpLink Rate : " + data.getInt("uLRate" + index) + "\n" +
"DownLink Rate : " + data.getInt("dLRate" + index) + "\n" +
"QoE Level : " + data.getInt("netQoeLevel" + index) + "\n" +
"UpLink Package Loss Rate : " + data.getInt("uLPkgLossRate" + index) + "\n" +
"Download Speed in Mbps : " + data.getInt("dLBandwidth" + index) / 1000.0
;
qoeLevel = data.getInt("netQoeLevel" + index) + "";
updateText(networkData);
}
else {
Log.e(TAG, "realTimeData else");
}
}

Integration of Location and Map Kit and Displaying the Data Obtained on the Screen

We call the showProgressAlertDialog(), getNetworkData(), getLocationData() methods using the openMapButton button we created in our manifest. First, we use the showProgressAlertDialog() method to print the “loading” screen to indicate to the user that the screen should be waited until the other operations to be performed and the location and cellular connection information provided on the map are completed. We do this process using the code section below.

private AlertDialog showProgressAlertDialog(){
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(this);
builder.setTitle("Loading...");
LayoutInflater factory = LayoutInflater.from(this);
View progressBar = factory.inflate(R.layout.progress_bar, null);
builder.setView(progressBar);
AlertDialog alertDialog = builder.create();
alertDialog.setCancelable(false);
alertDialog.show();
return alertDialog;
}

Secondly, we get real-time NetworkQoe information of the application by calling the getNetworkData() method. We will use the netQoeLevel data in the Wireless Kit results. The netQoeLevel variable takes one of the 4 and 5 values as in the pictures below, according to the connection quality. If the user has a smooth network performance, this value will return 4. However, if the user has poor network performance, this value will return 5.

​

Finally, we get the location information of the user calling the getLocationData() method, when the network connection quality is calculated. We do the process of obtaining location information as below.

private void getLocationData() {

locationService.getLocationUpdate(new LocationCallback() {

@Override

public void onLocationResult(LocationResult locationResult) {

if (locationResult != null) {

locationData = locationResult.getLastLocation();

openMapActivity();

locationService.stopLocationUpdates(this);

progressDialog.cancel();

}

}

});

}

As you see in the code section above, we use the getLocationUpdate method to get location information. Then we get the last location information using getLastLocation() method and we start our map operations using the openMapActivity() method. When we start this process, we stop the location service update process using stopLocationUpdates() because we have obtain the necessary location data. In addition, since the map opening process will start, we use progressDialog.cancel () to close the loading screen.

In the openMapActivity () method, we open the MapActivity using the necessary network information and location information as in the code section below.

private void openMapActivity() {
this.startActivity(MapActivity.newIntent(this, networkData, qoeLevel, locationData.getLatitude(), locationData.getLongitude()));
}

In the MapActivity’s onCreate() method we are directed here, we make the necessary assignments to the parameters, the width and length of our map, and the necessary definitions for the mapView.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
networkData = getIntent().getStringExtra(KEY_NETWORK_DATA);
qoeLevel = getIntent().getStringExtra(KEY_QOE_LEVEL);
double latitude = getIntent().getDoubleExtra(KEY_LATITUDE, 0);
double longitude = getIntent().getDoubleExtra(KEY_LONGITUDE, 0);
latLng = new LatLng(latitude, longitude);
mMapView = findViewById(R.id.mapView);
Bundle mapViewBundle = null;
if (savedInstanceState != null) {
mapViewBundle = savedInstanceState.getBundle(MAP_VIEW_BUNDLE_KEY);
}
MapsInitializer.setApiKey(API_KEY);
mMapView.onCreate(mapViewBundle);
mMapView.getMapAsync(this);
}

After completing the operations above, we will work on the onMapReady() method. In this method, we do our map configurations in the section we specified with the update camera view. Then we set the marker in If condition, which will show the user’s location on the map according to the qoeLevel value in the network data we receive from the Wireless Kit. As we explained above in our article, the netQoeLevel parameter will return 4 if the user has a smooth network connection, and in this case, we set the marker showing the user’s location to green. But if the user has poor network performance, this value will return as 5, and in this case, we set the location marker on the map to red to indicate the weak link. Then, when we click on these markers, we define InfoWindowAdapter on HuaweiMap to display network information on the screen. After these processes are finished, we create a LinearLayout to place the network connection data we receive from the Wireless Kit. Finally, we add the titles of the markers that indicate the network quality status that we have determined according to the netQoeLevel parameter to the LinearLayout we have created before, after adjusting the properties such as title text, background like below.

public void onMapReady(HuaweiMap huaweiMap) {
//update camera view
CameraUpdateParam cameraUpdateParam = new CameraUpdateParam();
cameraUpdateParam.setLatLng(latLng);
CameraUpdate cameraUpdate = new CameraUpdate(cameraUpdateParam);
huaweiMap.moveCamera(cameraUpdate);
//add marker
MarkerOptions markerOptions = new MarkerOptions()
.position(latLng)
.snippet(networkData);
if (GOOD_QOE_LEVEL.equals(qoeLevel)){
markerOptions.title("GOOD NETWORK CONNECTION");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
}
else if (BAD_QOE_LEVEL.equals(qoeLevel)) {
markerOptions.title("BAD NETWORK CONNECTION");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
}
huaweiMap.addMarker(markerOptions);
huaweiMap.setInfoWindowAdapter(new HuaweiMap.InfoWindowAdapter() {
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public View getInfoWindow(Marker marker) {
LinearLayout info = new LinearLayout(MapActivity.this);
info.setOrientation(LinearLayout.VERTICAL);
TextView title = new TextView(MapActivity.this);
title.setTextColor(Color.BLACK);
title.setBackgroundColor(Color.LTGRAY);
title.setTypeface(null, Typeface.BOLD);
title.setText(marker.getTitle());
TextView snippet = new TextView(MapActivity.this);
snippet.setTextColor(Color.BLACK);
snippet.setBackgroundColor(Color.LTGRAY);
snippet.setText(marker.getSnippet());
info.addView(title);
info.addView(snippet);
return info;
}
});
}

You can see the screenshots we created below. Thus, we complete our application.

​

You can visit the link below for detailed information about the Wireless Kit.

https://developer.huawei.com/consumer/en/hms/huawei-wirelesskit/

You can visit the link below for detailed information about the Map Kit.

https://developer.huawei.com/consumer/en/hms/huawei-MapKit/

You can visit the link below for detailed information about the Location Kit.

https://developer.huawei.com/consumer/en/hms/huawei-locationkit/

Thank you for taking your time and reading my article. Hope to see you in my next forum xda article.

​