Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

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

Prototype

String ACTION_GET_CONTENT

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

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.IntimateCarCare.MainActivity.java

private void choseHeadImageFromGallery() {
    Intent intentFromGallery = new Intent();
    // //from w  ww.ja v a2 s.  c om
    intentFromGallery.setType("image/*");
    intentFromGallery.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intentFromGallery, CODE_GALLERY_REQUEST);
}

From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java

private void showFileChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {//ww  w  .  ja v a2s  .  c  om
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}

From source file:cc.metapro.openct.myclass.ClassActivity.java

private void showFilerChooser() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    try {//from  w w  w  . j ava 2  s  . c o m
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_schedule_file)),
                FILE_SELECT_CODE);
    } catch (ActivityNotFoundException ex) {
        Toast.makeText(this, R.string.fail_file_chooser, Toast.LENGTH_LONG).show();
    }
}

From source file:com.HumanDecisionSupportSystemsLaboratory.DD_P2P.Main.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override/*  w ww  .  ja  va2 s .c o  m*/
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.add_new_safe_my) {
        try {
            DD.load_listing_directories();
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(this.getApplicationContext(), "Error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG)
                    .show();
            // return;
        }

        if ((Identity.getListing_directories_addr().size() <= 0)) {
            Toast.makeText(this,
                    "To add your safe, first add a directory from the Manage Directories top-right menu!",
                    Toast.LENGTH_LONG).show();
            return super.onOptionsItemSelected(item);
        }
        Toast.makeText(this, "add a new safe my", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, AddSafe.class);
        startActivityForResult(intent, Main.RESULT_ADD_PEER);
    }

    if (item.getItemId() == R.id.add_new_safe_other) {
        if ((Identity.getListing_directories_addr().size() <= 0)) {
            Toast.makeText(this,
                    "To add a safe, first add a directory from the Manage Directories top-right menu!",
                    Toast.LENGTH_LONG).show();
            return super.onOptionsItemSelected(item);
        }
        Toast.makeText(this, "add a new safe other", Toast.LENGTH_SHORT).show();

        if (Build.VERSION.SDK_INT < 19) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(intent, SELECT_PHOTO);
        } else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.setType("image/*");
            startActivityForResult(intent, SELECT_PHOTO_KITKAT);
        }
    }

    if (item.getItemId() == R.id.add_new_org) {
        Toast.makeText(this, "add a new organization", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, AddOrg.class);
        startActivity(intent);
    }

    if (item.getItemId() == R.id.action_directories) {
        Toast.makeText(this, "adding a directory", Toast.LENGTH_SHORT).show();

        Intent intent = new Intent();
        intent.setClass(this, SelectDirectoryServer.class);
        startActivity(intent);
    }

    if (item.getItemId() == R.id.action_loadAddresss) {

        FragmentManager fm = getSupportFragmentManager();
        LoadPK loadPKDialog = new LoadPK();
        loadPKDialog.show(fm, "fragment_send_public_key");

    }

    // not yet implemented!
    if (item.getItemId() == R.id.action_start_directory) {

        Intent i = new Intent();
        i.setClass(this, StartDirectoryServer.class);
        startActivity(i);
    }

    if (item.getItemId() == R.id.action_settings) {
        Intent intent = new Intent();
        intent.setClass(this, Setting.class);
        startActivity(intent);
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.android.gallery3d.gadget.WidgetConfigure.java

private void setWidgetType(Intent data) {
    int widgetType = data.getIntExtra(KEY_WIDGET_TYPE, R.id.widget_type_shuffle);
    if (widgetType == R.id.widget_type_album) {
        Intent intent = new Intent(this, AlbumPicker.class);
        startActivityForResult(intent, REQUEST_CHOOSE_ALBUM);
    } else if (widgetType == R.id.widget_type_shuffle) {
        WidgetDatabaseHelper helper = new WidgetDatabaseHelper(this);
        try {/*ww w  . jav  a2  s . c  om*/
            helper.setWidget(mAppWidgetId, WidgetDatabaseHelper.TYPE_SHUFFLE, null, null);
            updateWidgetAndFinish(helper.getEntry(mAppWidgetId));
        } finally {
            helper.close();
        }
    } else {
        // Explicitly send the intent to the DialogPhotoPicker
        Intent request = new Intent(this, DialogPicker.class).setAction(Intent.ACTION_GET_CONTENT)
                .setType("image/*");
        startActivityForResult(request, REQUEST_GET_PHOTO);
    }
}

From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    if (itemId == R.id.menu_post_accounts)
        chooseAccounts();/*  ww w  .j  a  v  a  2 s.c o m*/
    else if (itemId == R.id.menu_post_photo) {
        boolean supported = false;
        Iterator<Integer> services = mAccountsService.values().iterator();
        while (services.hasNext() && ((supported = sPhotoSupported.contains(services.next())) == false))
            ;
        if (supported) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PHOTO);
        } else
            unsupportedToast(sPhotoSupported);
        //      } else if (itemId == R.id.menu_post_tags) {
        //         if (mAccountsService.size() == 1) {
        //            if (sTaggingSupported.contains(mAccountsService.values().iterator().next()))
        //               selectFriends(mAccountsService.keySet().iterator().next());
        //            else
        //               unsupportedToast(sTaggingSupported);
        //         } else {
        //            // dialog to select an account
        //            Iterator<Long> accountIds = mAccountsService.keySet().iterator();
        //            HashMap<Long, String> accountEntries = new HashMap<Long, String>();
        //            while (accountIds.hasNext()) {
        //               Long accountId = accountIds.next();
        //               Cursor account = this.getContentResolver().query(Accounts.getContentUri(this), new String[]{Accounts._ID, ACCOUNTS_QUERY}, Accounts._ID + "=?", new String[]{Long.toString(accountId)}, null);
        //               if (account.moveToFirst() && sTaggingSupported.contains(mAccountsService.get(accountId)))
        //                  accountEntries.put(account.getLong(0), account.getString(1));
        //            }
        //            int size = accountEntries.size();
        //            if (size != 0) {
        //               final long[] accountIndexes = new long[size];
        //               final String[] accounts = new String[size];
        //               int i = 0;
        //               Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
        //               while (entries.hasNext()) {
        //                  Map.Entry<Long, String> entry = entries.next();
        //                  accountIndexes[i] = entry.getKey();
        //                  accounts[i++] = entry.getValue();
        //               }
        //               mDialog = (new AlertDialog.Builder(this))
        //                     .setTitle(R.string.accounts)
        //                     .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           selectFriends(accountIndexes[which]);
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        //                        @Override
        //                        public void onClick(DialogInterface dialog, int which) {
        //                           dialog.dismiss();
        //                        }
        //                     })
        //                     .create();
        //               mDialog.show();
        //            } else
        //               unsupportedToast(sTaggingSupported);
        //         }
    } else if (itemId == R.id.menu_post_location) {
        LocationManager locationManager = (LocationManager) MyfeedleCreatePost.this
                .getSystemService(Context.LOCATION_SERVICE);
        Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        if (location != null) {
            mLat = Double.toString(location.getLatitude());
            mLong = Double.toString(location.getLongitude());
            if (mAccountsService.size() == 1) {
                if (sLocationSupported.contains(mAccountsService.values().iterator().next()))
                    setLocation(mAccountsService.keySet().iterator().next());
                else
                    unsupportedToast(sLocationSupported);
            } else {
                // dialog to select an account
                Iterator<Long> accountIds = mAccountsService.keySet().iterator();
                HashMap<Long, String> accountEntries = new HashMap<Long, String>();
                while (accountIds.hasNext()) {
                    Long accountId = accountIds.next();
                    Cursor account = this.getContentResolver().query(Accounts.getContentUri(this),
                            new String[] { Accounts._ID, ACCOUNTS_QUERY }, Accounts._ID + "=?",
                            new String[] { Long.toString(accountId) }, null);
                    if (account.moveToFirst() && sLocationSupported.contains(mAccountsService.get(accountId)))
                        accountEntries.put(account.getLong(account.getColumnIndex(Accounts._ID)),
                                account.getString(account.getColumnIndex(Accounts.USERNAME)));
                }
                int size = accountEntries.size();
                if (size != 0) {
                    final long[] accountIndexes = new long[size];
                    final String[] accounts = new String[size];
                    int i = 0;
                    Iterator<Map.Entry<Long, String>> entries = accountEntries.entrySet().iterator();
                    while (entries.hasNext()) {
                        Map.Entry<Long, String> entry = entries.next();
                        accountIndexes[i] = entry.getKey();
                        accounts[i++] = entry.getValue();
                    }
                    mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts)
                            .setSingleChoiceItems(accounts, -1, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    setLocation(accountIndexes[which]);
                                    dialog.dismiss();
                                }
                            })
                            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            }).create();
                    mDialog.show();
                } else
                    unsupportedToast(sLocationSupported);
            }
        } else
            (Toast.makeText(this, getString(R.string.location_unavailable), Toast.LENGTH_LONG)).show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.skt.runtime.RuntimeChromeClient.java

