Olá, Habr! Em maio do ano passado, sem os serviços e APIs do Google, começamos a trabalhar em nossa plataforma Huawei Mobile Services . Este é o nosso projeto de longa data, ao qual voltamos após a imposição das sanções americanas. O problema do "corte" dos serviços foi desaparecendo gradualmente. Adicionamos componentes que faltam: um cliente de e-mail, nossos próprios mapas e outros serviços, e HMS Core - um conjunto de APIs, SDKs e outros serviços para desenvolver e melhorar aplicativos. Este conjunto inclui o Push Kit - um serviço de notificação baseado em nuvem - e muito mais. Abaixo do corte, mostraremos como essa ferramenta funciona, como ela se destaca e como pode ser usada.

A principal função do Push Kit (falaremos sobre o resto mais tarde) é entregar notificações de aplicativos para o dispositivo do usuário. Este processo é organizado assim:
API- Push Kit ;
Push Kit .
, Push Kit :

, Huawei Analytics Kit;
- , ;
- AppGallery Connect.
Push Kit HTTPS;
- , Android-;
- Android/iOS -;
- ;
– , - - .

Push Kit
Push Kit , . «», - . , , , VoIP. , , , .
- -, Push Kit. , , . . , , — , , .

- , — . 24 - EMUI 10 49 EMUI 9. , .

, Push Kit, 128 , 4 .
, , 1 . , Push Kit , .
Push Kit
Push Kit . , . , — . , .
Push Kit : (NC), . Push Service. , , .

: Push Service , .
Push Kit , . 99 % 10 , . , , .

Push Service EMUI, .
« » Huawei EMUI 4 EMUI 5. , HMS Core, , Huawei Push Kit. , - .
Push Kit , React Native, Cordova, Xamarin Flutter. , iOS, Android, SDK.
Push Kit , . . , SMS , .

Push Kit , . Push Kit — 200 , .

Push Kit:
, Huawei Developers. :
Windows Java JDK 1.8, Android Studio Android SDK;
Huawei USB- HMS Core 4- .

:
AppGallery Connect Android Studio;
SHA-256;
;
AppGallery Connect;
Maven build.gradle.
: Push Kit -, Android. , Quick Apps — , , 12 . AppGallery Push Kit.
, .
, . , , .
HMS Core SDK
AppGallery Connect.
AppGallery Connect My project.
, HMS Core SDK.
Project Setting → General information. App information agconnect-services.json.
agconnect-services.json Android Studio.

. build.gradle .

dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// Add the following line
implementation 'com.huawei.hms:push:5.0.0.300'
}5.0.0.300 HMS Core Push SDK.
Sync Now, build.gradle.


synced successfully, .
Manifest
push , Push Kit, AndroidManifest.xml. MyPushService, HmsMessageService.
<service
android:name=".MyPushService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>MyPushService android: name = ". MyPushService" , HmsMessageService. .
proguard-rules.pro Android Studio. , HMS Core SDK.
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}AndResGuard, c .
"R.string.agc*",
"R.string.hms*",
"R.string.connect_server_fail_prompt_toast",
"R.string.getting_message_fail_prompt_toast",
"R.string.no_available_network_prompt_toast",
"R.string.third_app_*",
"R.string.upsdk_*",
"R.layout.hms*",
"R.layout.upsdk_*",
"R.drawable.upsdk*",
"R.color.upsdk*",
"R.dimen.upsdk*",
"R.style.upsdk*".
Android Studio, TextView MainActivity, . , MainActivity, TextView.
public class MainActivity extends AppCompatActivity {
private TextView tvToken;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvToken = findViewById(R.id.tv_log);
MyReceiver receiver = new MyReceiver();
IntentFilter filter=new IntentFilter();
filter.addAction("com.huawei.codelabpush.ON_NEW_TOKEN");
MainActivity.this.registerReceiver(receiver,filter);
}
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if ("com.huawei.codelabpush.ON_NEW_TOKEN".equals(intent.getAction())) {
String token = intent.getStringExtra("token");
tvToken.setText(token);
}
}
}
}<meta-data> AndroidManifest.xml.
<application
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
</application>Name value meta-data . Push SDK .
onNewToken thMyPushService*ce class.
MyPushService.java
public class MyPushService extends HmsMessageService {
private static final String TAG = "PushDemoLog";
@Override
public void onNewToken(String token) {
super.onNewToken(token);
Log.i(TAG, "receive token:" + token);
sendTokenToDisplay(token);
}
private void sendTokenToDisplay(String token) {
Intent intent = new Intent("com.huawei.push.codelab.ON_NEW_TOKEN");
intent.putExtra("token", token);
sendBroadcast(intent);
}
}MyPushService HmsMessageService. , , - — onNewToken.
,
Huawei .
1. Play ( ), . APK .
2. Android Studio, APK.
ADB, APK .
adb install D:\WorkSpace\CodeLab\pushdemo1\app\release\app-release.apk, . onNewToken AFcSAHhhnxdrMCYBxth2QOG9IgY2VydAM61DTThqNux3KBC_hgzQQT *******.
. , PushDemoLog.
-
Push Kit AppGallery Connect , . . APK — com.huawei.codelabpush. .
, .
Push Kit
.
, Push Kit, mfms°: - , -, .
, . SMS, : SDK, mfms°, APNs, FCM Huawei Push Kit « ».
. Push Kit mfms° , . SDK SMS . , mfms° , , .
- Push Kit — , . : , , , -.