Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

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

Prototype

String ACTION_PICK

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

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:org.egov.android.view.activity.EditProfileActivity.java

/**
 * Function called when choosing the gallery option. Start the implicit intent ACTION_PICK for
 * result.//from   w  w w  .  j av  a2s  .  co m
 */
private void _openGalleryImages() {
    Intent photo_picker = new Intent();
    photo_picker.setAction(Intent.ACTION_PICK);
    photo_picker.setType("image/*");
    startActivityForResult(photo_picker, FROM_GALLERY);
}

From source file:org.akvo.rsr.up.UpdateEditorActivity.java

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

    mUser = SettingsUtil.getAuthUser(this);
    nextLocalId = SettingsUtil.ReadInt(this, ConstantUtil.LOCAL_ID_KEY, -1);

    // find which update we are editing
    // null means create a new one
    Bundle extras = getIntent().getExtras();
    projectId = extras != null ? extras.getString(ConstantUtil.PROJECT_ID_KEY) : null;
    if (projectId == null) {
        DialogUtil.errorAlert(this, R.string.noproj_dialog_title, R.string.noproj_dialog_msg);
    }/* ww  w.  java2s .c om*/
    updateId = extras != null ? extras.getString(ConstantUtil.UPDATE_ID_KEY) : null;
    if (updateId == null) {
        updateId = savedInstanceState != null ? savedInstanceState.getString(ConstantUtil.UPDATE_ID_KEY) : null;
    }

    //Limit what we can write 
    InputFilter postFilter = new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            boolean keepOriginal = true;
            StringBuilder sb = new StringBuilder(end - start);
            for (int i = start; i < end; i++) {
                char c = source.charAt(i);
                if (isCharAllowed(c)) // put your condition here
                    sb.append(c);
                else
                    keepOriginal = false;
            }
            if (keepOriginal)
                return null;
            else {
                if (source instanceof Spanned) {
                    SpannableString sp = new SpannableString(sb);
                    TextUtils.copySpansFrom((Spanned) source, start, sb.length(), null, sp, 0);
                    return sp;
                } else {
                    return sb;
                }
            }
        }

        private boolean isCharAllowed(char c) {
            //                    return !Character.isSurrogate(c); //From API 19
            return !(c >= 0xD800 && c <= 0xDFFF);
        }
    };

    // get the look
    setContentView(R.layout.activity_update_editor);
    // find the fields
    progressGroup = findViewById(R.id.sendprogress_group);
    uploadProgress = (ProgressBar) findViewById(R.id.sendProgressBar);
    projTitleLabel = (TextView) findViewById(R.id.projupd_edit_proj_title);
    projupdTitleCount = (TextView) findViewById(R.id.projupd_edit_titlecount);
    projupdTitleCount.setText(Integer.toString(TITLE_LENGTH));
    projupdTitleText = (EditText) findViewById(R.id.projupd_edit_title);
    projupdTitleText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(TITLE_LENGTH), postFilter });
    projupdTitleText.addTextChangedListener(new TextWatcher() {
        //Show count of remaining characters
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            projupdTitleCount.setText(String.valueOf(TITLE_LENGTH - s.length()));
        }

        public void afterTextChanged(Editable s) {
        }
    });
    projupdDescriptionText = (EditText) findViewById(R.id.projupd_edit_description);
    projupdDescriptionText.setFilters(new InputFilter[] { postFilter });
    projupdImage = (ImageView) findViewById(R.id.image_update_detail);
    photoAndToolsGroup = findViewById(R.id.image_with_tools);
    photoAddGroup = findViewById(R.id.photo_buttons);
    photoCaptionText = (EditText) findViewById(R.id.projupd_edit_photo_caption);
    photoCaptionText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(75), postFilter });
    photoCreditText = (EditText) findViewById(R.id.projupd_edit_photo_credit);
    photoCreditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25), postFilter });

    positionGroup = findViewById(R.id.position_group);
    latField = (TextView) findViewById(R.id.latitude);
    lonField = (TextView) findViewById(R.id.longitude);
    eleField = (TextView) findViewById(R.id.elevation);
    accuracyField = (TextView) findViewById(R.id.gps_accuracy);
    searchingIndicator = (TextView) findViewById(R.id.gps_searching);
    gpsProgress = (ProgressBar) findViewById(R.id.progress_gps);

    // Activate buttons
    btnSubmit = (Button) findViewById(R.id.btn_send_update);
    btnSubmit.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            sendUpdate();
        }
    });

    btnDraft = (Button) findViewById(R.id.btn_save_draft);
    btnDraft.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            saveAsDraft(true);
        }
    });

    btnTakePhoto = (Button) findViewById(R.id.btn_take_photo);
    btnTakePhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            // generate unique filename
            captureFilename = FileUtil.getExternalPhotoDir(UpdateEditorActivity.this) + File.separator
                    + "capture" + System.nanoTime() + ".jpg";
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(captureFilename)));
            startActivityForResult(takePictureIntent, photoRequest);
        }
    });

    btnAttachPhoto = (Button) findViewById(R.id.btn_attach_photo);
    btnAttachPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, photoPick);
        }
    });

    btnDelPhoto = (Button) findViewById(R.id.btn_delete_photo);
    btnDelPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // Forget image
            update.setThumbnailFilename(null);
            // TODO: delete image file if it was taken through this app?
            // Hide photo w tools
            showPhoto(false);
        }
    });

    btnRotRightPhoto = (Button) findViewById(R.id.btn_rotate_photo_r);
    btnRotRightPhoto.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            // Rotate image right
            rotatePhoto(true);
        }
    });

    btnGpsGeo = (Button) findViewById(R.id.btn_gps_position);
    btnGpsGeo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onGetGPSClick(view);
        }
    });

    btnPhotoGeo = (Button) findViewById(R.id.btn_photo_position);
    btnPhotoGeo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onGetPhotoLocationClick(view);
        }
    });

    dba = new RsrDbAdapter(this);
    dba.open();

    Project project = dba.findProject(projectId);
    projTitleLabel.setText(project.getTitle());

    if (updateId == null) { // create new
        update = new Update();
        update.setUuid(UUID.randomUUID().toString()); // should do sth
                                                      // better, especially
                                                      // if MAC address is
                                                      // avaliable
                                                      /*
                                                       * WifiManager wifiManager = (WifiManager)
                                                       * getSystemService(Context.WIFI_SERVICE); WifiInfo wInfo =
                                                       * wifiManager.getConnectionInfo(); String macAddress =
                                                       * wInfo.getMacAddress(); if (macAddress == null) txt_View.append(
                                                       * "MAC Address : " + macAddress + "\n" ); else txt_View.append(
                                                       * "MAC Address : " + macAddress + "\n" ); }
                                                       */
        update.setUserId(mUser.getId());
        update.setDate(new Date());
        editable = true;
    } else {
        update = dba.findUpdate(updateId);
        if (update == null) {
            DialogUtil.errorAlert(this, R.string.noupd_dialog_title, R.string.noupd2_dialog_msg);
        } else {
            // populate fields
            editable = update.getDraft(); // This should always be true with
                                          // the current UI flow - we go to
                                          // UpdateDetailActivity if it is sent
            if (update.getTitle().equals(TITLE_PLACEHOLDER)) {
                projupdTitleText.setText(""); //placeholder is just to satisfy db
            } else {
                projupdTitleText.setText(update.getTitle());
            }
            projupdDescriptionText.setText(update.getText());
            photoCaptionText.setText(update.getPhotoCaption());
            photoCreditText.setText(update.getPhotoCredit());
            latField.setText(update.getLatitude());
            lonField.setText(update.getLongitude());
            eleField.setText(update.getElevation());
            if (update.validLatLon()) {
                positionGroup.setVisibility(View.VISIBLE);
            }
            // show preexisting image
            if (update.getThumbnailFilename() != null) {
                // btnTakePhoto.setText(R.string.btncaption_rephoto);
                ThumbnailUtil.setPhotoFile(projupdImage, update.getThumbnailUrl(),
                        update.getThumbnailFilename(), null, null, false);
                photoLocation = FileUtil.exifLocation(update.getThumbnailFilename());
                showPhoto(true);
            }
        }
    }

    // register a listener for a completion and progress intents
    broadRec = new ResponseReceiver();
    IntentFilter f = new IntentFilter(ConstantUtil.UPDATES_SENT_ACTION);
    f.addAction(ConstantUtil.UPDATES_SENDPROGRESS_ACTION);
    LocalBroadcastManager.getInstance(this).registerReceiver(broadRec, f);

    enableChanges(editable);
    btnDraft.setVisibility(editable ? View.VISIBLE : View.GONE);
    btnSubmit.setVisibility(editable ? View.VISIBLE : View.GONE);
    // btnTakePhoto.setVisibility(editable?View.VISIBLE:View.GONE);

    // Show the Up button in the action bar.
    // setupActionBar();
}

