华为的Push Kit如何工作

哈Ha!去年5月,在没有Google服务和API的情况下,我们彻底着手准备在华为移动服务平台上工作这是我们的长期项目,在美国实施制裁之后,我们回到了这个项目。“切断”服务的问题逐渐消失。我们添加了缺少的组件:电子邮件客户端,我们自己的地图和其他服务以及HMS Core-一组用于开发和改进应用程序的API,SDK和其他服务。该套件包括Push Kit(基于云的通知服务)等。切入后,我们将告诉您该工具的工作原理,突出的特点以及使用方法。

Push Kit的主要功能(我们将在后面讨论其余部分)是将通知从应用程序传递到用户的设备。这个过程是这样组织的:

  • 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