下面列出了com.facebook.react.bridge.ReactApplicationContext#getPackageName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean isAppOnForeground(ReactApplicationContext context) {
/**
* We need to check if app is in foreground otherwise the app will crash.
* http://stackoverflow.com/questions/8489993/check-android-application-is-in-foreground-or-not
**/
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
final String packageName = context.getPackageName();
for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
if (appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
&& appProcess.processName.equals(packageName)) {
return true;
}
}
return false;
}
public InCallManagerModule(ReactApplicationContext reactContext) {
super(reactContext);
mPackageName = reactContext.getPackageName();
reactContext.addLifecycleEventListener(this);
mWindowManager = (WindowManager) reactContext.getSystemService(Context.WINDOW_SERVICE);
mPowerManager = (PowerManager) reactContext.getSystemService(Context.POWER_SERVICE);
audioManager = ((AudioManager) reactContext.getSystemService(Context.AUDIO_SERVICE));
audioUriMap = new HashMap<String, Uri>();
audioUriMap.put("defaultRingtoneUri", defaultRingtoneUri);
audioUriMap.put("defaultRingbackUri", defaultRingbackUri);
audioUriMap.put("defaultBusytoneUri", defaultBusytoneUri);
audioUriMap.put("bundleRingtoneUri", bundleRingtoneUri);
audioUriMap.put("bundleRingbackUri", bundleRingbackUri);
audioUriMap.put("bundleBusytoneUri", bundleBusytoneUri);
mRequestPermissionCodePromises = new SparseArray<Promise>();
mRequestPermissionCodeTargetPermission = new SparseArray<String>();
mOnFocusChangeListener = new OnFocusChangeListener();
bluetoothManager = AppRTCBluetoothManager.create(reactContext, this);
proximityManager = InCallProximityManager.create(reactContext, this);
wakeLockUtils = new InCallWakeLockUtils(reactContext);
Log.d(TAG, "InCallManager initialized");
}
public NotificationModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
//this.reactContext.addActivityEventListener(this);
reactContext.addActivityEventListener(this);
thisApp = reactContext.getPackageName();
smsApp = getDefaultSmsPackage();
//Log.d(TAG, "sms app: "+SmsApp);
}
public Class getMainActivityClass(ReactApplicationContext context) {
String packageName = context.getPackageName();
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName();
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
public MusicControlNotification(MusicControlModule module, ReactApplicationContext context) {
this.context = context;
this.module = module;
Resources r = context.getResources();
String packageName = context.getPackageName();
// Optional custom icon with fallback to the play icon
smallIcon = r.getIdentifier("music_control_icon", "drawable", packageName);
if (smallIcon == 0) smallIcon = r.getIdentifier("play", "drawable", packageName);
}
public RNTesseractOcrModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
if (!this.DATA_PATH.contains(reactContext.getPackageName()))
this.DATA_PATH += reactContext.getPackageName() + File.separator;
}
public MusicControlReceiver(MusicControlModule module, ReactApplicationContext context) {
this.module = module;
this.packageName = context.getPackageName();
this.reactContext = context;
}