From source file:com.zlkj.dingdangwuyou.activity.CompanyInfoActivity.java

/**
 * ?//  w ww .  j a  va2  s .  c  om
 */
private void showAvatarOption() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    String[] items = new String[] { "?", "" };
    builder.setTitle("").setItems(items, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent();
            switch (which) {
            case 0: // ?
                if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
                    String curTime = AppTool.dateFormat(System.currentTimeMillis(), "yyyyMMddHHmmss");
                    // ???
                    File imagePath = new File(Environment.getExternalStorageDirectory() + Const.APP_IMAGE_PATH);
                    if (!imagePath.exists()) {
                        imagePath.mkdirs();
                    }
                    cameraFile = new File(imagePath.getPath(), curTime + ".jpg");

                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile));
                    startActivityForResult(intent, Const.REQUEST_CODE_CAMERA);

                } else {
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            case 1: // 
                intent.setAction(Intent.ACTION_PICK);
                intent.setType("image/*");
                startActivityForResult(intent, Const.REQUEST_CODE_GALLERY);
                break;

            default:
                break;
            }
        }
    });

    builder.show();
}

From source file:net.potterpcs.recipebook.RecipeEditor.java

public void onAttachPhoto(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, GALLERY_ACTIVITY);
}

From source file:com.insthub.O2OMobile.Activity.F9_SettingActivity.java

