String tag = "wake:" + comp.flattenToShortString(); PowerManager.WakeLock wakeLock = acquireWakeLock(context, tag, TimeUnit.MINUTES.toMillis(3)); if (wakeLock != null) {
@Override public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { Intent intent1 = new Intent(INTENT_SET_NOTIFICATION); boolean intent1Success; intent1.putExtra(EXTRA_COMPONENT, componentName.flattenToShortString()); intent1.putExtra(EXTRA_COUNT, badgeCount); Intent intent = new Intent(INTENT_UPDATE_SHORTCUT); boolean intentSuccess; intent.putExtra(PACKAGENAME, componentName.getPackageName()); intent.putExtra(COUNT, badgeCount); try { BroadcastHelper.sendIntentExplicitly(context, intent1); intent1Success = true; } catch (ShortcutBadgeException e) { intent1Success = false; } try { BroadcastHelper.sendIntentExplicitly(context, intent); intentSuccess = true; } catch (ShortcutBadgeException e) { intentSuccess = false; } if (!intent1Success && !intentSuccess) { throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); } }
b.append("cmp=").append(mComponent.flattenToShortString());
private synchronized void saveSubscriptions() { Set<String> serializedSubscriptions = new HashSet<>(); for (ComponentName subscriber : subscribers.keySet()) { serializedSubscriptions.add(subscriber.flattenToShortString() + "|" + subscribers.get(subscriber)); } sharedPrefs.edit().putStringSet(PREF_SUBSCRIPTIONS, serializedSubscriptions).apply(); }
protected static String getResourceFilename(ComponentName component) { return component.flattenToShortString(); } }
public static String getVoiceSearchIMId(Context context){ ComponentName voiceInputComponent = new ComponentName("com.google.android.voicesearch", "com.google.android.voicesearch.ime.VoceInputMethdServce"); if(DEBUG) Log.i(TAG, "getVoiceSearchIMId(), Comonent name = " + voiceInputComponent.flattenToString() + ", id = " + voiceInputComponent.flattenToShortString()); return voiceInputComponent.flattenToShortString(); }
private static String getResourceFilename(ComponentName component) { String resourceName = component.flattenToShortString(); String filename = resourceName.replace(File.separatorChar, '_'); return RESOURCE_FILE_PREFIX + filename; } }
public static String getLIMEID(Context context){ ComponentName LIMEComponentName = new ComponentName(context, LIMEService.class); return LIMEComponentName.flattenToShortString(); }
Intent updateIntent = new Intent("com.htc.launcher.action.UPDATE_SHORTCUT"); updateIntent.putExtra("packagename", packageName); updateIntent.putExtra("count", number); this.sendBroadcast(updateIntent); Intent setNotificationIntent = new Intent("com.htc.launcher.action.SET_NOTIFICATION"); ComponentName localComponentName = new ComponentName(packageName, className); setNotificationIntent.putExtra("com.htc.launcher.extra.COMPONENT", localComponentName.flattenToShortString()); setNotificationIntent.putExtra("com.htc.launcher.extra.COUNT", number); this.sendBroadcast(setNotificationIntent);
/** * Create and return an Intent that can launch the voice search activity for web search. */ private Intent createVoiceWebSearchIntent(Intent baseIntent, SearchableInfo searchable) { Intent voiceIntent = new Intent(baseIntent); ComponentName searchActivity = searchable.getSearchActivity(); voiceIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, searchActivity == null ? null : searchActivity.flattenToShortString()); return voiceIntent; }
public static void createLauncherIcon(Context context, ComponentName activity, String name, BitmapDrawable icon) { Toast.makeText(context, String.format(context.getText(R.string.creating_activity_shortcut).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show(); Intent shortcutIntent = new Intent(); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getActivityIntent(activity)); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); Bitmap bm = icon.getBitmap(); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bm); shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(shortcutIntent); //finish(); }
public static void launchActivity(Context context, ComponentName activity) { Intent intent = LauncherIconCreator.getActivityIntent(activity); Toast.makeText(context, String.format(context.getText(R.string.starting_activity).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show(); try { context.startActivity(intent); } catch(Exception e) { Toast.makeText(context, context.getText(R.string.error).toString() + ": " + e.toString(), Toast.LENGTH_LONG).show(); } } }
public static void createLauncherIcon(Context context, ComponentName activity, String name, String icon_resource_name) { Toast.makeText(context, String.format(context.getText(R.string.creating_activity_shortcut).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show(); Intent shortcutIntent = new Intent(); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getActivityIntent(activity)); shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); Intent.ShortcutIconResource ir = new Intent.ShortcutIconResource(); ir.packageName = activity.getPackageName(); ir.resourceName = icon_resource_name; shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ir); shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); context.sendBroadcast(shortcutIntent); //finish(); }
@Thunk private void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) { ContentValues values = new ContentValues(); values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString()); values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user)); values.put(CacheDb.COLUMN_SIZE, key.size); values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); mDb.insertOrReplace(values); }
@Thunk void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) { ContentValues values = new ContentValues(); values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString()); values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user)); values.put(CacheDb.COLUMN_SIZE, key.size); values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); mDb.insertOrReplace(values); }
@Thunk void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) { ContentValues values = new ContentValues(); values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString()); values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user)); values.put(CacheDb.COLUMN_SIZE, key.size); values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); mDb.insertOrReplace(values); }
@Override public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException { Intent intent1 = new Intent(INTENT_SET_NOTIFICATION); intent1.putExtra(EXTRA_COMPONENT, componentName.flattenToShortString()); intent1.putExtra(EXTRA_COUNT, badgeCount); Intent intent = new Intent(INTENT_UPDATE_SHORTCUT); intent.putExtra(PACKAGENAME, componentName.getPackageName()); intent.putExtra(COUNT, badgeCount); if(BroadcastHelper.canResolveBroadcast(context, intent1) || BroadcastHelper.canResolveBroadcast(context, intent)) { context.sendBroadcast(intent1); context.sendBroadcast(intent); } else { throw new ShortcutBadgeException("unable to resolve intent: " + intent.toString()); } }
@Thunk void writeToDb(WidgetCacheKey key, long[] versions, Bitmap preview) { ContentValues values = new ContentValues(); values.put(CacheDb.COLUMN_COMPONENT, key.componentName.flattenToShortString()); values.put(CacheDb.COLUMN_USER, mUserManager.getSerialNumberForUser(key.user)); values.put(CacheDb.COLUMN_SIZE, key.size); values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); try { mDb.getWritableDatabase().insertWithOnConflict(CacheDb.TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE); } catch (SQLException e) { Log.e(TAG, "Error saving image to DB", e); } }
@Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { ComponentName componentName = new ComponentName( event.getPackageName().toString(), event.getClassName().toString() ); ActivityInfo activityInfo = tryGetActivity(componentName); boolean isActivity = activityInfo != null; if (isActivity) { Log.i("CurrentActivity", componentName.flattenToShortString()); } } }
private void testNextStartedActivity(Activity activity, String nextActivity) { ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); ComponentName name = startedIntent.getComponent(); assertNotNull(name); assertEquals(nextActivity, name.flattenToShortString()); Bundle bundle = startedIntent.getExtras(); assertNull(bundle); }