Hello, Habr! In May last year, left without Google services and APIs, we thoroughly started working on our Huawei Mobile Services platform . This is our long-standing project, to which we returned after the imposition of US sanctions. The problem of "cut off" services gradually faded away. We have added missing components: an email client, our own maps and other services, and HMS Core - a set of APIs, SDKs and other services for developing and improving applications. This set includes the Push Kit - a cloud-based notification service - and more. Under the cut, we will tell you how this tool works, how it stands out and how it can be used.
The main function of the Push Kit (we'll talk about the rest later) is to deliver notifications from applications to the user's device. This process is organized like this:
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 — , . : , , , -.