Cómo funciona el Push Kit de Huawei

¡Hola, Habr! En mayo del año pasado, sin las API ni los servicios de Google, nos pusimos manos a la obra en nuestra plataforma de servicios móviles de Huawei . Este es nuestro proyecto de larga data, al que volvimos después de la imposición de sanciones estadounidenses. El problema de los servicios "cortados" se fue desvaneciendo gradualmente. Hemos agregado componentes faltantes: un cliente de correo electrónico, nuestros propios mapas y otros servicios, y HMS Core, un conjunto de API, SDK y otros servicios para desarrollar y mejorar aplicaciones. Este conjunto incluye Push Kit, un servicio de notificación basado en la nube y más. Debajo del corte, te contamos cómo funciona esta herramienta, en qué se destaca y cómo se puede utilizar.

La función principal del Push Kit (del resto hablaremos más adelante) es enviar notificaciones de las aplicaciones al dispositivo del usuario. Este proceso está organizado así:

  • 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- .

Android. iOS - -.

:

  • AppGallery Connect Android Studio;

  • SHA-256;

  • ;

  • AppGallery Connect;

  • Maven build.gradle.

, , .

: Push Kit -, Android. , Quick Apps — , , 12 . AppGallery Push Kit.

Push Kit, . , , WebPush iOS.

, .

, . , , .

HMS Core SDK

AppGallery Connect.

  1. AppGallery Connect My project.

  2. , HMS Core SDK.

  3. Project Setting → General information. App information agconnect-services.json.

  4. 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 — , . : , , , -.




All Articles