List of usage examples for android.content ComponentName unflattenFromString
public static @Nullable ComponentName unflattenFromString(@NonNull String str)
From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.N_MR1)//from w w w . j av a2 s .com @Override public boolean onPreferenceClick(Preference p) { UserManager userManager = (UserManager) getSystemService(USER_SERVICE); LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE); boolean appIsValid = isStartButton || isOverflowMenu || !launcherApps.getActivityList(getIntent().getStringExtra("package_name"), userManager.getUserForSerialNumber(userId)).isEmpty(); if (appIsValid) switch (p.getKey()) { case "app_info": startFreeformActivity(); launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(componentName), userManager.getUserForSerialNumber(userId), null, null); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "uninstall": if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isInMultiWindowMode()) { Intent intent2 = new Intent(ContextMenuActivity.this, DummyActivity.class); intent2.putExtra("uninstall", packageName); intent2.putExtra("user_id", userId); startFreeformActivity(); startActivity(intent2); } else { startFreeformActivity(); Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + packageName)); intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(userId)); try { startActivity(intent2); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "open_taskbar_settings": startFreeformActivity(); Intent intent2 = new Intent(this, MainActivity.class); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent2); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "quit_taskbar": Intent quitIntent = new Intent("com.farmerbb.taskbar.QUIT"); quitIntent.setPackage(BuildConfig.APPLICATION_ID); sendBroadcast(quitIntent); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "pin_app": PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this); if (pba.isPinned(componentName)) pba.removePinnedApp(this, componentName); else { Intent intent = new Intent(); intent.setComponent(ComponentName.unflattenFromString(componentName)); LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(userId)); if (appInfo != null) { AppEntry newEntry = new AppEntry(packageName, componentName, appName, IconCache.getInstance(this).getIcon(this, getPackageManager(), appInfo), true); newEntry.setUserId(userId); pba.addPinnedApp(this, newEntry); } } break; case "block_app": PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this); if (pba2.isBlocked(componentName)) pba2.removeBlockedApp(this, componentName); else { pba2.addBlockedApp(this, new AppEntry(packageName, componentName, appName, null, false)); } break; case "show_window_sizes": getPreferenceScreen().removeAll(); addPreferencesFromResource(R.xml.pref_context_menu_window_size_list); findPreference("window_size_standard").setOnPreferenceClickListener(this); findPreference("window_size_large").setOnPreferenceClickListener(this); findPreference("window_size_fullscreen").setOnPreferenceClickListener(this); findPreference("window_size_half_left").setOnPreferenceClickListener(this); findPreference("window_size_half_right").setOnPreferenceClickListener(this); findPreference("window_size_phone_size").setOnPreferenceClickListener(this); SharedPreferences pref = U.getSharedPreferences(this); if (pref.getBoolean("save_window_sizes", true)) { String windowSizePref = SavedWindowSizes.getInstance(this).getWindowSize(this, packageName); CharSequence title = findPreference("window_size_" + windowSizePref).getTitle(); findPreference("window_size_" + windowSizePref).setTitle('\u2713' + " " + title); } if (U.isOPreview()) { U.showToast(this, R.string.window_sizes_not_available); } secondaryMenu = true; break; case "window_size_standard": case "window_size_large": case "window_size_fullscreen": case "window_size_half_left": case "window_size_half_right": case "window_size_phone_size": String windowSize = p.getKey().replace("window_size_", ""); SharedPreferences pref2 = U.getSharedPreferences(this); if (pref2.getBoolean("save_window_sizes", true)) { SavedWindowSizes.getInstance(this).setWindowSize(this, packageName, windowSize); } startFreeformActivity(); U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "app_shortcuts": getPreferenceScreen().removeAll(); generateShortcuts(); secondaryMenu = true; break; case "shortcut_1": case "shortcut_2": case "shortcut_3": case "shortcut_4": case "shortcut_5": U.startShortcut(getApplicationContext(), packageName, componentName, shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1)); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "start_menu_apps": startFreeformActivity(); Intent intent = null; SharedPreferences pref3 = U.getSharedPreferences(this); switch (pref3.getString("theme", "light")) { case "light": intent = new Intent(this, SelectAppActivity.class); break; case "dark": intent = new Intent(this, SelectAppActivityDark.class); break; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref3.getBoolean("freeform_hack", false) && intent != null && isInMultiWindowMode()) { intent.putExtra("no_shadow", true); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); U.launchAppMaximized(getApplicationContext(), intent); } else startActivity(intent); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "volume": AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE); audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "file_manager": Intent fileManagerIntent; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { startFreeformActivity(); fileManagerIntent = new Intent("android.provider.action.BROWSE"); } else { fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT"); fileManagerIntent.setComponent( ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity")); } fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT); fileManagerIntent .setData(Uri.parse("content://com.android.externalstorage.documents/root/primary")); try { startActivity(fileManagerIntent); } catch (ActivityNotFoundException e) { U.showToast(this, R.string.lock_device_not_supported); } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "system_settings": startFreeformActivity(); Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS); try { startActivity(settingsIntent); } catch (ActivityNotFoundException e) { U.showToast(this, R.string.lock_device_not_supported); } showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "lock_device": U.lockDevice(this); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "power_menu": U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; case "change_wallpaper": Intent intent3 = Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), getString(R.string.set_wallpaper)); intent3.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); U.launchAppMaximized(getApplicationContext(), intent3); showStartMenu = false; shouldHideTaskbar = true; contextMenuFix = false; break; } if (!secondaryMenu) finish(); return true; }
From source file:ca.mimic.apphangar.Settings.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { Tools.HangarLog("ResultCode: " + resultCode + "RequestCode: " + requestCode + "Intent: " + data); if (requestCode == 1001) { int responseCode = data.getIntExtra("RESPONSE_CODE", 0); String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA"); if (responseCode == 0) { try { JSONObject jo = new JSONObject(purchaseData); String sku = jo.getString("productId"); Tools.HangarLog("It werked! productId: " + sku); launchThanks(THANK_YOU_GOOGLE); } catch (JSONException e) { e.printStackTrace();/*from w w w . j a v a 2 s.c o m*/ } } else { if (responseCode > 1) { Tools.HangarLog("Not user's fault, tried to purchase but bailed."); Toast.makeText(mContext, getResources().getString(R.string.donate_try_paypal), Toast.LENGTH_LONG).show(); } launchDonate(); } } else if (requestCode == 1) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); ComponentName componentTask = ComponentName .unflattenFromString(mIconTask.getPackageName() + "/" + mIconTask.getClassName()); IconCacheHelper.preloadComponent(mContext, componentTask, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } else if (requestCode == 2) { // Icon chooser if (resultCode == Activity.RESULT_OK) { try { Bitmap bitmap = data.getParcelableExtra("icon"); IconCacheHelper.preloadIcon(mContext, Settings.MORE_APPS_PACKAGE, bitmap, Tools.dpToPx(mContext, CACHED_ICON_SIZE)); myService.execute(SERVICE_CREATE_NOTIFICATIONS); completeRedraw = true; Tools.updateWidget(mContext); updateMoreAppsIcon(mContext); } catch (Exception e) { Tools.HangarLog("Icon result exception: " + e); } } } }
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
public void updateSources() { mSelectedSource = null;/*from ww w. ja v a 2s. c om*/ Intent queryIntent = new Intent(ACTION_MUZEI_ART_SOURCE); PackageManager pm = getContext().getPackageManager(); mSources.clear(); List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA); for (ResolveInfo ri : resolveInfos) { Source source = new Source(); source.label = ri.loadLabel(pm).toString(); source.icon = new BitmapDrawable(getResources(), generateSourceImage(ri.loadIcon(pm))); source.targetSdkVersion = ri.serviceInfo.applicationInfo.targetSdkVersion; source.componentName = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name); if (ri.serviceInfo.descriptionRes != 0) { try { Context packageContext = getContext() .createPackageContext(source.componentName.getPackageName(), 0); Resources packageRes = packageContext.getResources(); source.description = packageRes.getString(ri.serviceInfo.descriptionRes); } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { Log.e(TAG, "Can't read package resources for source " + source.componentName); } } Bundle metaData = ri.serviceInfo.metaData; source.color = Color.WHITE; if (metaData != null) { String settingsActivity = metaData.getString("settingsActivity"); if (!TextUtils.isEmpty(settingsActivity)) { source.settingsActivity = ComponentName .unflattenFromString(ri.serviceInfo.packageName + "/" + settingsActivity); } String setupActivity = metaData.getString("setupActivity"); if (!TextUtils.isEmpty(setupActivity)) { source.setupActivity = ComponentName .unflattenFromString(ri.serviceInfo.packageName + "/" + setupActivity); } source.color = metaData.getInt("color", source.color); try { float[] hsv = new float[3]; Color.colorToHSV(source.color, hsv); boolean adjust = false; if (hsv[2] < 0.8f) { hsv[2] = 0.8f; adjust = true; } if (hsv[1] > 0.4f) { hsv[1] = 0.4f; adjust = true; } if (adjust) { source.color = Color.HSVToColor(hsv); } if (Color.alpha(source.color) != 255) { source.color = Color.argb(255, Color.red(source.color), Color.green(source.color), Color.blue(source.color)); } } catch (IllegalArgumentException ignored) { } } mSources.add(source); } final String appPackage = getContext().getPackageName(); Collections.sort(mSources, new Comparator<Source>() { @Override public int compare(Source s1, Source s2) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { boolean target1IsO = s1.targetSdkVersion >= Build.VERSION_CODES.O; boolean target2IsO = s2.targetSdkVersion >= Build.VERSION_CODES.O; if (target1IsO && !target2IsO) { return 1; } else if (!target1IsO && target2IsO) { return -1; } } String pn1 = s1.componentName.getPackageName(); String pn2 = s2.componentName.getPackageName(); if (!pn1.equals(pn2)) { if (appPackage.equals(pn1)) { return -1; } else if (appPackage.equals(pn2)) { return 1; } } return s1.label.compareTo(s2.label); } }); redrawSources(); }
From source file:com.farmerbb.taskbar.service.DashboardService.java
private void cellClick(View view, boolean isActualClick) { Bundle bundle = (Bundle) view.getTag(); int cellId = bundle.getInt("cellId"); int appWidgetId = bundle.getInt("appWidgetId", -1); int currentlySelectedCell = appWidgetId == -1 ? cellId : -1; SharedPreferences pref = U.getSharedPreferences(this); boolean shouldShowPlaceholder = pref .getBoolean("dashboard_widget_" + Integer.toString(cellId) + "_placeholder", false); if (isActualClick && ((appWidgetId == -1 && currentlySelectedCell == previouslySelectedCell) || shouldShowPlaceholder)) { fadeOut(false);/*ww w. j av a 2s .c om*/ FrameLayout frameLayout = cells.get(currentlySelectedCell); frameLayout.findViewById(R.id.empty).setVisibility(View.GONE); Intent intent = new Intent("com.farmerbb.taskbar.ADD_WIDGET_REQUESTED"); intent.putExtra("appWidgetId", APPWIDGET_HOST_ID); intent.putExtra("cellId", cellId); LocalBroadcastManager.getInstance(DashboardService.this).sendBroadcast(intent); if (shouldShowPlaceholder) { String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null"); if (!providerName.equals("null")) { ComponentName componentName = ComponentName.unflattenFromString(providerName); List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager .getInstalledProvidersForProfile(Process.myUserHandle()); for (AppWidgetProviderInfo info : providerInfoList) { if (info.provider.equals(componentName)) { U.showToast(this, getString(R.string.widget_restore_toast, info.loadLabel(getPackageManager())), Toast.LENGTH_SHORT); break; } } } } previouslySelectedCell = -1; } else { for (int i = 0; i < maxSize; i++) { FrameLayout frameLayout = cells.get(i); frameLayout.findViewById(R.id.empty).setVisibility( i == currentlySelectedCell && !shouldShowPlaceholder ? View.VISIBLE : View.GONE); } previouslySelectedCell = currentlySelectedCell; } }
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
private void updateIntentComponent() { ComponentName newComponentName = ComponentName.unflattenFromString(mComponentText.getText().toString()); ComponentName oldComponentName = mEditedIntent.getComponent(); mEditedIntent.setComponent(newComponentName); if ((newComponentName != null) != (oldComponentName != null)) { getIntentEditor().safelyInvalidateOptionsMenu(); }/*w w w . j ava 2s . c o m*/ }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertArtwork(@NonNull final Uri uri, final ContentValues values) { Context context = getContext(); if (context == null) { return null; }/*from w w w .j a v a2 s .co m*/ if (values == null) { throw new IllegalArgumentException("Invalid ContentValues: must not be null"); } if (!values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME) || TextUtils.isEmpty(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name: " + values); } // Check to make sure the component name is valid ComponentName componentName = ComponentName .unflattenFromString(values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME)); } // Make sure they are using the short string format values.put(MuzeiContract.Artwork.COLUMN_NAME_SOURCE_COMPONENT_NAME, componentName.flattenToShortString()); // Ensure the app inserting the artwork is either Muzei or the same app as the source String callingPackageName = getCallingPackage(); if (!context.getPackageName().equals(callingPackageName) && !TextUtils.equals(callingPackageName, componentName.getPackageName())) { throw new IllegalArgumentException("Calling package name (" + callingPackageName + ") must match the source's package name (" + componentName.getPackageName() + ")"); } if (values.containsKey(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT)) { String viewIntentString = values.getAsString(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); Intent viewIntent; try { if (!TextUtils.isEmpty(viewIntentString)) { // Make sure it is a valid Intent URI viewIntent = Intent.parseUri(viewIntentString, Intent.URI_INTENT_SCHEME); // Make sure we can construct a PendingIntent for the Intent PendingIntent.getActivity(context, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT); } } catch (URISyntaxException e) { Log.w(TAG, "Removing invalid View Intent: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } catch (RuntimeException e) { // This is actually meant to catch a FileUriExposedException, but you can't // have catch statements for exceptions that don't exist at your minSdkVersion Log.w(TAG, "Removing invalid View Intent that contains a file:// URI: " + viewIntentString, e); values.remove(MuzeiContract.Artwork.COLUMN_NAME_VIEW_INTENT); } } // Ensure the related source has been added to the database. // This should be true in 99.9% of cases, but the insert will fail if this isn't true Cursor sourceQuery = querySource(MuzeiContract.Sources.CONTENT_URI, new String[] { BaseColumns._ID }, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME + "=?", new String[] { componentName.flattenToShortString() }, null); if (sourceQuery == null || sourceQuery.getCount() == 0) { ContentValues initialValues = new ContentValues(); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); insertSource(MuzeiContract.Sources.CONTENT_URI, initialValues); } if (sourceQuery != null) { sourceQuery.close(); } values.put(MuzeiContract.Artwork.COLUMN_NAME_DATE_ADDED, System.currentTimeMillis()); final SQLiteDatabase db = databaseHelper.getWritableDatabase(); long rowId = db.insert(MuzeiContract.Artwork.TABLE_NAME, MuzeiContract.Artwork.COLUMN_NAME_IMAGE_URI, values); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the artwork ID pattern and the new row ID appended to it. final Uri artworkUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, rowId); File artwork = getCacheFileForArtworkUri(artworkUri); if (artwork != null && artwork.exists()) { // The image already exists so we'll notifyChange() to say the new artwork is ready // Otherwise, this will be called when the file is written with openFile() // using this Uri and the actual artwork is written successfully notifyChange(artworkUri); } return artworkUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }
From source file:com.android.settings.accessibility.AccessibilitySettings.java
private void initializePreBundledServicesMapFromArray(String categoryKey, int key) { String[] services = getResources().getStringArray(key); PreferenceCategory category = mCategoryToPrefCategoryMap.get(categoryKey); for (int i = 0; i < services.length; i++) { ComponentName component = ComponentName.unflattenFromString(services[i]); mPreBundledServiceComponentToCategoryMap.put(component, category); }//w w w . j a v a2 s . com }
From source file:com.farmerbb.taskbar.service.DashboardService.java
private void addPlaceholder(int cellId) { FrameLayout placeholder = (FrameLayout) cells.get(cellId).findViewById(R.id.placeholder); SharedPreferences pref = U.getSharedPreferences(this); String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null"); if (!providerName.equals("null")) { ImageView imageView = (ImageView) placeholder.findViewById(R.id.placeholder_image); ComponentName componentName = ComponentName.unflattenFromString(providerName); List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager .getInstalledProvidersForProfile(Process.myUserHandle()); for (AppWidgetProviderInfo info : providerInfoList) { if (info.provider.equals(componentName)) { Drawable drawable = info.loadPreviewImage(this, -1); if (drawable == null) drawable = info.loadIcon(this, -1); ColorMatrix matrix = new ColorMatrix(); matrix.setSaturation(0); imageView.setImageDrawable(drawable); imageView.setColorFilter(new ColorMatrixColorFilter(matrix)); break; }/* www . j a v a 2s . c o m*/ } } placeholder.setVisibility(View.VISIBLE); }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
private ComponentName stringToComponentName(String str) { return str == null ? null : ComponentName.unflattenFromString(str); }
From source file:com.google.android.apps.muzei.provider.MuzeiProvider.java
private Uri insertSource(@NonNull final Uri uri, final ContentValues initialValues) { Context context = getContext(); if (context == null) { return null; }/*from w w w . j a v a2 s . co m*/ if (!initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME) || TextUtils.isEmpty(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME))) { throw new IllegalArgumentException("Initial values must contain component name " + initialValues); } ComponentName componentName = ComponentName .unflattenFromString(initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); if (componentName == null) { throw new IllegalArgumentException("Invalid component name: " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME)); } ApplicationInfo info; try { // Ensure the service is valid and extract the application info info = context.getPackageManager().getServiceInfo(componentName, 0).applicationInfo; } catch (PackageManager.NameNotFoundException e) { throw new IllegalArgumentException("Invalid component name " + initialValues.getAsString(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME), e); } // Make sure they are using the short string format initialValues.put(MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, componentName.flattenToShortString()); // Only Muzei can set the IS_SELECTED field if (initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED)) { if (!context.getPackageName().equals(getCallingPackage())) { Log.w(TAG, "Only Muzei can set the " + MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED + " column. Ignoring the value in " + initialValues); initialValues.remove(MuzeiContract.Sources.COLUMN_NAME_IS_SELECTED); } } // Disable network access callbacks if we're running on an API 24 device and the source app // targets API 24. This is to be consistent with the Behavior Changes in Android N if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && initialValues.containsKey(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE) && initialValues.getAsBoolean(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE)) { if (info.targetSdkVersion >= Build.VERSION_CODES.N) { Log.w(TAG, "Sources targeting API 24 cannot receive network access callbacks. Changing " + componentName + " to false for " + MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE); initialValues.put(MuzeiContract.Sources.COLUMN_NAME_WANTS_NETWORK_AVAILABLE, false); } } final SQLiteDatabase db = databaseHelper.getWritableDatabase(); final long rowId = db.insert(MuzeiContract.Sources.TABLE_NAME, MuzeiContract.Sources.COLUMN_NAME_COMPONENT_NAME, initialValues); // If the insert succeeded, the row ID exists. if (rowId > 0) { // Creates a URI with the source ID pattern and the new row ID appended to it. final Uri sourceUri = ContentUris.withAppendedId(MuzeiContract.Sources.CONTENT_URI, rowId); notifyChange(sourceUri); return sourceUri; } // If the insert didn't succeed, then the rowID is <= 0 throw new SQLException("Failed to insert row into " + uri); }