List of usage examples for android.content ComponentName getPackageName
public @NonNull String getPackageName()
From source file:com.atwal.wakeup.battery.util.Utilities.java
/** * Returns a widget with category {@link AppWidgetProviderInfo#WIDGET_CATEGORY_SEARCHBOX} * provided by the same package which is set to be global search activity. * If widgetCategory is not supported, or no such widget is found, returns the first widget * provided by the package./* w w w . j a v a 2 s . c o m*/ */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static AppWidgetProviderInfo getSearchWidgetProvider(Context context) { SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); ComponentName searchComponent = searchManager.getGlobalSearchActivity(); if (searchComponent == null) return null; String providerPkg = searchComponent.getPackageName(); AppWidgetProviderInfo defaultWidgetForSearchPackage = null; AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); for (AppWidgetProviderInfo info : appWidgetManager.getInstalledProviders()) { if (info.provider.getPackageName().equals(providerPkg)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { if ((info.widgetCategory & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) { return info; } else if (defaultWidgetForSearchPackage == null) { defaultWidgetForSearchPackage = info; } } else { return info; } } } return defaultWidgetForSearchPackage; }
From source file:com.facebook.login.LoginFragment.java
private void initializeCallingPackage(final Activity activity) { ComponentName componentName = activity.getCallingActivity(); if (componentName == null) { return;/*from w w w. ja v a 2s. c o m*/ } callingPackage = componentName.getPackageName(); }
From source file:com.tasomaniac.android.widget.IntegrationPreference.java
private Intent marketIntent(Intent originalIntent) { ComponentName component = originalIntent.getComponent(); if (component != null) { final String packageName = component.getPackageName(); Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName)); if (!hasIntent(marketIntent)) { marketIntent.setData(Uri.parse("https://play.google.com/store/apps/details?id=" + packageName)); }/*from w w w. jav a2s .c o m*/ if (hasIntent(marketIntent)) { return marketIntent; } } return null; }
From source file:de.luhmer.owncloudnewsreader.services.OwnCloudSyncService.java
private void finishedSync() { TeslaUnreadManager.PublishUnreadCount(this); WidgetProvider.UpdateWidget(this); syncRunning = false;/* www .ja v a2 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("de.luhmer.owncloudnewsreader")) { 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); } } List<IOwnCloudSyncServiceCallback> callbackList = getCallBackItemsAndBeginBroadcast(); for (IOwnCloudSyncServiceCallback icb : callbackList) { try { icb.finishedSync(); //icb.finishedSyncOfItems(); } catch (RemoteException e) { e.printStackTrace(); } } callbacks.finishBroadcast(); }
From source file:com.air.mobilebrowser.ActivityWatchService.java
/** * Hide any application that is in the foreground and is not * in the white-list, and collapse the status bar. *///w ww .j av a 2 s . co m private void hideApplications() { ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; String packageName = topActivity.getPackageName(); if (!packageName.equals(getPackageName()) && !mApplicationWhitelist.contains(packageName)) { //We hide the activity, by bringing the BrowserActivity back in front. Intent intent = new Intent(this, BrowserActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); //Visual indicator that we are hiding an app. Toast.makeText(this, "Blocked " + packageName, Toast.LENGTH_SHORT).show(); } } try { final Object service = getSystemService("statusbar"); Class<?> statusbarManager = Class.forName("android.app.StatusBarManager"); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN) { final Method collapse = statusbarManager.getMethod("collapse"); collapse.setAccessible(true); collapse.invoke(service); } else { final Method collapse = statusbarManager.getMethod("collapsePanels"); collapse.setAccessible(true); collapse.invoke(service); } } catch (Exception ex) { Log.e(TAG, "Failed to collapse status bar"); } List<RunningAppProcessInfo> appList = am.getRunningAppProcesses(); for (RunningAppProcessInfo info : appList) { am.killBackgroundProcesses(info.processName); } appList = am.getRunningAppProcesses(); for (RunningAppProcessInfo info : appList) { if (mAppBlacklist.contains(info.processName)) { Intent intent = new Intent(super.getResources().getString(R.string.intent_black_logtag)); LocalBroadcastManager.getInstance(super.getApplicationContext()).sendBroadcast(intent); } } }
From source file:com.arctech.gcm.MyGcmListenerService.java
public boolean checkApp() { ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); // get the info from the currently running task List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); // ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); // List<ActivityManager.RunningTaskInfo> services = activityManager // .getRunningTasks(Integer.MAX_VALUE); ComponentName componentInfo = taskInfo.get(0).topActivity; Log.i("Package Activity", " " + componentInfo.getPackageName()); Log.i("Class Activity", " " + componentInfo.getClassName()); if (componentInfo.getClassName().equalsIgnoreCase("com.arctech.stikyhive.StikyChatMoreActivity")) { Log.i(TAG, "Chat More Activity"); StikyChatMoreActivity.flagGCM = true; flagNoti = false;/* w w w .j a va2 s. c om*/ Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); return false; } else if (componentInfo.getClassName().equalsIgnoreCase("com.arctech.stikyhive.ChattingActivity")) { Log.i("TAG", componentInfo.getClass() + " "); Intent registrationComplete = new Intent(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete); return true; } else if (componentInfo.getPackageName() != "com.arctech.stikyhive") { flagNoti = true; return false; } else { flagNoti = false; return false; } }
From source file:com.openerp.services.ExpenseSyncService.java
/** * Perform sync.//from ww w .jav a 2 s . c om * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.d(TAG, "ExpenseSyncService->performSync()"); Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { ExpenseDBHelper expense_db = new ExpenseDBHelper(context); expense_db.setAccountUser(user); OEHelper oe = expense_db.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); //newContext.put("default_model", "res.users"); //newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : domain //OEDomain domain = new OEDomain(); //arguments.add(domain); // Param 2 : context arguments.add(oe.updateContext(newContext)); //??? List<Integer> ids = expense_db.ids(); if (oe.syncWithMethod("get_waiting_audit_expenses", arguments, true)) { int affected_rows = oe.getAffectedRows(); Log.d(TAG, "ExpenseSyncService[arguments]:" + arguments.toString()); Log.d(TAG, "ExpenseSyncService->affected_rows:" + affected_rows); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mainActiivty.setAction("EXPENSES"); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.expenses_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.expenses_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } //?expense? List<Integer> updated_ids = updateOldExpenses(expense_db, oe, user, ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); //context.sendBroadcast(updateWidgetIntent); } }
From source file:com.openerp.services.VoucherSyncService.java
/** * Perform sync.// ww w. j a v a2 s . co m * * @param context the context * @param account the account * @param extras the extras * @param authority the authority * @param provider the provider * @param syncResult the sync result */ public void performSync(Context context, Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) { Log.d(TAG, "VoucherSyncService->performSync()"); Intent intent = new Intent(); Intent updateWidgetIntent = new Intent(); updateWidgetIntent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.setAction(SyncFinishReceiver.SYNC_FINISH); OEUser user = OpenERPAccountManager.getAccountDetail(context, account.name); try { VoucherDB voucherDb = new VoucherDB(context); voucherDb.setAccountUser(user); OEHelper oe = voucherDb.getOEInstance(); if (oe == null) { return; } int user_id = user.getUser_id(); // Updating User Context for OE-JSON-RPC JSONObject newContext = new JSONObject(); //newContext.put("default_model", "res.users"); //newContext.put("default_res_id", user_id); OEArguments arguments = new OEArguments(); // Param 1 : domain OEDomain domain = new OEDomain(); //type = payment arguments.add(domain); // Param 2 : context arguments.add(oe.updateContext(newContext)); //??? List<Integer> ids = voucherDb.ids(); if (oe.syncWithMethod("get_waiting_audit_vouchers", arguments, true)) { int affected_rows = oe.getAffectedRows(); Log.d(TAG, "VoucherSyncService[arguments]:" + arguments.toString()); Log.d(TAG, "VoucherSyncService->affected_rows:" + affected_rows); List<Integer> affected_ids = oe.getAffectedIds(); boolean notification = true; ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; if (componentInfo.getPackageName().equalsIgnoreCase("com.openerp")) { notification = false; } if (notification && affected_rows > 0) { OENotificationHelper mNotification = new OENotificationHelper(); Intent mainActiivty = new Intent(context, MainActivity.class); mainActiivty.setAction("VOUCHERS"); mNotification.setResultIntent(mainActiivty, context); String notify_title = context.getResources().getString(R.string.vouchers_sync_notify_title); notify_title = String.format(notify_title, affected_rows); String notify_body = context.getResources().getString(R.string.vouchers_sync_notify_body); notify_body = String.format(notify_body, affected_rows); mNotification.showNotification(context, notify_title, notify_body, authority, R.drawable.ic_oe_notification); } intent.putIntegerArrayListExtra("new_ids", (ArrayList<Integer>) affected_ids); } //?expense? List<Integer> updated_ids = updateOldVouchers(voucherDb, oe, user, ids); } catch (Exception e) { e.printStackTrace(); } if (user.getAndroidName().equals(account.name)) { context.sendBroadcast(intent); //context.sendBroadcast(updateWidgetIntent); } }
From source file:edu.umich.oasis.sandbox.SandboxContext.java
@Override public boolean bindService(Intent service, ServiceConnection conn, int flags) { ComponentName component = service.getComponent(); if (component != null && component.getPackageName().equals(BuildConfig.APPLICATION_ID) && component.getClassName().equals(OASISService.class.getName())) { IBinder rootBinder = mRootService.asBinder(); ComponentName oldMapping;// www. j a va 2 s . c o m synchronized (mBoundServices) { oldMapping = mBoundServices.put(conn, component); } if (oldMapping == null) { conn.onServiceConnected(component, rootBinder); } return true; } return super.bindService(service, conn, flags); }
From source file:com.stikyhive.gcm.MyGcmListenerService.java
public boolean checkApp() { ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(ACTIVITY_SERVICE); // get the info from the currently running task List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1); // ActivityManager activityManager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE); // List<ActivityManager.RunningTaskInfo> services = activityManager // .getRunningTasks(Integer.MAX_VALUE); ComponentName componentInfo = taskInfo.get(0).topActivity; Log.i("Package Activity", " " + componentInfo.getPackageName()); Log.i("Class Activity", " " + componentInfo.getClassName()); if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.StikyChatMoreActivity")) { Log.i(TAG, "Chat More Activity"); StikyChatMoreActivity.flagGCM = true; flagNoti = false;/*from w w w . j av a2 s . c o m*/ Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete); return false; } else if (componentInfo.getClassName().equalsIgnoreCase("com.stikyhive.stikyhive.ChattingActivity")) { Log.i("TAG", componentInfo.getClass() + " "); Intent registrationComplete = new Intent(QuickstartPreferences.CHAT_REGISTRATION_COMPLETE); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(registrationComplete); return true; } else if (componentInfo.getPackageName() != "com.stikyhive.stikyhive") { flagNoti = true; return false; } else { flagNoti = false; return false; } }