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:edu.mit.mobile.android.livingpostcards.CardListFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from  www  .j  a v a  2s . co m
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (final ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }
    final Uri card = ContentUris.withAppendedId(mCards, info.id);

    switch (item.getItemId()) {
    case R.id.share:
        send(mAdapter.getCursor());
        return true;

    case R.id.edit:
        startActivity(new Intent(Intent.ACTION_EDIT, card));
        return true;

    case R.id.delete:
        startActivity(new Intent(Intent.ACTION_DELETE, card));
        return true;
    default:
        return super.onContextItemSelected(item);
    }

}

From source file:edu.mit.mobile.android.locast.itineraries.ItineraryDetail.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {//from  ww w. j a v a  2 s.c om
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (final ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }

    final Uri cast = Cast.getCanonicalUri(this, ContentUris.withAppendedId(mCastsUri, info.id));

    switch (item.getItemId()) {
    case R.id.cast_view:
        startActivity(new Intent(Intent.ACTION_VIEW, cast));
        return true;

    case R.id.cast_edit:
        startActivity(new Intent(Intent.ACTION_EDIT, cast));
        return true;

    case R.id.cast_delete:
        startActivity(new Intent(Intent.ACTION_DELETE, cast));
        return true;

    // case R.id.cast_play:
    // startActivity(new Intent(CastDetailsActivity.ACTION_PLAY_CAST, cast));
    // return true;

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:org.wso2.app.catalog.api.ApplicationManager.java

/**
 * Removes an application from the device.
 *
 * @param packageName - Application package name should be passed in as a String.
 *///from   w  w  w.j  ava2 s .  co m
public void uninstallApplication(String packageName) {
    if (packageName != null
            && !packageName.contains(resources.getString(R.string.application_package_prefix))) {
        packageName = resources.getString(R.string.application_package_prefix) + packageName;
    }

    if (isPackageInstalled(Constants.AGENT_PACKAGE_NAME)) {
        CommonUtils.callAgentApp(context, Constants.Operation.UNINSTALL_APPLICATION, packageName, null);
    } else {
        Uri packageURI = Uri.parse(packageName);
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
        uninstallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(uninstallIntent);
    }
}

From source file:co.lemonlabs.android.slidingdebugmenu.SlidingDebugMenu.java

@SuppressWarnings("ConstantConditions")
@Override/*from   www  .  ja  va 2  s  . c o m*/
public void onClick(View v) {
    final int id = v.getId();
    Context context = getContext();

    if (id == R.id.sdm__settings_developer) {
        // open dev settings
        Intent devIntent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(devIntent, 0);
        if (resolveInfo != null)
            context.startActivity(devIntent);
        else
            Toast.makeText(context, "Developer settings not available on device", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.sdm__settings_battery) {
        // try to find an app to handle battery settings
        Intent batteryIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);
        ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(batteryIntent, 0);
        if (resolveInfo != null)
            context.startActivity(batteryIntent);
        else
            Toast.makeText(context, "No app found to handle power usage intent", Toast.LENGTH_SHORT).show();

    } else if (id == R.id.sdm__settings_drawer) {
        // open android settings
        context.startActivity(new Intent(Settings.ACTION_SETTINGS));

    } else if (id == R.id.sdm__settings_app_info) {
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.setData(Uri.parse("package:" + context.getPackageName()));
        context.startActivity(intent);

    } else if (id == R.id.sdm__settings_uninstall) {
        // open dialog to uninstall app
        Uri packageURI = Uri.parse("package:" + context.getPackageName());
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
        context.startActivity(uninstallIntent);
    }
}

From source file:com.tomclaw.appteka.main.view.AppsView.java

private void showActionDialog(final AppItem appItem) {
    ListAdapter menuAdapter = new MenuAdapter(getContext(), R.array.app_actions_titles,
            R.array.app_actions_icons);/*from  w ww . j  a  v a  2s  .  c o m*/
    new AlertDialog.Builder(getContext()).setAdapter(menuAdapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which) {
            case 0: {
                FlurryAgent.logEvent("App menu: run");
                PackageManager packageManager = getContext().getPackageManager();
                Intent launchIntent = packageManager.getLaunchIntentForPackage(appItem.getPackageName());
                if (launchIntent == null) {
                    Snackbar.make(recyclerView, R.string.non_launchable_package, Snackbar.LENGTH_LONG).show();
                } else {
                    startActivity(launchIntent);
                }
                break;
            }
            case 1: {
                FlurryAgent.logEvent("App menu: share");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_SHARE));
                break;
            }
            case 2: {
                FlurryAgent.logEvent("App menu: extract");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_EXTRACT));
                break;
            }
            case 3: {
                FlurryAgent.logEvent("App menu: upload");
                Intent intent = new Intent(getContext(), UploadActivity.class);
                intent.putExtra(UploadActivity.UPLOAD_ITEM, appItem);
                startActivity(intent);
                break;
            }
            case 4: {
                FlurryAgent.logEvent("App menu: bluetooth");
                TaskExecutor.getInstance()
                        .execute(new ExportApkTask(getContext(), appItem, ExportApkTask.ACTION_BLUETOOTH));
                break;
            }
            case 5: {
                FlurryAgent.logEvent("App menu: Google Play");
                String packageName = appItem.getPackageName();
                openGooglePlay(getContext(), packageName);
                break;
            }
            case 6: {
                FlurryAgent.logEvent("App menu: permissions");
                try {
                    PackageInfo packageInfo = appItem.getPackageInfo();
                    List<String> permissions = Arrays.asList(packageInfo.requestedPermissions);
                    Intent intent = new Intent(getContext(), PermissionsActivity.class).putStringArrayListExtra(
                            PermissionsActivity.EXTRA_PERMISSIONS, new ArrayList<>(permissions));
                    startActivity(intent);
                } catch (Throwable ex) {
                    Snackbar.make(recyclerView, R.string.unable_to_get_permissions, Snackbar.LENGTH_LONG)
                            .show();
                }
                break;
            }
            case 7: {
                FlurryAgent.logEvent("App menu: details");
                setRefreshOnResume();
                final Intent intent = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        .addCategory(Intent.CATEGORY_DEFAULT)
                        .setData(Uri.parse("package:" + appItem.getPackageName()))
                        .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            }
            case 8: {
                FlurryAgent.logEvent("App menu: remove");
                setRefreshOnResume();
                Uri packageUri = Uri.parse("package:" + appItem.getPackageName());
                Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
                startActivity(uninstallIntent);
                break;
            }
            }
        }
    }).show();
}

