Example usage for android.content Intent ACTION_DELETE

List of usage examples for android.content Intent ACTION_DELETE

Introduction

In this page you can find the example usage for android.content Intent ACTION_DELETE.

Prototype

String ACTION_DELETE

To view the source code for android.content Intent ACTION_DELETE.

Click Source Link

Document

Activity Action: Delete the given data from its container.

Usage

From source file:cm.aptoide.pt.RemoteInSearch.java

private void removeApk(String apk_pkg, int position) {
    try {//from  w  w w.  ja v a 2  s.  c  om
        pkginfo = mPm.getPackageInfo(apk_pkg, 0);
    } catch (NameNotFoundException e) {
    }
    Uri uri = Uri.fromParts("package", pkginfo.packageName, null);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    startActivityForResult(intent, position);
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display a grid of all installed apps + virtual apps. Allow user to launch
 * apps.//ww  w . j  a  v  a2 s .c om
 * 
 * @param context
 * @param applications
 */
public static void displayAllApps(final Launcher context, final ArrayList<ApplicationInfo> applications) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.apps_grid);

    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    gridView.setAdapter(new AllItemAdapter(context, getApplications(context, applications, false)));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            itemInfo.invoke(context);
            context.showCover(false);
            dialog.dismiss();
            if (itemInfo instanceof ApplicationInfo) {
                ApplicationInfo applicationInfo = (ApplicationInfo) itemInfo;
                RecentAppsTable.persistRecentApp(context, applicationInfo);
            }
        }

    });
    gridView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> gridView, View view, int pos, long arg3) {
            ItemInfo itemInfo = (ItemInfo) gridView.getAdapter().getItem(pos);
            if (itemInfo instanceof ApplicationInfo) {
                Uri packageURI = Uri.parse("package:" + itemInfo.getIntent().getComponent().getPackageName());
                Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
                context.startActivity(uninstallIntent);
                context.showCover(false);
                dialog.dismiss();
                Analytics.logEvent(Analytics.UNINSTALL_APP);
            }

            return false;
        }

    });
    gridView.setDrawingCacheEnabled(true);
    gridView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ALL_APPS);
}

From source file:org.deviceconnect.android.manager.setting.DevicePluginInfoFragment.java

/**
 * Open uninstall dialog./*from   w  w  w .j a v  a 2s . c  om*/
 */
private void openUninstall() {
    Uri uri = Uri.fromParts("package", mPluginInfo.getPackageName(), null);
    Intent intent = new Intent(Intent.ACTION_DELETE, uri);
    startActivityForResult(intent, REQUEST_CODE);
}

From source file:me.piebridge.prevent.ui.PreventActivity.java

private void showTestDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.app_name) + "(" + BuildConfig.VERSION_NAME + ")");
    builder.setMessage(R.string.soak_version);
    builder.setIcon(R.drawable.ic_launcher);
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override// w  w  w . j a v a  2s  . c om
        public void onCancel(DialogInterface dialog) {
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            startActivity(new Intent(Intent.ACTION_DELETE,
                    Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)));
            finish();
        }
    });
    builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            init();
        }
    });
    builder.create().show();
}

From source file:com.farmerbb.taskbar.activity.ContextMenuActivity.java

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)/*from w w w .  j  a v  a2s . 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:edu.mit.mobile.android.livingpostcards.CardEditActivity.java

@Override
public void onDelete(Uri item, boolean deleted) {
    if (mCard.equals(item) && deleted) {
        mSaveOnPause = false;/*from w  w  w .  j av  a 2 s  . co m*/
        setResult(RESULT_OK);
        // no need to call finish, as the loader will automatically reload, which will result in
        // no data being loaded, which will then call finish()

    } else if (Intent.ACTION_DELETE.equals(getIntent().getAction()) && !deleted) {
        setResult(RESULT_CANCELED);
        finish();
    }
}

From source file:com.polyvi.xface.extension.XAppExt.java

/**
 * ?native/*from w w  w  . j av  a  2  s .c  o m*/
 *
 * @param appId
 *            ??
 */
public void uninstallNativeApp(String appId, XCallbackContext callbackCtx) {
    registerInstallerReceiver(callbackCtx);
    uninstallPackageName = appId;
    Uri packageURI = Uri.parse("package:" + appId);
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    getContext().startActivity(uninstallIntent);
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static void uninstallApk(final Context ctx, final String packagename) {
    Log.i(TAG, "Will uninstall package: " + packagename);
    try {/*from   ww w  .  j a  v  a  2  s  . c  o m*/
        Intent intent = new Intent(Intent.ACTION_DELETE);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setData(Uri.parse("package:" + packagename));
        ctx.startActivity(intent);
        Log.i(TAG, "Uninstallation intent started successfully.");
    } catch (final Throwable e) {
        Log.e(TAG, "Exception while uninstalling package: ", e);
    }
}

From source file:com.chen.download.Utils.java

/**
 * ?//from  w  w w. java2 s.co  m
 * 
 * @param context
 *            
 * @param pkgName
 *            ??
 */
public static void uninstallApk(Context context, String pkgName) {
    Uri packageURI = Uri.parse("package:" + pkgName);
    Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
    uninstallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(uninstallIntent);
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a application informative dialog with options to
 * uninstall/launch or cancel.//from  w  w  w .j a  va  2 s.  c om
 * 
 * @param context
 * @param appPackage
 */
public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) {

    try {

        final PackageManager packageManager = context.getPackageManager();
        final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA);

        AlertDialog dialog = new AlertDialog.Builder(context).create();

        dialog.setTitle(app.applicationInfo.loadLabel(packageManager));

        String description = null;
        if (app.applicationInfo.loadDescription(packageManager) != null) {
            description = app.applicationInfo.loadDescription(packageManager).toString();
        }

        String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName
                + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "")
                + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir);
        dialog.setMessage(msg);

        dialog.setCancelable(true);
        dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent intent = new Intent(Intent.ACTION_DELETE);
                intent.setData(Uri.parse("package:" + app.packageName));
                context.startActivity(intent);
            }
        });
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = packageManager.getLaunchIntentForPackage(app.packageName);
                context.startActivity(i);
            }
        });

        dialog.show();
    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. ["
                    + e.getMessage() + "].", e);
        }
    }
}