private void showDialog() {
    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.photo_dialog, null);
    mDialog = new Dialog(this, R.style.dialog);
    mDialog.setContentView(view);// w w  w .  ja  va  2s  .c  om

    mDialog.setCanceledOnTouchOutside(true);
    mDialog.show();
    LinearLayout requsetCameraLayout = (LinearLayout) view.findViewById(R.id.register_camera);
    LinearLayout requestPhotoLayout = (LinearLayout) view.findViewById(R.id.register_photo);

    requsetCameraLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            if (mFileDir == null) {
                mFileDir = new File(O2OMobileAppConst.FILEPATH + "img/");
                if (!mFileDir.exists()) {
                    mFileDir.mkdirs();
                }
            }
            mFileName = O2OMobileAppConst.FILEPATH + "img/" + "temp.jpg";
            mFile = new File(mFileName);
            Uri imageuri = Uri.fromFile(mFile);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageuri);
            intent.putExtra("return-data", false);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    });

    requestPhotoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mDialog.dismiss();
            Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(picture, REQUEST_PHOTO);

        }
    });
}

From source file:com.ola.insta.BookingAcivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub

    switch (item.getItemId()) {
    case R.id.menu_emergency_contact:

        PreferenceManager pref = new PreferenceManager(context);
        final String contactName = pref.getStringData((Constants.EMERGENCY_CONTACT_NAME));
        final String phoneNum = pref.getStringData((Constants.EMERGENCY_CONTACT_NUMBER));

        if (contactName != null && phoneNum != null) {
            MaterialDialog dialog = new MaterialDialog(context, context.getString(R.string.emergency_contact),
                    "Name : " + contactName + "\nNumber : " + phoneNum, context.getString(R.string.update),
                    context.getString(R.string.cancel));
            dialog.setOnAcceptButtonClickListener(new OnClickListener() {

                @Override//w  ww .java 2 s  . com
                public void onClick(View v) {

                    Intent i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
                    startActivityForResult(i, REQ_CODE_SELECT_CONTACT);
                }
            });
            dialog.setOnCancelButtonClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {

                }
            });
            dialog.show();
        } else {
            Intent i = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
            super.startActivityForResult(i, REQ_CODE_SELECT_CONTACT);
        }

        break;

    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.melvin.share.zxing.activity.CaptureActivity.java