From source file:edu.mit.mobile.android.locast.ver2.itineraries.ItineraryDetail.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {/*from   www.  j av  a2  s. c  o m*/
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (final ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return false;
    }

    final Uri cast = Cast.getCanonicalUri(this, ContentUris.withAppendedId(mCastsUri, info.id));

    switch (item.getItemId()) {
    case R.id.cast_view:
        startActivity(new Intent(Intent.ACTION_VIEW, cast));
        return true;

    case R.id.cast_edit:
        startActivity(new Intent(Intent.ACTION_EDIT, cast));
        return true;

    case R.id.cast_delete:
        startActivity(new Intent(Intent.ACTION_DELETE, cast));
        return true;

    //       case R.id.cast_play:
    //          startActivity(new Intent(CastDetailsActivity.ACTION_PLAY_CAST, cast));
    //          return true;

    default:
        return super.onContextItemSelected(item);
    }
}

From source file:moe.johnny.tombstone.ui.PreventFragment.java

private boolean startActivity(int id, String packageName) {
    String action;/*from   w w  w .java 2  s. c  o  m*/
    if (id == R.string.app_info) {
        action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
    } else if (id == R.string.uninstall) {
        action = Intent.ACTION_DELETE;
    } else {
        return false;
    }
    mActivity.startActivity(new Intent(action, Uri.fromParts("package", packageName, null)));
    return true;
}

From source file:org.cyanogenmod.theme.chooser.ChooserDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_uninstall:
        Uri packageUri = Uri.parse("package:" + mPkgName);
        Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageUri);
        startActivity(uninstallIntent);/*from  w w  w  .j a va 2s. com*/
        return true;
    }
    return false;
}

From source file:com.farmerbb.taskbar.MainActivity.java