public void openFileChooser(ValueCallback<Uri> uploadFile, String acceptType) {
    uploadMessage = uploadFile;//from ww w  .  j a  va 2s  .c o m
    ;
    Intent intent = null;

    //[20130723][chisu]<input type="file"></input>
    if (acceptType.equals("")) {
        //[20120614][chisu]call gallery 
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");

        Intent chooser = createChooserIntent(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE),
                new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE),
                new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION));
        chooser.putExtra(Intent.EXTRA_INTENT, intent);

        ctx.startActivityForResult(chooser, FILE_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="image" accept="image/*" capture>
    else if (acceptType.equals("image/*")) {
        intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        ctx.startActivityForResult(intent, IMAGE_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="video" accept="video/*" capture>
    else if (acceptType.equals("video/*")) {
        intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
        ctx.startActivityForResult(intent, VIDEO_RESULTCODE);
    }
    //[20130723][chisu]<input type="file" name="audio" accept="audio/*" capture>
    else if (acceptType.equals("audio/*")) {
        intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
        ctx.startActivityForResult(intent, AUDIO_RESULTCODE);
    }
    //[20131011][chisu]FIXME:<input type="file" name="image" accept="image/S4" capture>
    else if (acceptType.equals("image/S4")) {
        //[20120614][chisu]call gallery 
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("*/*");

        Intent chooser = createChooserIntent(new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE));
        chooser.putExtra(Intent.EXTRA_INTENT, intent);

        ctx.startActivityForResult(chooser, FILE_RESULTCODE);
    }
}

From source file:TIG055st2014.mailmaster.Activities.ComposeActivity.java

/**
 * Launches chooser for gallery apps and restricts file selection to images.
 *///ww w  .j  a  va  2 s.  c  o  m
public void openGallery() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.putExtra("return-data", true);
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
}

