22package me .youchai .rnpush .mipush ;
33
44import android .content .Context ;
5+ import android .content .pm .ApplicationInfo ;
6+ import android .content .pm .PackageManager ;
7+ import android .os .Bundle ;
8+ import android .util .Log ;
9+
510import com .facebook .react .bridge .ReactApplicationContext ;
611
712import com .xiaomi .mipush .sdk .MiPushClient ;
1116import me .youchai .rnpush .Notification ;
1217import me .youchai .rnpush .PushService ;
1318import me .youchai .rnpush .utils .Logger ;
14- import me .youchai .rnpush .R ;
1519
1620public class MiPushService extends PushService {
1721 private ReactApplicationContext _rac ;
@@ -22,9 +26,17 @@ public MiPushService(ReactApplicationContext rac) {
2226
2327 @ Override
2428 public void init () {
25- String appkey = _rac .getString (R .string .mipush_appkey );
26- String appid = _rac .getString (R .string .mipush_appid );
27- MiPushClient .registerPush (_rac , appkey , appid );
29+ try {
30+ ApplicationInfo ai = _rac .getPackageManager ()
31+ .getApplicationInfo (_rac .getPackageName (), PackageManager .GET_META_DATA );
32+ Bundle bundle = ai .metaData ;
33+ String appid = bundle .getString ("MIPUSH_APPID" , null );
34+ String appkey = bundle .getString ("MIPUSH_APPKEY" , null );
35+ Logger .i (appid + " - " + appkey );
36+ MiPushClient .registerPush (_rac , appkey , appid );
37+ } catch (PackageManager .NameNotFoundException e ) {
38+ Logger .i ("cannot read metadata" );
39+ }
2840 }
2941
3042 @ Override
0 commit comments