private void proceedWithAppLaunch(Bundle savedInstanceState) {
    setContentView(R.layout.main);//from w ww  .j  a v  a  2  s  .c  o  m

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setCustomView(R.layout.switch_layout);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    theSwitch = (SwitchCompat) findViewById(R.id.the_switch);
    if (theSwitch != null) {
        final SharedPreferences pref = U.getSharedPreferences(this);
        theSwitch.setChecked(pref.getBoolean("taskbar_active", false));

        theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
            if (b) {
                if (U.canDrawOverlays(this)) {
                    boolean firstRun = pref.getBoolean("first_run", true);
                    startTaskbarService();

                    if (firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !U.isSystemApp(this)) {
                        ApplicationInfo applicationInfo = null;
                        try {
                            applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID,
                                    0);
                        } catch (PackageManager.NameNotFoundException e) {
                            /* Gracefully fail */ }

                        if (applicationInfo != null) {
                            AppOpsManager appOpsManager = (AppOpsManager) getSystemService(
                                    Context.APP_OPS_SERVICE);
                            int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
                                    applicationInfo.uid, applicationInfo.packageName);

                            if (mode != AppOpsManager.MODE_ALLOWED) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                                builder.setTitle(R.string.pref_header_recent_apps)
                                        .setMessage(R.string.enable_recent_apps)
                                        .setPositiveButton(R.string.action_ok, (dialog, which) -> {
                                            try {
                                                startActivity(
                                                        new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS));
                                                U.showToastLong(MainActivity.this,
                                                        R.string.usage_stats_message);
                                            } catch (ActivityNotFoundException e) {
                                                U.showErrorDialog(MainActivity.this, "GET_USAGE_STATS");
                                            }
                                        }).setNegativeButton(R.string.action_cancel, null);

                                AlertDialog dialog = builder.create();
                                dialog.show();
                            }
                        }
                    }
                } else {
                    U.showPermissionDialog(MainActivity.this);
                    compoundButton.setChecked(false);
                }
            } else
                stopTaskbarService();
        });
    }

    if (savedInstanceState == null) {
        if (!getIntent().hasExtra("theme_change"))
            getFragmentManager().beginTransaction()
                    .replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit();
        else
            getFragmentManager().beginTransaction()
                    .replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit();
    }

    if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
        final SharedPreferences pref = U.getSharedPreferences(this);
        if (!pref.getBoolean("dont_show_uninstall_dialog", false)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message)
                    .setPositiveButton(R.string.action_uninstall, (dialog, which) -> {
                        pref.edit().putBoolean("uninstall_dialog_shown", true).apply();

                        try {
                            startActivity(new Intent(Intent.ACTION_DELETE,
                                    Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
                        } catch (ActivityNotFoundException e) {
                            /* Gracefully fail */ }
                    });

            if (pref.getBoolean("uninstall_dialog_shown", false))
                builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit()
                        .putBoolean("dont_show_uninstall_dialog", true).apply());

            AlertDialog dialog = builder.create();
            dialog.show();
            dialog.setCancelable(false);
        }

        if (!pref.getBoolean("uninstall_dialog_shown", false)) {
            if (theSwitch != null)
                theSwitch.setChecked(false);

            SharedPreferences.Editor editor = pref.edit();

            String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID);
            if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
                editor.putString("icon_pack", BuildConfig.APPLICATION_ID);
            } else {
                U.refreshPinnedIcons(this);
            }

            editor.putBoolean("first_run", true);
            editor.apply();
        }
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        if (shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClass(this, StartTaskbarActivity.class);
            intent.putExtra("is_launching_shortcut", true);

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar")
                    .setShortLabel(getString(R.string.start_taskbar))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent)
                    .build();

            Intent intent2 = new Intent(Intent.ACTION_MAIN);
            intent2.setClass(this, ShortcutActivity.class);
            intent2.putExtra("is_launching_shortcut", true);

            ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode")
                    .setShortLabel(getString(R.string.pref_header_freeform))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform))
                    .setIntent(intent2).build();

            shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
        }
    }
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.receiver.NotificationHelper.java

/**
 * Needs the builder that contains non-note specific values.
 *
 *///from  w  w w.j ava  2 s . com
private static void notifyBigText(final Context context, final NotificationManager notificationManager,
        final NotificationCompat.Builder builder,
        final cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.data.model.sql.Notification note) {
    final Intent delIntent = new Intent(Intent.ACTION_DELETE, note.getUri());
    if (note.repeats != 0) {
        delIntent.setAction(ACTION_RESCHEDULE);
    }
    // Add extra so we don't delete all
    // if (note.time != null) {
    // delIntent.putExtra(ARG_MAX_TIME, note.time);
    // }
    delIntent.putExtra(ARG_TASKID, note.taskID);
    // Delete it on clear
    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0, delIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Open intent
    final Intent openIntent = new Intent(Intent.ACTION_VIEW, Task.getUri(note.taskID));
    // Should create a new instance to avoid fragment problems
    openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);

    // Delete intent on non-location repeats
    // Opening the note should delete/reschedule the notification
    openIntent.putExtra(NOTIFICATION_DELETE_ARG, note._id);

    // Opening always cancels the notification though
    openIntent.putExtra(NOTIFICATION_CANCEL_ARG, note._id);

    // Open note on click
    PendingIntent clickIntent = PendingIntent.getActivity(context, 0, openIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Action to complete
    PendingIntent completeIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(ACTION_COMPLETE, note.getUri()).putExtra(ARG_TASKID, note.taskID),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Action to snooze
    PendingIntent snoozeIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(ACTION_SNOOZE, note.getUri()).putExtra(ARG_TASKID, note.taskID),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Build notification
    builder.setContentTitle(note.taskTitle).setContentText(note.taskNote).setContentIntent(clickIntent)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(note.taskNote));

    // Delete intent on non-location repeats
    builder.setDeleteIntent(deleteIntent);

    // Snooze button only on time non-repeating
    if (note.time != null && note.repeats == 0) {
        builder.addAction(R.drawable.ic_alarm_24dp_white, context.getText(R.string.snooze), snoozeIntent);
    }
    // Complete button only on non-repeating, both time and location
    if (note.repeats == 0) {
        builder.addAction(R.drawable.ic_check_24dp_white, context.getText(R.string.completed), completeIntent);
    }

    final Notification noti = builder.build();

    notificationManager.notify((int) note._id, noti);
}