It can be difficult for users to differentiate between legitimate URLs and malicious ones which attempt to trick them into transferring money or sharing personal details. To address this issue, HUAWEI Safety Detect provides a malicious URL check function (URLCheck) which helps developers identify the threats posed by malicious URLs.
I. Service Introduction
URLCheck's malicious URL check capability is reliable, easy to integrate, and free of maintenance. With this capability, creating a secure browsing service has never been cheaper or simpler.
Once you have integrated URLCheck into your app, the process of checking URLs is as follows.
{
"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"
}
(1) Your app has the Safety Detect SDK integrated and calls the URLCheck API.
(2) Safety Detect requests a URL check from the URLCheck server, and then sends back the check result to your app (normal URL, phishing URL, or malicious software URL).
(3) Your app can determine whether to access the URL based on the check result.
II. Scenarios
Developers in many industries have integrated URLCheck to identify risks posed by URLs accessed within their apps. This enables them to determine whether to block risky URLs based on the check result.
l URLCheck can help the app check whether the URL the user wants to access is secure, and determine whether to access the URL based on the check result.
l If the URL is risky, the app will show a security warning before enabling the user to access the URL.
III. Code Development
1 Configure app information in AppGallery Connect.
Before you start developing an app, configure app information in AppGallery Connect.
For more details about how to do this, take a look at our website.
2 Configure the Maven repository address for the HMS Core SDK.
2.1 Open the build.gradle file in the root directory of your Android Studio project.
2.2 Add the AppGallery Connect plug-in and the Maven repository.
· Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
1. allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
1. buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > dependencies and add dependency on the AppGallery Connect plug-in.
Code:
buildscript{
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
3 Add build dependencies in the dependencies section.
Code:
// Create a SafetyDetectClient instance.
SafetyDetectClient mClient = SafetyDetect.getClient(MainActivity.this);
4.1 Initialize URLCheck.
Code:
// Initialize URLCheck.
mClient.initUrlCheck();
4.2 Request a URL check.
Code:
client.urlCheck(url, appid, UrlCheckThreat.MALWARE)
.addOnSuccessListener(new OnSuccessListener<UrlCheckResponse>() {
@Override
public void onSuccess(UrlCheckResponse urlCheckerResponse) {
List<UrlCheckThreat> list = urlCheckerResponse.getUrlCheckResponse();
if (list.isEmpty()) {
// No threats detected.
} else {
// Threats detected.
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
if (e instanceof ApiException){
ApiException apiException = (ApiException) e;
} else {
// An unknown error occurred.
}
}
});
4.3 Shut down URLCheck.
Code:
// Shut down URLCheck.
mClient.shutdownUrlCheck();
Demo
URLCheck on HUAWEI Developers
Safety Detect Development Guide
Sample Code on GitHub
Stack Overflow (where you can ask more questions)
Related
More information like this, you can visit HUAWEI Developer Forum
This article is based on Nearby Chat. We will create a new application that provides the chat with nearby people without the internet with the help of Nearby Kit and we can share our current location in latitude and longitude.
We are going to integrate the following kits in this application.
1) Nearby Kit
2) Awareness Kit
3) Scan Kit
Prerequisite
1) Must have a Huawei Developer Account.
2) Must have a Huawei phone with HMS 4.0.0.300 or later.
3) Must have a laptop or desktop with Android Studio, JDK 1.8, SDK platform 26 and Gradle 4.6 installed.
Things Need To Be Done
1) Create a project in android studio.
2) Create a project in the Huawei AppGallery connect.
3) Enable Nearby, Awareness, and Scan kit setting in Manage APIs section.
4) Provide storage location.
5) After completing all the above points we need to download the agconnect-services.json from App Information Section. Copy and paste the Json file in the app folder of the android project.
6) Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file).
7) Add dependencies inside the app module and Sync Project.
8) Start development with kit integration inside the application.
9) Launch the application.
Create a project in Android Studio
Open your android studio and create a new project, Choose No Activity then click on Next
{
"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"
}
Provide your application name, package, and project location then click on Finish.
Create a project on AppGalleryConnect portal
1. Open AppGalleryConnect portal and choose My projects
2. Click on Add project and provide your project’s details
3. Provide your project name and click Ok
Provide storage location
Navigate to General Information then provide Data Storage location.
Enable Nearby, Awareness, and Scan kit setting in Manage APIs section
Navigate to Manage APIs and enable APIs which require by application
After completing all the above points we need to download the agconnect-services.json
Navigate to General information then download the agconnect-services.json file
Add agconnect-services.json file into your project
Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file)
Add maven url and add following AppGalleryConnect class path.
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Add dependencies inside the app module and Sync Project
Add the following dependencies for kit specific in app module based gradle file
Code:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Awareness Kit
implementation 'com.huawei.hms:awareness:1.0.6.300'
//Nearby Kit
implementation 'com.huawei.hms:nearby:4.0.4.300'
//Scan Kit
implementation "com.huawei.hms:scan:1.2.0.301"
}
Start development with kit integration inside the application
We have created the following package inside the project
Awareness
We have handled all the operations in this package which is related to awareness kit. We have created LocationAwarenessActivity which implements location-awareness api.
getLocation() method provides accurate latitude and longitude.
Code:
private void getLocation() {
Awareness.getCaptureClient(this).getLocation()
.addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(LocationResponse locationResponse) {
Location location = locationResponse.getLocation();
Utils.setHomeLatitude(location.getLatitude());
Utils.setHomeLongitude(location.getLongitude());
location_details_capture.setText("Capture Your Location
Longitude:" + location.getLongitude()
+ "
Latitude:" + location.getLatitude());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
location_details_capture.setText("Failed to get the location.");
}
});
}
This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201327967934830047&fid=0101188387844930001
Can we share media files also?
Easy-to-Integrate Huawei System Integrity Check – Helping You Protect Your Apps from Unsafe Devices
Running apps on an unsafe device, for example, a rooted or unlocked device, can pose serious security risks. On an unsafe device, viruses, Trojan horses, and other malicious software may exploit the root permission to implant viruses, tamper with device information, and damage the system. Therefore, there is a real need to protect your apps from being run on unsafe devices. To meet such a need, Huawei offers Safety Detect, which provides the SysIntegrity API for system integrity check. This API can check whether a device running your app is unsafe, for example, due to the device being rooted or unlocked.
I. Service Introduction
The SysIntegrity API has the following features:
1. TEE-based system integrity check results: The API evaluates the integrity of a system during its secure boot in the Trusted Execution Environment (TEE) and will dynamically evaluate the system integrity. The check results are highly reliable.
2. Secure and reliable system integrity check results: The system integrity check results are signed using the signing certificate and cannot be tampered with.
(1) The Safety Detect SDK integrated with your app calls the SysIntegrity API.
(2) Safety Detect requests the signed check results from the Trusted Security Management Service (TSMS) server.
(3) Your app requests the check results.
II. Scenarios
Currently, developers of apps in the finance, entertainment, lifestyle, news, and other categories have integrated the SysIntegrity API into their apps.
A financial app can integrate SysIntegrity to improve transaction security. For example, the app can check whether the device is secure when a user enters the Card Verification Code (CVC) of their credit card. If the device is unsafe, the app will be stopped on the device to ensure no unsafe transactions can occur.
{
"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"
}
A lifestyle or news app can integrate SysIntegrity to prevent malicious attacks, ensuring security of in-app operations such as payment.
A video entertainment app can integrate SysIntegrity to help protect copyrighted content. When a user registers an account on the app and watches or downloads video content, SysIntegrity can help ensure that this being done on a device that is trusted by the content provider.
III. Code Development
1 Configuring App Information in AppGallery Connect
Before you start developing an app, configure app information in AppGallery Connect.
For details, please visit https://developer.huawei.com/consumer/en/doc/HMSCore-Guides-V5/config-agc-0000001050416303-V5?ha_source=hms1
2 Configuring the Maven Repository Address for the HMS Core SDK
2.1 Open the build.gradle file in the root directory of your Android Studio project.
2.2 Add the AppGallery connect plug-in and the Maven repository.
Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
Go to buildscript > dependencies and add dependency configurations.
Code:
buildscript{
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
3 Creating a SafetyDetectClient Instance and Generating a Nonce Value
Code:
// Create a SafetyDetectClient instance.
SafetyDetectClient mClient = SafetyDetect.getClient(MainActivity.this);
// Generate a nonce value.
byte[] nonce = new byte[24];
try {
SecureRandom random;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
random = SecureRandom.getInstanceStrong();
} else {
random = SecureRandom.getInstance("SHA1PRNG");
}
random.nextBytes(nonce);
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, e.getMessage());
}
4 Creating a Check Result Listener
Code:
// Implement the OnSuccessListener API and obtain the check result from onSuccess
protected class SysIntegrityOnSuccessListener implements OnSuccessListener<SysIntegrityResp> {
// Obtain the system integrity check result.
@Override
public void onSuccess(SysIntegrityResp sysIntegrityResp) {
}
}
// Implement the OnFailureListener API and obtain the failure details from onFailure.
protected class SysIntegrityOnFailureListener implements OnFailureListener {
// Obtain the result code and description.
@Override
public void onFailure(Exception e) {
}
}
5 Calling the SysIntegrity API
Code:
// Call the SysIntegrity API. Replace ******** in the following code with your app ID.
Task task = mClient.sysIntegrity(nonce,"********");
task.addOnSuccessListener(new SysIntegrityOnSuccessListener()).addOnFailureListener(new SysIntegrityOnFailureListener());
6 Verifying the Check Results
For details about how to verify the check results on the server, please refer to relevant documents on the HUAWEI Developers website.
To find out more, visit the following links:
SysIntegrity API:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/dysintegritydevelopment-0000001050156331?ha_source=hms1
Safety Detect development guide:
https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/introduction-0000001050156325?ha_source=hms1
Demo and sample code on GitHub:
https://github.com/HMS-Core/hms-safetydetect-demo-android
Stack Overflow (for technical discussions):
https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest
When there are malicious apps on a device, they can put the user’s personal information and transactions at risk. This is why HUAWEI Safety Detect provides the malicious app detection (AppsCheck) API. It enables your app to obtain a list of malicious apps installed on the user’s device, and use this to determine whether to restrict functionality such as in-app payments.
I. Service Introduction
AppsCheck in Safety Detect features in the following:
1. Detects malicious apps with an accuracy rate of 99%, according to authority.
2. Detects unknown threats based on app behavior.
The figure below illustrates the process of checking for malicious apps.
{
"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"
}
(1) Your app, which has integrated the Safety Detect SDK, calls the AppsCheck API.
(2) The AppsCheck API returns a list of malicious apps to your app.
----End
II. Use Cases
All kinds of apps have integrated the AppsCheck API, including those in the fields of finance, tools, education, photography, news, media & entertainment. With this API, your app can obtain a list of malicious apps on the device running your app.
Example: When a user scans a QR code with your app to make a payment, your app will show the user a security warning if it detects any malicious apps on the user device.
Financial apps can integrate the AppsCheck API to ensure the security of user accounts. For example, when a user makes a payment in a financial app, the app will call the AppsCheck API to obtain a list of malicious apps on the user device. If any malicious apps are detected, the financial app will display a security warning and restrict the user's in-app operations. This means the app can protect the user's private information and finances.
Media & entertainment apps can integrate the AppsCheck API to ensure that videos are only played and downloaded on devices which do not contain any malicious apps. This prevents video piracy, makes apps more secure and efficient, and enables videos to run more smoothly.
News apps can integrate the AppsCheck API to ensure users’ accounts are secure when they read news stories or perform actions such as making in-app payments.
Demo video: Opening the demo app on a device with no malicious apps.
III. Development Procedure
1 Configuring App Information in AppGallery Connect
Before you start developing an app, configure the app information in AppGallery Connect.
For details about the procedure, please refer to HUAWEI Safety Detect Development Guide.
2 Configuring the Maven Repository Address for the HMS Core SDK
2.1 Opening the build.gradle File in the Root Directory of Your Android Studio Project
2.2 Adding the AppGallery Connect Plug-in and the Maven Repository
· Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
allprojects {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
· Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
Code:
<p style="line-height: 1.5em;">buildscript {
repositories {
google()
jcenter()
maven {url 'https://developer.huawei.com/repo/'}
}
}
</p>
· Go to buildscript > dependencies and add dependency on the AppGallery Connect plug-in.
Code:
<p style="line-height: 1.5em;">buildscript{
dependencies {
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
</p>
3. Creating a SafetyDetectClient Instance
Code:
<p style="line-height: 1.5em;">// Create a SafetyDetectClient instance.
SafetyDetectClient appsCheckClient = SafetyDetect.getClient(getActivity());
}
</p>
4. Calling the AppsCheck API and Listen for the Call Result
Code:
<p style="line-height: 1.5em;">Task task = appsCheckClient.getMaliciousAppsList();
task.addOnSuccessListener(new OnSuccessListener<MaliciousAppsListResp>() {
// Obtain the malicious app check result.
@Override
public void onSuccess (MaliciousAppsListResp maliciousAppsListResp) {
}
}).addOnFailureListener(new OnFailureListener() {
// Obtain the result code and description of an exception.
@Override
public void onFailure(Exception e) {
}
});
</p>
Demo
To find out more, visit the following links:
AppsCheck API
Safety Detect Development Guide
GitHub (where you can download the demo and sample code)
Stack Overflow (where you can ask questions)
Does it works offline ?
It's very nice and reassuring.
Outline
1. Background
2. Integration Preparations
3. Main Code
4. Results
I. Used Functions
Map Kit provides an SDK for map development. The map data covers over 200 countries and regions and supports hundreds of languages, allowing you to easily integrate map-related functions into your app for better user experience.
Keyword search: Searches for places like scenic spots, companies, and schools in the specified geographical area based on the specified keyword.
Route planning: Provides a set of HTTPS-based APIs used to plan routes for walking, cycling, and driving and calculate route distances. The APIs return route data in JSON format and provide the route planning capability.
II. Integration Preparations
1. Register as a developer and create a project in AppGallery Connect.
1) Register as a developer.
Click the following link to register as a Huawei developer:
https://developer.huawei.com/consumer/en/service/josp/agc/index.html?ha_source=hms1
{
"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"
}
2) Create an app, add the SHA-256 signing certificate fingerprint, enable Map Kit and Site Kit, and download the agconnect-services.json file of the app.
2. Integrate the Map SDK and Site SDK.
1) Copy the agconnect-services.json file to the app directory of the project.
· Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.
· Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK.
· If the agconnect-services.json file has been added to the app, go to buildscript > dependencies and add the AppGallery Connect plug-in configuration.
Code:
<p style="line-height: 1.5em;">buildscript {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
}
}
allprojects {
repositories {
maven { url 'https://developer.huawei.com/repo/' }
google()
jcenter()
}
}
</p>
2) Add build dependencies in the dependencies section.
Code:
<p style="line-height: 1.5em;">dependencies {
implementation 'com.huawei.hms:maps:{version}'
implementation 'com.huawei.hms:site:{version}'
}
</p>
3) Add the AppGallery Connect plug-in dependency to the file header.
Code:
<p style="line-height: 1.5em;">apply plugin: 'com.huawei.agconnect'
</p>
4) Copy the signing certificate generated in Generating a Signing Certificate to the app directory of your project, and configure the signing certificate in android in the build.gradle file.
Code:
<p style="line-height: 1.5em;">signingConfigs {
release {
// Signing certificate.
storeFile file("**.**")
// KeyStore password.
storePassword "******"
// Key alias.
keyAlias "******"
// Key password.
keyPassword "******"
v2SigningEnabled true
v2SigningEnabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable true
}
debug {
debuggable true
}
}
</p>
For more, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0202463432567010036
With the release of AppGallery Connect version 1.5.2 the Auth service now has full support for making use of unified sign-in with a Facebook account!
This new functionality makes AppGallery Connect Auth a great option for all of your app’s authentication needs both on Huawei devices and other Android devices.
So how do we go about using unified sign-in with a Facebook account? Let’s take a look!
Configuring the Facebook Login EnvironmentFirst, you’ll need to configure the Facebook Login environment.
Select or create a Facebook app.
{
"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"
}
Edit your resource file. Copy the following code to the /app/res/values/strings.xml file of your Android project.
Edit your manifest file. Add the following uses-permission element following the application element in the /app/manifest/AndroidManifest.xml file of your Android project.
Copy the following meta-data element to the application element.
Associate your package name and default activity class with your app and click Save. Confirm the use of this package name (skip this if your app has not been released on Google Play).
Develop a key hash using the following command, and release it for your app.
If you haven’t installed OpenSSL (openssl-for-windows) for your project, please go to Google Code Archive and download it as required.
keytool -exportcert -alias authdemounion -keystore F:\1.test\4.Auth\AuthDemo-Union\app\authdemounion.jks | openssl sha1 -binary | openssl base64
The command format is as follows:
keytool -exportcert -alias YOUR_RELEASE_KEY_ALIAS -keystore YOUR_RELEASE_KEY_PATH* | openssl sha1 -binary | openssl base64
The Facebook Login environment has now been successfully configured. Let’s move on to the operations relevant to Auth Service.
Enabling Auth ServiceSign in to AppGallery Connect, create a project and an app, and enable Auth Service. You’ll need to enter the App ID and App Secret for your app when enabling Facebook under Authentication modes, which can be found under Settings > Basic on Facebook for Developers. If they are not displayed, click the button following App Secret to show them.
Generating the Certificate Fingerprint for Your Android ProjectIf the demo project does not provide a Java KeyStore, go to Generate Signed Bundle or APK and click Create new.key store to create one
Generate an SHA-256 certificate fingerprint. Run the following command and enter the configured password to generate a SHA-256 certificate fingerprint.
keytool -list -v -keystore you_path\AuthDemo-Union\app\authdemounion.jks
Open the app-level build.gradle file, and configure the certificate information for your project
Click here to view the sample code.
Configure the generated SHA-256 certificate fingerprint in AppGallery Connect. (If you do not perform this step, error 6003 will be reported.)
Configure Your AppOpen the project-level build.gradle file and configure information, including the Maven repository address. The code is as follows:
Code:
buildscript {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' } // Configure this maven.
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.huawei.agconnect:agcp:1.5.1.300' // Configure this path.
// NOTE: Do not copy your dependencies in here, which should be included
// in the build.gradle files of each module.
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'http://developer.huawei.com/repo/' } // Configure this maven.
}
}
Open the app-level build.gradle file and configure information, including the SDK information and app plug-in address. The code is as follows:
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect' // Configure the apply plug-in.
android {…}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "com.huawei.agconnect:agconnect-auth-facebook:1.5.2.201" // Configure this SDK.
implementation 'com.huawei.agconnect:agconnect-auth:1.5.2.201' // Configure this SDK.
}
Add the code for implementing unified sign-in:
Java:
private void FaceBookLogin(){
Log.i("AuthDemo", "start:" );
AGConnectAuth.getInstance().signIn(this, AGConnectAuthCredential.Facebook_Provider)
.addOnSuccessListener(new OnSuccessListener<SignInResult>() {
@Override
public void onSuccess(SignInResult signInResult) {
// onSuccess
AGConnectUser user = signInResult.getUser();
Log.i("AuthDemo", "success:" + user);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
// onFail
Log.i("AuthDemo", "failed:" + e.getMessage());
}
});
}
// Activity lifecycle required by the unified sign-in.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
AGConnectApi.getInstance().activityLifecycle().onActivityResult(requestCode, resultCode, data);
Viewing the Result and LogsOnce you run your signed APK on an Android phone and call the FaceBookLogin method, you’ll get the following page.
You can tap CONTINUE AS LINKING and sign in to your app with your Facebook account. The following log information will be displayed.
Compared with the traditional implementation mode, the unified sign-in has greatly simplified the development process. It is strongly recommended that you use the new mode.
For details about Auth Service, please refer to:
Auth Service document for Android
Guide for integrating Facebook account
Thanks for sharing.