PushState.uts 1.3 KB
Newer Older
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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;
	}
}