/**
 * toolbar??/*from ww w.j a  v a2s  .c o  m*/
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();
        return true;
    case R.id.camera:
        Intent pickIntent = new Intent(Intent.ACTION_PICK, null);
        // ??"image/jpeg ? image/png"
        pickIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
        startActivityForResult(pickIntent, 10);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.facebook.android.Hackbook.java

@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
    switch (position) {
    /*//from ww  w  .j  a  v  a 2  s  .c om
     * Source Tag: update_status_tag Update user's status by invoking the
     * feed dialog To post to a friend's wall, provide his uid in the 'to'
     * parameter Refer to
     * https://developers.facebook.com/docs/reference/dialogs/feed/ for more
     * info.
     */
    case 0: {
        Bundle params = new Bundle();
        params.putString("caption", getString(R.string.app_name));
        params.putString("description", getString(R.string.app_desc));
        params.putString("picture", Utility.HACK_ICON_URL);
        params.putString("name", getString(R.string.app_action));

        Utility.mFacebook.dialog(Hackbook.this, "feed", params, new UpdateStatusListener());
        String access_token = Utility.mFacebook.getAccessToken();
        System.out.println(access_token);
        break;
    }

    /*
     * Source Tag: app_requests Send an app request to friends. If no
     * friend is specified, the user will see a friend selector and will
     * be able to select a maximum of 50 recipients. To send request to
     * specific friend, provide the uid in the 'to' parameter Refer to
     * https://developers.facebook.com/docs/reference/dialogs/requests/
     * for more info.
     */
    case 1: {
        Bundle params = new Bundle();
        params.putString("message", getString(R.string.request_message));
        Utility.mFacebook.dialog(Hackbook.this, "apprequests", params, new AppRequestsListener());
        break;
    }

    /*
     * Source Tag: friends_tag You can get friends using
     * graph.facebook.com/me/friends, this returns the list sorted by
     * UID OR using the friend table. With this you can sort the way you
     * want it.
     * Friend table - https://developers.facebook.com/docs/reference/fql/friend/
     * User table - https://developers.facebook.com/docs/reference/fql/user/
     */
    case 2: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            dialog = ProgressDialog.show(Hackbook.this, "", getString(R.string.please_wait), true, true);
            new AlertDialog.Builder(this).setTitle(R.string.Graph_FQL_title).setMessage(R.string.Graph_FQL_msg)
                    .setPositiveButton(R.string.graph_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            graph_or_fql = "graph";
                            Bundle params = new Bundle();
                            params.putString("fields", "name, picture, location");
                            Utility.mAsyncRunner.request("me/friends", params, new FriendsRequestListener());
                        }

                    }).setNegativeButton(R.string.fql_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            graph_or_fql = "fql";
                            String query = "select name, current_location, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by name";
                            Bundle params = new Bundle();
                            params.putString("method", "fql.query");
                            params.putString("query", query);
                            Utility.mAsyncRunner.request(null, params, new FriendsRequestListener());
                        }

                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            dialog.dismiss();
                        }
                    }).show();
        }
        break;
    }

    /*
     * Source Tag: upload_photo You can upload a photo from the media
     * gallery or from a remote server How to upload photo:
     * https://developers.facebook.com/blog/post/498/
     */
    case 3: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            dialog = ProgressDialog.show(Hackbook.this, "", getString(R.string.please_wait), true, true);
            new AlertDialog.Builder(this).setTitle(R.string.gallery_remote_title)
                    .setMessage(R.string.gallery_remote_msg)
                    .setPositiveButton(R.string.gallery_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_PICK,
                                    (MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
                            startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE);
                        }

                    }).setNegativeButton(R.string.remote_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            /*
                             * Source tag: upload_photo_tag
                             */
                            Bundle params = new Bundle();
                            params.putString("url",
                                    "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
                            params.putString("caption", "FbAPIs Sample App photo upload");
                            Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(),
                                    null);
                        }

                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            dialog.dismiss();
                        }
                    }).show();
        }
        break;
    }

    /*
     * User can check-in to a place, you require publish_checkins
     * permission for that. You can use the default Times Square
     * location or fetch user's current location. Get user's checkins:
     * https://developers.facebook.com/docs/reference/api/checkin/
     */
    case 4: {
        final Intent myIntent = new Intent(getApplicationContext(), Places.class);

        new AlertDialog.Builder(this).setTitle(R.string.get_location)
                .setMessage(R.string.get_default_or_new_location)
                .setPositiveButton(R.string.current_location_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        myIntent.putExtra("LOCATION", "current");
                        startActivity(myIntent);
                    }
                }).setNegativeButton(R.string.times_square_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        myIntent.putExtra("LOCATION", "times_square");
                        startActivity(myIntent);
                    }

                }).show();
        break;
    }

    case 5: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            new FQLQuery(Hackbook.this).show();
        }
        break;
    }
    /*
     * This is advanced feature where you can request new permissions
     * Browser user's graph, his fields and connections. This is similar
     * to the www version:
     * http://developers.facebook.com/tools/explorer/
     */
    case 6: {
        Intent myIntent = new Intent(getApplicationContext(), GraphExplorer.class);
        if (Utility.mFacebook.isSessionValid()) {
            Utility.objectID = "me";
        }
        startActivity(myIntent);
        break;
    }

    case 7: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            new TokenRefreshDialog(Hackbook.this).show();
        }
    }
    }
}

