Overview
We've grown accustomed to the hassle of connecting our devices to the Wi-Fi networks in new locations, which can be an annoyance at best, and a major frustration at worst. But perhaps more importantly, this process also comes with the risk of password leakage. Wouldn't it be nice if there was a way to connect our devices to Wi-Fi networks on an automatic basis, rather than having to manually enter the password each time?
HUAWEI Nearby Service offers a Wi-Fi sharing feature, which once integrated, equips your app to connect users on a wide range of smart devices to the Wi-Fi networks that they encounter.
Wi-FiShareDemo
Here, we've used Wi-FiShareDemo as an example, which has integrated the Wi-Fi sharing function in Nearby Service. Now, we'll show you the core code for the app, and how the app can be run.
Preparing Tools
One Huawei phone (The phone for sharing Wi-Fi must be a Huawei phone, and be connected to Wi-Fi.)
One Android device (The device to be connected to Wi-Fi must run Android 5.0 or later and have HMS Core installed, and can be a phone or a TV box.)
Android Studio (3.X or later)
Creating an app
Import the source code to Android Studio.
Register as a Huawei developer.
Create an app in Huawei AppGallery. For details, please refer to HUAWEI Developers-App Development. Note that you will need to download the agconnect-services.json file, generate the signing certificate, and save both to the app directory.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Run the app in Android Studio and install it on the test devices.
Procedures
After configuring the code and completing the installation, perform the following steps.
1.Start Wi-FiShareDemo on B, and tap Connect Wi-Fi.
2.Start Wi-FiShareDemo on A, and tap Share Wi-Fi.
3.On A, select the phone that will share Wi-Fi, make sure that the verification codes on both phones are the same, and tap ALLOW.
4.On B, tap ALLOW in the dialog box that is displayed to authorize the Wi-Fi connection.
Core Code
You can view the source code of the app in GitHub. In this app, the WifiShareHelper.java class is encapsulated based on the Nearby Service APIs. Only the APIs requestWiFiConfig and shareWiFiConfig for WifiShareHelper.java are used to connect to and share Wi-Fi.
requestWiFiConfig
// The device request to connect WiFipublic void requestWiFiConfig() { Log.d(TAG, "requestWiFiConfig"); mWifiShareEngine.startWifiShare(mWifiShareCallback, WifiSharePolicy.POLICY_SET) .addOnFailureListener(e -> Log.e(TAG, Objects.requireNonNull(e.getMessage())));}
shareWiFiConfig
// The device to share wifipublic void shareWiFiConfig() { Log.d(TAG, "Start to share WiFi"); mWifiShareEngine.startWifiShare(mWifiShareCallback, WifiSharePolicy.POLICY_SHARE) .addOnFailureListener(e -> Log.e(TAG, Objects.requireNonNull(e.getMessage()))); showListView(); setListViewListenerMode();}
Learn More
For more details, please visit HUAWEI Developers.
For further instructions, please refer to Development Guides.
To join the developer discussion, please visit Reddit.
To download the demo and sample code, please go to GitHub.
To resolve integration issues, please go to Stack Overflow.
Related
This is originally from HUAWEI Devloper Forum
Forum link: https://forums.developer.huawei.com/forumPortal/en/home
This article provides tips for integrating HUAWEI Windows Share Kit, with the goal of accelerating the integration process.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
As introduced in the Share Kit | Fully-Open HUAWEI Windows Share Kit Unveiled, Offering a New Paradigm for Phone-PC File Transfers, HUAWEI Windows Share Kit is designed to facilitate quick wireless transfers between Huawei phones and Windows PCs. By integrating Huawei Share capabilities into Windows PC apps, developers can facilitate high-speed file transfers between Huawei phones and Windows PCs.
Next, we'd like to share some tips for integrating HUAWEI Share Kit into Windows PC apps.
l Check whether your device meets the specification requirements. Currently, only devices that run Windows 10, and come in any of the following network adapters, are supported:
- Intel(R) Wi-Fi 6 AX201
- Intel Dual Band Wireless-AC 9560
- Intel Dual Band Wireless-AC 8275
- Intel Dual Band Wireless-AC 8265
- Intel Dual Band Wireless-AC 8260
l To determine whether your device's network adapter meets the requirements, check the network adapter ID. (In later versions, you can also do so by calling the specific API.)
Go to Start > Run, enter CMD, and click OK.
In the command prompt window, enter IPCONFIG /ALL and press Enter.
The 12-digit code displayed to the right of Physical Address is the ID of the network adapter on the computer.
Make sure that the compiler and compilation settings are consistent, as the APIs are provided using static linking, and message callback is implemented by directly exporting classes. Please remain aware of the scope of the exported class object, in order to prevent unnecessary breakdowns or API calling failures from occurring.
Folder-based sharing is currently not supported. An I/O error message will display when attempting to share folders. It is recommended that you display a message to warn the user in advance of this issue, when they select a folder to share.
The discovery module is based on Bluetooth BLE advertising. It discovers a target device (a Huawei phone) for file transmission by using the BLE advertising channel. In order to avoid unnecessary resource consumption, the advertising interval and time should be properly managed.
I did not know we could use Share kit with windows apps. This is a great tutorial.
More information like this, you can visit HUAWEI Developer Forum
Introduction
So you have built a wonderful application but how to test it.
Or do you want to test you application on a specific device.
Let us meet your new friendly developer tool HMS Toolkit. This tool provide us the functionality of Cloud Debugging.
HMS Toolkit Installation:
If you have not yet installed HMS Core Toolkit then please go to below link to download the latest version of it before proceeding further into the article.
https://developer.huawei.com/consumer/en/doc/development/Tools-Library/toolkit-download-0000001050148172
Once downloading is done for the plugin you can directly install it via Install Plugin from disk option.
After installation it should show like below.
By the time of writing this article the latest version was 3.0.1.300.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Let’s Start with Cloud Debugging
Step by step I will guide you on how you can use this tool to test and debug your application without a real Huawei Device.
Step 1: Go to HMS and click Cloud Debugging as shown below.
Cloud debugging needs a user login in order to provide access to real devices. Hence you will be redirected to a URL where you need to confirm your identity for a successful login.
Step 2: Login and allow the service.
Once the service is allowed you will get a success message and your android studio will get access to real remote devices.
Step 3: If this screen is not opened click on cloud debugging in right sidebar.
Filters are available as highlighted below to get a specific device.
You can also check the availability of device by checking Available Devices
Once the list of device is available choose any one and proceed.
Step 4: Below should be the result after filter selection. Click Run and start the device.
A device should appear which can be accessed by sidebar. Default testing time is 2 Hours but if your testing require more time you can choose the same device once again after it gets released automatically.
Step 5: Let us run one application to see how it is performing on Cloud Debugger.
Let us see what all configurable options are given to us with this cloud debugger.
Screen Resolution:
Different resolution for a device are mentioned.
My recommendation – If your internet connection is good then go for higher resolution.
Screen Size:
You can also control screen size between 75%, 100% and 125%. To do that see the below screenshot.
Apart from this all three navigation buttons are provided to you for better control.
Conclusion
I hope you this article had given some insights in cloud Debugging.
In case you face any issue in the installation process do comment.
PS: You can also use this while presenting your screen, it doesn’t consume resources like how android emulator would do.
References
Get Application Insights and start Improving your application in minutes using HMS Toolkit Cloud Testing
HMS Toolkit - Automatic HMS SDK Integration
HMS Toolkit Convertor - Your New Best Friend for Migration
Its very interesting tool but when am trying to connect through cloud debugging am get below error
Request remote service failed: error_code 30002, 暂无可用设备,请稍后再试
To enhance data security, we are planning to implement security hardening on HUAWEI Analytics servers on September 20, 2020. This may affect data logging of some Android apps.
To prevent the said problem, we have released HMS Core Analytics SDK 5.0.1.301 for you to test whether data logging of your app is functioning properly. You are advised to integrate the SDK as soon as possible and conduct a test.
If the test fails, please refer to the following FAQs for the solution:
Debugging problems:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/commissioning-faq-0000001050164019
Installation environment problems:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/environment-faq-0000001050162062
Performing the Upgrade
Change the SDK version to 5.0.1.301 in the build.grade file of your app.
Code:
implementation 'com.huawei.hms:hianalytics:5.0.1.301'
Testing the Data Logging Result
After upgrading the SDK, enable the debug mode to check whether your app data is logged successfully. The procedure is as follows:
1. Enable the debug mode.
Run the following command to enable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app package_name
Replace the package_name field in the command with your app package name.
2. Sign in to AppGallery Connect, go to HUAWEI Analytics > Management > App debugging, and check whether data has been logged.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
3. If no data has been logged, resolve the problem by referring to FAQs. If the problem persists, submit a trouble ticket online. We will contact you as soon as possible.
4. Disable the debug mode.
The debug mode remains active after being enabled. If app debugging is no longer needed, run the following command to disable the debug mode:
Code:
adb shell setprop debug.huawei.hms.analytics.app .none.
Thank you for your support for HUAWEI Analytics Kit.
To learn more, feel free to visit our official website at
https://developer.huawei.com/consumer/en/hms/huawei-analyticskit
For more details, you can go to:
Official website
Development Documentation page, to find the documents you need
Reddit to join our developer discussion
GitHub to download demos and sample codes
Stack Overflow to solve any integration problems
My app crashes and the error message "Time out waiting for process to appear on xxx" is displayed in Android Studio. What is the reason?
can we track Realtime data using cloud debugger?
Background
A developer team wants to integrate HUAWEI Out-of-App Purchases, allowing users to purchase a product on the app details page of a game on HUAWEI AppGallery. To use this mode, they need to deep link a user to the app details page, and pass the ID of the product for purchase..
Official documentation: https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/appgallerykit-devguide-game#h1-1589804284330
Let’s see how they achieved this.
Implementation
1. Activity Configuration in the Manifest File
The team added intent-filters for an activity of their game.
<data android:scheme=”agpms” androidath=”/product/pay” android:host=”com.sxx.huawei”/>
The assembled request URL is agpms://com.sxx.huawei/product/pay.
The official documentation describes the requirements on the link.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Sample code:
2. Code Implementation of Redirection (Opening a Deep Link from Another App)
HUAWEI AppGallery should be used for the testing. However, the team had not released the game on AppGallery, and they failed to find a test environment on the AppGallery side. So they turned to another app.
Java:
Intent intent = new Intent();
intent.setAction("com.google.open02");
intent.addCategory("android.intent.category.DEFAULT");
intent.setData(Uri.parse("agpms://com.sxx.huawei/product/pay?producid=TestProduct503"));
startActivity(intent);
agpms://com.sxx.huawei/product/pay?producid=TestProduct503
Generally, the parameter following a question mark (?) is in the format of key=value&key1=value1.
Sample code:
As shown in the sample code, the only parameter set is producid.
3. Parameter Parsing After Redirection to the Payment Page
If the details page has not been opened before the redirection, the onCreate method of the app activity needs to be called to obtain the intent object for data parsing.
If the details page has already been opened before the redirection, the onNewIntent method of the app activity needs to be called to obtain the intent object for data parsing.
Sample code:
After the team obtains the product ID from the parsed data, the HMS Core SDK displays the payment page.
FAQs
What should I do if I fail to open the payment page after configuring the deep link?
Generally, this problem is caused by the inconsistency between scheme, host, and path in the assembled URL and those in the configuration. You can perform a check by referring to the official documentation.
After an app is launched, the app update function checks whether there is a later version available on AppGallery. If so, a pop-up is displayed, asking the user whether to update the app.
After you have integrated Cocos SDKHub, the function will use the SDK to check for app updates.
If your joint operations game is rejected for not integrating the app update function, check this post.
Before you integrate the app update function, you need to integrate Cocos SDKHub. (Reference: Integrating HUAWEI Game Service Based on Cocos SDKHub — Integrating Cocos SDKHub)
After that, here’s how you integrate the function:
1.Add the following code by referring to the official document:
JavaScript:
checkUpdate:function(){
var params = {
"showUpdateDialog": "1",
"forceUpdate": "0"
}
console.log("checkAppUpdate button pressed");
sdkhub.getUserPlugin().callFuncWithParam("checkAppUpdate",params);// Call the checkAppUpdate API.
}
2. Associate the code with a specified button and select the checkUpdate method as the tap event.
3. If you see the error information informing you that the callFuncWithParam method is not found during a simulator test, just test the packaged file on a real device.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
4. If the following information is displayed,
the function is integrated.
XML:
D/jswrapper: JS: checkAppUpdate pressed
I/updatesdk: UpdateSDK version is: 2.0.6.302 ,flavor: envrelease ,pkgName: com.cocos2d.xxx
D/HwConnectivityServiceEx: set 10323 wlan0 value false
I/NetworkKit_a: 27569-28056|null|com.huawei.hms.framework.network.grs.a|a|22|get url from sp is not empty.
I/DeviceUtil: UpdateSDK Get url from GRS_SDK Success!https://store1.hispace.hicloud.com/hwmarket/api/
I/StoreTask: UpdateSDK call store responsecode: 200
If the function passes the real-device test, the error displayed in the simulator test may be caused by compatibility failure.
For a mobile game that needs to be forcibly updated, pay attention to:
1. Select Force update when editing information for the new game version in AppGallery Connect.
(See step 8 in the official document)
2. Set forceUpdate in the input parameters to 1.
This way, you have successfully integrated the app update function.
very useful writeup
Neha J said:
very useful writeup
Click to expand...
Click to collapse
Thank you for your liking.