import Context from 'android.content.Context'; import PackageManager from 'android.content.pm.PackageManager'; import Bundle from 'android.os.Bundle'; import TextUtils from 'android.text.TextUtils'; export class PushState { private static sMetaDatas : Bundle | null = null static getAutoNotification() : boolean { const context = UTSAndroid.getAppContext() as Context const sp = context.getSharedPreferences("push_db_name", Context.MODE_PRIVATE) const autoNotification = this.getMetaValue(context, "dcloud_unipush_auto_notification") let needPush = true if (autoNotification != null) { if (!autoNotification.equals("ture", true)) { needPush = false; } } needPush = sp.getBoolean("auto_notification", needPush); return needPush } private static getMetaValue(context : Context, metaKey : string) : string | null { if (this.sMetaDatas == null) { try { this.sMetaDatas = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData; } catch (e : Exception) { e.printStackTrace(); return null; } } if (this.sMetaDatas != null) { const value = this.sMetaDatas!!.get(metaKey) if (value != null && !TextUtils.isEmpty(value as string)) { return value as string; } } return null; } }