From source file:net.potterpcs.recipebook.RecipeEditor.java

public void onAttachDirectionPhoto(int position) {
    // We let the system do the hard work of finding a picture to attach.
    Intent intent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, RecipeEditor.DIRECTION_PHOTO_ATTACH + position);
}

From source file:org.comu.homescreen.Hackbook.java

@Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
    switch (position) {
    /*/*ww w. ja  va  2  s.c o  m*/
    * Source Tag: update_status_tag
    * Update user's status by invoking the feed dialog
    * To post to a friend's wall, provide his uid in the 'to' parameter
    * Refer to https://developers.facebook.com/docs/reference/dialogs/feed/ for more info.
    */
    case 0: {
        Bundle params = new Bundle();
        params.putString("caption", getString(R.string.app_name));
        params.putString("description", getString(R.string.app_desc));
        params.putString("picture", Utility.HACK_ICON_URL);
        params.putString("name", getString(R.string.app_action));

        Utility.mFacebook.dialog(Hackbook.this, "feed", params, new UpdateStatusListener());
        String access_token = Utility.mFacebook.getAccessToken();
        System.out.println(access_token);
        break;
    }

    /*
     * Source Tag: app_requests
     * Send an app request to friends. If no friend is specified, the user will see a friend selector and will be able to select a maximum of 50 recipients.
     * To send request to specific friend, provide the uid in the 'to' parameter
     * Refer to https://developers.facebook.com/docs/reference/dialogs/requests/ for more info.
     */
    case 1: {
        Bundle params = new Bundle();
        params.putString("message", getString(R.string.request_message));
        Utility.mFacebook.dialog(Hackbook.this, "apprequests", params, new AppRequestsListener());
        break;
    }

    /*
     * Source Tag: friends_tag
     * You can get friends using graph.facebook.com/me/friends, this returns the list sorted by UID
     * OR
     * using the friend table. With this you can sort the way you want it.
     * friend table - https://developers.facebook.com/docs/reference/fql/friend/
     * user table - https://developers.facebook.com/docs/reference/fql/user/ 
     */
    case 2: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            dialog = ProgressDialog.show(Hackbook.this, "", getString(R.string.please_wait), true, true);
            new AlertDialog.Builder(this).setTitle(R.string.Graph_FQL_title).setMessage(R.string.Graph_FQL_msg)
                    .setPositiveButton(R.string.graph_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            graph_or_fql = "graph";
                            Bundle params = new Bundle();
                            params.putString("fields", "name, picture, location");
                            Utility.mAsyncRunner.request("me/friends", params, new FriendsRequestListener());
                        }

                    }).setNegativeButton(R.string.fql_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            graph_or_fql = "fql";
                            String query = "select name, current_location, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by name";
                            Bundle params = new Bundle();
                            params.putString("method", "fql.query");
                            params.putString("query", query);
                            Utility.mAsyncRunner.request(null, params, new FriendsRequestListener());
                        }

                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            dialog.dismiss();
                        }
                    }).show();
        }
        break;
    }

    /*
     * Source Tag: upload_photo
     * You can upload a photo from the media gallery or from a remote server
     * How to upload photo: https://developers.facebook.com/blog/post/498/
     */
    case 3: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            dialog = ProgressDialog.show(Hackbook.this, "", getString(R.string.please_wait), true, true);
            new AlertDialog.Builder(this).setTitle(R.string.gallery_remote_title)
                    .setMessage(R.string.gallery_remote_msg)
                    .setPositiveButton(R.string.gallery_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Intent intent = new Intent(Intent.ACTION_PICK,
                                    (MediaStore.Images.Media.EXTERNAL_CONTENT_URI));
                            startActivityForResult(intent, PICK_EXISTING_PHOTO_RESULT_CODE);
                        }

                    }).setNegativeButton(R.string.remote_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            /*
                             * Source tag: upload_photo_tag
                             */
                            Bundle params = new Bundle();
                            params.putString("url",
                                    "http://www.facebook.com/images/devsite/iphone_connect_btn.jpg");
                            params.putString("caption", "FbAPIs Sample App photo upload");
                            Utility.mAsyncRunner.request("me/photos", params, "POST", new PhotoUploadListener(),
                                    null);
                        }

                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface d) {
                            dialog.dismiss();
                        }
                    }).show();
        }
        break;
    }

    /*
    * User can check-in to a place, you require publish_checkins permission for that.
    * You can use the default Times Square location or fetch user's current location
    * Get user's checkins - https://developers.facebook.com/docs/reference/api/checkin/
    */
    case 4: {
        final Intent myIntent = new Intent(getApplicationContext(), Places.class);

        new AlertDialog.Builder(this).setTitle(R.string.get_location)
                .setMessage(R.string.get_default_or_new_location)
                .setPositiveButton(R.string.current_location_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        myIntent.putExtra("LOCATION", "current");
                        startActivity(myIntent);
                    }
                }).setNegativeButton(R.string.times_square_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        myIntent.putExtra("LOCATION", "times_square");
                        startActivity(myIntent);
                    }

                }).show();
        break;
    }

    case 5: {
        if (!Utility.mFacebook.isSessionValid()) {
            Util.showAlert(this, "Warning", "You must first log in.");
        } else {
            new FQLQuery(Hackbook.this).show();
        }
        break;
    }
    /*
    * This is advanced feature where you can request new permissions
    * Browser user's graph, his fields and connections.
    * This is similar to the www version - http://developers.facebook.com/tools/explorer/
    */
    case 6: {
        Intent myIntent = new Intent(getApplicationContext(), GraphExplorer.class);
        if (Utility.mFacebook.isSessionValid()) {
            Utility.objectID = "me";
        }
        startActivity(myIntent);
        break;
    }
    }
}