From source file:com.grass.caishi.cc.activity.RegisterActivity.java

/**
 * ?//from  w  w w .  j  a v a2  s .  co m
 */
public void selectPicFromLocal() {
    Intent intent;
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");

        // Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
        /*
         * intent.setType("image/*"); intent.putExtra("crop", "true"); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", 600); intent.putExtra("outputY", 600); intent.putExtra("scale", true); intent.putExtra("return-data", false); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUritest); intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("noFaceDetection", true); // no face detection
         */
        // startActivityForResult(intent, CHOOSE_BIG_PICTURE);
    } else {
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        // startActivityForResult(intent, USERPIC_REQUEST_CODE_LOCAL_19);
    }
    startActivityForResult(intent, USERPIC_REQUEST_CODE_LOCAL);
}

From source file:org.thoughtland.xlocation.ActivityShare.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;// w w  w . java2s . c  o m

    // Get data
    int userId = Util.getUserId(Process.myUid());
    final Bundle extras = getIntent().getExtras();
    final String action = getIntent().getAction();
    final int[] uids = (extras != null && extras.containsKey(cUidList) ? extras.getIntArray(cUidList)
            : new int[0]);
    final String restrictionName = (extras != null ? extras.getString(cRestriction) : null);
    int choice = (extras != null && extras.containsKey(cChoice) ? extras.getInt(cChoice) : -1);
    if (action.equals(ACTION_EXPORT))
        mFileName = (extras != null && extras.containsKey(cFileName) ? extras.getString(cFileName) : null);

    // License check
    if (action.equals(ACTION_IMPORT) || action.equals(ACTION_EXPORT)) {
        if (!Util.isProEnabled() && Util.hasProLicense(this) == null) {
            Util.viewUri(this, ActivityMain.cProUri);
            finish();
            return;
        }
    } else if (action.equals(ACTION_FETCH) || (action.equals(ACTION_TOGGLE) && uids.length > 1)) {
        if (Util.hasProLicense(this) == null) {
            Util.viewUri(this, ActivityMain.cProUri);
            finish();
            return;
        }
    }

    // Registration check
    if (action.equals(ACTION_SUBMIT) && !registerDevice(this)) {
        finish();
        return;
    }

    // Check whether we need a user interface
    if (extras != null && extras.containsKey(cInteractive) && extras.getBoolean(cInteractive, false))
        mInteractive = true;

    // Set layout
    setContentView(R.layout.sharelist);

    // Reference controls
    final TextView tvDescription = (TextView) findViewById(R.id.tvDescription);
    final ScrollView svToggle = (ScrollView) findViewById(R.id.svToggle);
    final RadioGroup rgToggle = (RadioGroup) findViewById(R.id.rgToggle);
    final Spinner spRestriction = (Spinner) findViewById(R.id.spRestriction);
    RadioButton rbClear = (RadioButton) findViewById(R.id.rbClear);
    RadioButton rbTemplateFull = (RadioButton) findViewById(R.id.rbTemplateFull);
    RadioButton rbODEnable = (RadioButton) findViewById(R.id.rbEnableOndemand);
    RadioButton rbODDisable = (RadioButton) findViewById(R.id.rbDisableOndemand);
    final Spinner spTemplate = (Spinner) findViewById(R.id.spTemplate);
    final CheckBox cbClear = (CheckBox) findViewById(R.id.cbClear);
    final Button btnOk = (Button) findViewById(R.id.btnOk);
    final Button btnCancel = (Button) findViewById(R.id.btnCancel);

    // Set title
    if (action.equals(ACTION_TOGGLE)) {
        mActionId = R.string.menu_toggle;
        setTitle(R.string.menu_toggle);
    } else if (action.equals(ACTION_IMPORT)) {
        mActionId = R.string.menu_import;
        setTitle(R.string.menu_import);
    } else if (action.equals(ACTION_EXPORT)) {
        mActionId = R.string.menu_export;
        setTitle(R.string.menu_export);
    } else if (action.equals(ACTION_FETCH)) {
        mActionId = R.string.menu_fetch;
        setTitle(R.string.menu_fetch);
    } else if (action.equals(ACTION_SUBMIT)) {
        mActionId = R.string.menu_submit;
        setTitle(R.string.menu_submit);
    } else {
        finish();
        return;
    }

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build restriction adapter
    SpinnerAdapter saRestriction = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    saRestriction.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    saRestriction.addAll(listRestrictionName);

    // Setup restriction spinner
    int pos = 0;
    if (restrictionName != null)
        for (String restriction : PrivacyManager.getRestrictions(this).values()) {
            pos++;
            if (restrictionName.equals(restriction))
                break;
        }

    spRestriction.setAdapter(saRestriction);
    spRestriction.setSelection(pos);

    // Build template adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.add(getString(R.string.title_default));
    for (int i = 1; i <= 4; i++)
        spAdapter.add(getString(R.string.title_alternate) + " " + i);
    spTemplate.setAdapter(spAdapter);

    // Build application list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, uids);

    // Import/export filename
    if (action.equals(ACTION_EXPORT) || action.equals(ACTION_IMPORT)) {
        // Check for availability of sharing intent
        Intent file = new Intent(Intent.ACTION_GET_CONTENT);
        file.setType("file/*");
        boolean hasIntent = Util.isIntentAvailable(ActivityShare.this, file);

        // Get file name
        if (mFileName == null)
            if (action.equals(ACTION_EXPORT)) {
                String packageName = null;
                if (uids.length == 1)
                    try {
                        ApplicationInfoEx appInfo = new ApplicationInfoEx(this, uids[0]);
                        packageName = appInfo.getPackageName().get(0);
                    } catch (Throwable ex) {
                        Util.bug(null, ex);
                    }
                mFileName = getFileName(this, hasIntent, packageName);
            } else
                mFileName = (hasIntent ? null : getFileName(this, false, null));

        if (mFileName == null)
            fileChooser();
        else
            showFileName();

        if (action.equals(ACTION_IMPORT))
            cbClear.setVisibility(View.VISIBLE);

    } else if (action.equals(ACTION_FETCH)) {
        tvDescription.setText(getBaseURL());
        cbClear.setVisibility(View.VISIBLE);

    } else if (action.equals(ACTION_TOGGLE)) {
        tvDescription.setText(R.string.menu_toggle);
        spRestriction.setVisibility(View.VISIBLE);
        svToggle.setVisibility(View.VISIBLE);

        // Listen for radio button
        rgToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                btnOk.setEnabled(checkedId >= 0);
                spRestriction.setVisibility(
                        checkedId == R.id.rbEnableOndemand || checkedId == R.id.rbDisableOndemand ? View.GONE
                                : View.VISIBLE);

                spTemplate.setVisibility(checkedId == R.id.rbTemplateCategory
                        || checkedId == R.id.rbTemplateFull || checkedId == R.id.rbTemplateMergeSet
                        || checkedId == R.id.rbTemplateMergeReset ? View.VISIBLE : View.GONE);
            }
        });

        boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true);
        rbODEnable.setVisibility(ondemand ? View.VISIBLE : View.GONE);
        rbODDisable.setVisibility(ondemand ? View.VISIBLE : View.GONE);

        if (choice == CHOICE_CLEAR)
            rbClear.setChecked(true);
        else if (choice == CHOICE_TEMPLATE)
            rbTemplateFull.setChecked(true);

    } else
        tvDescription.setText(getBaseURL());

    if (mInteractive) {
        // Enable ok
        // (showFileName does this for export/import)
        if (action.equals(ACTION_SUBMIT) || action.equals(ACTION_FETCH))
            btnOk.setEnabled(true);

        // Listen for ok
        btnOk.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnOk.setEnabled(false);

                // Toggle
                if (action.equals(ACTION_TOGGLE)) {
                    mRunning = true;
                    for (int i = 0; i < rgToggle.getChildCount(); i++)
                        ((RadioButton) rgToggle.getChildAt(i)).setEnabled(false);
                    int pos = spRestriction.getSelectedItemPosition();
                    String restrictionName = (pos == 0 ? null
                            : (String) PrivacyManager.getRestrictions(ActivityShare.this).values().toArray()[pos
                                    - 1]);
                    new ToggleTask().executeOnExecutor(mExecutor, restrictionName);

                    // Import
                } else if (action.equals(ACTION_IMPORT)) {
                    mRunning = true;
                    cbClear.setEnabled(false);
                    new ImportTask().executeOnExecutor(mExecutor, new File(mFileName), cbClear.isChecked());
                }

                // Export
                else if (action.equals(ACTION_EXPORT)) {
                    mRunning = true;
                    new ExportTask().executeOnExecutor(mExecutor, new File(mFileName));

                    // Fetch
                } else if (action.equals(ACTION_FETCH)) {
                    if (uids.length > 0) {
                        mRunning = true;
                        cbClear.setEnabled(false);
                        new FetchTask().executeOnExecutor(mExecutor, cbClear.isChecked());
                    }
                }

                // Submit
                else if (action.equals(ACTION_SUBMIT)) {
                    if (uids.length > 0) {
                        if (uids.length <= cSubmitLimit) {
                            mRunning = true;
                            new SubmitTask().executeOnExecutor(mExecutor);
                        } else {
                            String message = getString(R.string.msg_limit, cSubmitLimit + 1);
                            Toast.makeText(ActivityShare.this, message, Toast.LENGTH_LONG).show();
                            btnOk.setEnabled(false);
                        }
                    }
                }
            }
        });

    } else
        btnOk.setEnabled(false);

    // Listen for cancel
    btnCancel.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mRunning) {
                mAbort = true;
                Toast.makeText(ActivityShare.this, getString(R.string.msg_abort), Toast.LENGTH_LONG).show();
            } else
                finish();
        }
    });
}