List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:com.example.finalfcm.MyFirebaseMessagingService.java
private boolean isAppIsInBackground(Context context) { boolean isInBackground = true; ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) { List<ActivityManager.RunningAppProcessInfo> runningProcesses = am.getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo processInfo : runningProcesses) { if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { for (String activeProcess : processInfo.pkgList) { if (activeProcess.equals(context.getPackageName())) { isInBackground = false; }// w w w . j a va 2 s.c o m } } } } else { List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equals(context.getPackageName())) { isInBackground = false; } } return isInBackground; }
From source file:com.google.android.apps.muzei.SourcePackageChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null || intent.getData() == null) { return;/*from w w w .j a v a 2s . c o m*/ } String packageName = intent.getData().getSchemeSpecificPart(); SourceManager sourceManager = SourceManager.getInstance(context); ComponentName selectedComponent = sourceManager.getSelectedSource(); if (!TextUtils.equals(packageName, selectedComponent.getPackageName())) { return; } try { context.getPackageManager().getServiceInfo(selectedComponent, 0); } catch (PackageManager.NameNotFoundException e) { LOGI(TAG, "Selected source no longer available; switching to default."); sourceManager.selectDefaultSource(); return; } // Some other change. LOGI(TAG, "Source package changed or replaced. Re-subscribing."); sourceManager.subscribeToSelectedSource(); }
From source file:com.battlelancer.seriesguide.extensions.ExtensionPackageChangeReceiver.java
@Override public void onReceive(Context context, Intent intent) { if (intent == null || intent.getData() == null) { return;//from ww w . jav a 2 s .c o m } String changedPackage = intent.getData().getSchemeSpecificPart(); ExtensionManager extensionManager = ExtensionManager.getInstance(context); List<ComponentName> enabledExtensions = extensionManager.getEnabledExtensions(); int affectedExtensionIndex = -1; for (int i = 0; i < enabledExtensions.size(); i++) { ComponentName componentName = enabledExtensions.get(i); if (TextUtils.equals(changedPackage, componentName.getPackageName())) { affectedExtensionIndex = i; break; } } if (affectedExtensionIndex == -1) { return; } // temporarily unsubscribe from extension ComponentName changedExtension = enabledExtensions.remove(affectedExtensionIndex); extensionManager.setEnabledExtensions(enabledExtensions); try { context.getPackageManager().getServiceInfo(changedExtension, 0); } catch (PackageManager.NameNotFoundException e) { Timber.i(e, "Extension no longer available: removed"); return; } // changed or updated Timber.i("Extension package changed or replaced: re-subscribing"); enabledExtensions.add(affectedExtensionIndex, changedExtension); extensionManager.setEnabledExtensions(enabledExtensions); }
From source file:com.entropy.promoenginedemoapp.gcm.MyGcmListenerService.java
private boolean isApplicationSentToBackground(final Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(context.getPackageName())) { return true; }//from ww w . j a v a 2 s . c o m } return false; }
From source file:eu.pinnoo.garbagecalendar.ui.AbstractSherlockActivity.java
protected int getVersionCode() { try {/*from w w w .j av a 2s. co m*/ ComponentName componentName = new ComponentName(this, AbstractSherlockActivity.class); PackageInfo info = getPackageManager().getPackageInfo(componentName.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { return 0; } }
From source file:eu.pinnoo.garbagecalendar.ui.AbstractSherlockListActivity.java
protected int getVersionCode() { try {//from w w w. j a va 2 s .c o m ComponentName componentName = new ComponentName(this, AbstractSherlockListActivity.class); PackageInfo info = getPackageManager().getPackageInfo(componentName.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { return 0; } }
From source file:eu.pinnoo.garbagecalendar.ui.AbstractSherlockPreferenceActivity.java
protected int getVersionCode() { try {/*from ww w . j a va2 s . c o m*/ ComponentName componentName = new ComponentName(this, AbstractSherlockPreferenceActivity.class); PackageInfo info = getPackageManager().getPackageInfo(componentName.getPackageName(), 0); return info.versionCode; } catch (PackageManager.NameNotFoundException e) { return 0; } }
From source file:net.bither.AndroidImplAbstractApp.java
@Override public ISetting initSetting() { return new ISetting() { @Override/*from w w w . j a va 2 s. c o m*/ public BitherjSettings.AppMode getAppMode() { return AppSharedPreference.getInstance().getAppMode(); } @Override public boolean getBitherjDoneSyncFromSpv() { return AppSharedPreference.getInstance().getBitherjDoneSyncFromSpv(); } @Override public void setBitherjDoneSyncFromSpv(boolean isDone) { AppSharedPreference.getInstance().setBitherjDoneSyncFromSpv(isDone); } @Override public BitherjSettings.TransactionFeeMode getTransactionFeeMode() { return AppSharedPreference.getInstance().getTransactionFeeMode(); } @Override public BitherjSettings.ApiConfig getApiConfig() { return AppSharedPreference.getInstance().getApiConfig(); } @Override public File getPrivateDir(String dirName) { File file = BitherApplication.mContext.getDir(dirName, Context.MODE_PRIVATE); if (!file.exists()) { file.mkdirs(); } return file; } @Override public boolean isApplicationRunInForeground() { if (BitherApplication.mContext == null) { return false; } ActivityManager am = (ActivityManager) BitherApplication.mContext .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (tasks != null && !tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(BitherApplication.mContext.getPackageName())) { return false; } } return true; } @Override public QRCodeUtil.QRQuality getQRQuality() { return AppSharedPreference.getInstance().getQRQuality(); } @Override public boolean getDownloadSpvFinish() { return AppSharedPreference.getInstance().getDownloadSpvFinish(); } @Override public void setDownloadSpvFinish(boolean finish) { AppSharedPreference.getInstance().setDownloadSpvFinish(finish); } @Override public CookieStore getCookieStore() { return PersistentCookieStore.getInstance(); } }; }
From source file:com.quarterfull.newsAndroid.services.OwnCloudSyncService.java
private void finishedSync() { TeslaUnreadManager.PublishUnreadCount(this); WidgetProvider.UpdateWidget(this); syncRunning = false;//from w w w .ja va 2 s . c om syncStopWatch.stop(); Log.v(TAG, "Time needed (synchronization): " + syncStopWatch.toString()); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this); int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0); if (newItemsCount > 0) { ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1); ComponentName componentInfo = runningTaskInfo.get(0).topActivity; if (!componentInfo.getPackageName().equals("com.quarterfull.newsAndroid")) { Resources res = getResources(); String tickerText = res.getQuantityString(R.plurals.notification_new_items_ticker, newItemsCount, newItemsCount); String contentText = res.getQuantityString(R.plurals.notification_new_items_text, newItemsCount, newItemsCount); String title = getString(R.string.app_name); if (mPrefs.getBoolean(SettingsActivity.CB_SHOW_NOTIFICATION_NEW_ARTICLES_STRING, true))//Default is true NotificationManagerNewsReader.getInstance(OwnCloudSyncService.this).ShowMessage(title, tickerText, contentText); } } EventBus.getDefault().post(new SyncFinishedEvent()); }
From source file:org.mariotaku.twidere.util.ExternalThemeManager.java
public void reloadEmojiPreferences() { final String emojiComponentName = preferences.getString(KEY_EMOJI_SUPPORT, null); if (emojiComponentName != null) { final ComponentName componentName = ComponentName.unflattenFromString(emojiComponentName); if (componentName != null) { emojiPackageName = componentName.getPackageName(); } else {//from www. j av a 2s. c o m emojiPackageName = null; } } else { emojiPackageName = null; } initEmojiSupport(); }