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.commonsware.android.documents.consumer.ConsumerFragment.java

private void get() {
    Intent i = new Intent().setType("image/png").setAction(Intent.ACTION_GET_CONTENT)
            .addCategory(Intent.CATEGORY_OPENABLE);

    startActivityForResult(i, REQUEST_GET);
}

From source file:com.android.common.util.IntentUtils.java

/**
 * Choose photo, this photo data will be returned in onActivityResult()
 *
 * @param activity// www .  j a  va 2  s  .c  om
 * @param requestCode
 */
public static void choosePhoto(Activity activity, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    activity.startActivityForResult(intent, requestCode);
}

From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java

/** Called when the activity is first created. */
@Override//from   ww  w .  j a  va2s  . c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* GoogleAnalyticsTracker */
    Log.i(TAG, "GoogleAnalytics Setup");
    tracker_ = GoogleAnalyticsTracker.getInstance();
    tracker_.start(getString(R.string.GoogleAnalyticsUA), this);

    /* set Full Screen */
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    /* set window with no title bar */
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    /* Restore preferences */
    SharedPreferences settings = getSharedPreferences(getString(R.string.SnapFacePreference), 0);
    appMode_ = settings.getInt(getString(R.string.menu_AppMode), 0);
    fdetLevel_ = settings.getInt(getString(R.string.menu_Preferences), 1);

    //implicit intent receiver(GET_CONTENT will be invoked to add contact thumbnail)
    if (Intent.ACTION_GET_CONTENT.equals(getIntent().getAction())) {
        Log.i(TAG, "implicit intent:ACTION_GET_CONTENT");
        calledACTION_GET_CONTENT_ = true;
        appMode_ = 0;
    }

    /* create camera view */
    camPreview_ = new PreviewView(this, calledACTION_GET_CONTENT_, tracker_);
    camPreview_.setAppMode(appMode_);
    camPreview_.setfdetLevel(fdetLevel_, true);
    setContentView(camPreview_);
    /* append Overlay */
    addContentView(camPreview_.getOverlay(),
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}

From source file:com.github.chenxiaolong.dualbootpatcher.FileUtils.java

private static Intent buildSafGetContentIntent(String mimeType) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    setCommonNativeSafOptions(intent);/*w w w.  jav a2 s  .com*/
    setCommonOpenOptions(intent, mimeType);
    return intent;
}

From source file:com.alanddev.gmscall.fragment.DeviceDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    mContentView = inflater.inflate(R.layout.device_detail, null);
    mContentView.findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() {

        @Override//  w w  w.j a va2  s .c  o  m
        public void onClick(View v) {
            WifiP2pConfig config = new WifiP2pConfig();
            config.deviceAddress = device.deviceAddress;
            config.wps.setup = WpsInfo.PBC;
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
            progressDialog = ProgressDialog.show(getActivity(), "Press back to cancel",
                    "Connecting to :" + device.deviceAddress, true, true
            //                        new DialogInterface.OnCancelListener() {
            //
            //                            @Override
            //                            public void onCancel(DialogInterface dialog) {
            //                                ((DeviceActionListener) getActivity()).cancelDisconnect();
            //                            }
            //                        }
            );
            ((DeviceListFragment.DeviceActionListener) getParentFragment()).connect(config);

        }
    });

    mContentView.findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((DeviceListFragment.DeviceActionListener) getParentFragment()).disconnect();
        }
    });

    mContentView.findViewById(R.id.btn_start_client).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // Allow user to pick an image from Gallery or other
            // registered apps
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(intent, CHOOSE_FILE_RESULT_CODE);
        }
    });

    return mContentView;
}

From source file:zuo.biao.library.ui.SelectPictureActivity.java

/**
 * ?/*  w  w w  . j  av  a2 s. c  om*/
 */
public void selectPicFromLocal() {
    Intent intent;
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
    } else {
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    }
    toActivity(intent, REQUEST_CODE_LOCAL);
}

From source file:com.github.jokar.rxupload.MainActivity.java

public void selectFile(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");//????
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, RESULT_SELECT_FILE);
}

From source file:com.cbtec.eliademy.EliademyLms.java

/**
 * Executes the request./*  w  w w . j a v  a 2s  .c  o  m*/
 * 
 * This method is called from the WebView thread. To do a non-trivial amount
 * of work, use: cordova.getThreadPool().execute(runnable);
 * 
 * To run on the UI thread, use:
 * cordova.getActivity().runOnUiThread(runnable);
 * 
 * @param action
 *            The action to execute.
 * @param rawArgs
 *            The exec() arguments in JSON form.
 * @param callbackContext
 *            The callback context used when calling back into JavaScript.
 * @return Whether the action was valid.
 * @throws JSONException
 */
@Override
public boolean execute(String action, JSONArray data, final CallbackContext callbackContext)
        throws JSONException {

    Log.i("HLMS", action);

    if ((action.compareTo("openfilesrv") == 0)) {
        try {
            Uri fileuri = Uri.parse(data.getString(0));
            Intent intent = new Intent(Intent.ACTION_VIEW);
            String mimeextn = android.webkit.MimeTypeMap.getFileExtensionFromUrl(data.getString(0));
            if (mimeextn.isEmpty()) {
                mimeextn = data.getString(0).substring(data.getString(0).indexOf(".") + 1);
                ;
            }
            String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(mimeextn);
            Log.i("HLMS", fileuri + "  " + mimetype);
            intent.setDataAndType(fileuri, mimetype);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            cordova.getActivity().getApplicationContext().startActivity(intent);
            callbackContext.success();
        } catch (Exception e) {
            Log.e("HLMS", "exception", e);
            callbackContext.error(0);
        }
        return true;
    } else if ((action.compareTo("getfilesrv") == 0)) {
        this.mCallbackContext = callbackContext;
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                    intent.setType("*/*");// TODO: Restrict file types
                    cordova.startActivityForResult(EliademyLms.this, intent, submitFileCode);
                } catch (Exception e) {
                    Log.e("HLMS", "exception", e);
                    callbackContext.error(0);
                }
                return;
            }
        });
    } else if ((action.compareTo("initservice") == 0)) {
        if (!mIsBound) {
            this.mCallbackContext = callbackContext;
            JSONObject tmp = new JSONObject(data.getString(0));
            String sname = tmp.getString("servicename");
            if (sname.contains("eliademy")) {
                mServiceName = "com.cbtec.serviceeliademy";
            } else {
                // From url determine version 2.2, 2.3, 2.4 and change
                mServiceName = "com.cbtec.service" + sname;
            }
            Log.i("HLMS", "Connecting to service: " + mServiceName);
            doBindService();
        } else {
            callbackContext.success();
        }
        return true;
    } else {
        final String aAction = action;
        final JSONArray aData = data;
        String mappedCmd = null;
        try {
            mappedCmd = mapExecCommand(aData.getString(0));
        } catch (JSONException e) {
            Log.e("HLMS", "exception", e);
        }
        if (mappedCmd == null) {
            Log.i("HLMS", "LMS service call failed " + mappedCmd);
            callbackContext.error(0);// TODO : error enum
            return false;
        }

        final String execCmd = mappedCmd;
        cordova.getThreadPool().execute(new Runnable() {
            @Override
            @SuppressLint("NewApi")
            public void run() {
                Log.i("HLMS", "Runner execute " + aAction + aData.toString());
                if (aAction.compareTo("lmsservice") == 0) {
                    try {
                        String retval = null;
                        Log.i("HLMS", "Execute cmd: " + execCmd);
                        if (execCmd.compareTo("initialize") == 0) {
                            if (mIBinder.initializeService(aData.getString(1))) {
                                String token = mIBinder.eliademyGetWebServiceToken();
                                callbackContext.success(token);
                                return;
                            }
                        } else if (execCmd.compareTo("deinitialize") == 0) {
                            if (mIBinder.deInitializeService(aData.getString(1))) {
                                doUnbindService();
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("pushregister") == 0) {
                            Log.i("pushdata", aData.getString(1));
                            if (mIBinder.registerPushNotifications(aData.getString(1))) {
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("pushunregister") == 0) {
                            Log.i("pushdata", aData.getString(1));
                            if (mIBinder.unregisterPushNotifications(aData.getString(1))) {
                                callbackContext.success();
                                return;
                            }
                        } else if (execCmd.compareTo("servicetoken") == 0) {
                            retval = mIBinder.eliademyGetWebServiceToken();
                        } else if (execCmd.compareTo("siteinfo") == 0) {
                            retval = mIBinder.eliademyGetSiteInformation(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_courses") == 0) {
                            retval = mIBinder.eliademyGetUsersCourses(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_forums") == 0) {
                            retval = mIBinder.eliademyGetUserForums(aData.getString(1));
                        } else if (execCmd.compareTo("get_user_info") == 0) {
                            retval = mIBinder.eliademyGetUserInformation(aData.getString(1));
                        } else if (execCmd.compareTo("exec_webservice") == 0) {
                            Log.i("HLMS", "Execute webservice");
                            retval = mIBinder.eliademyExecWebService(aData.getString(0), aData.getString(1));
                        } else if (execCmd.compareTo("course_get_contents") == 0) {
                            retval = mIBinder.eliademyGetCourseContents(aData.getString(1));
                        } else if (execCmd.compareTo("course_get_enrolled_users") == 0) {
                            retval = mIBinder.eliademyGetEnrolledUsers(aData.getString(1));
                        } else {
                            Log.i("HLMS", "LMS service failed " + execCmd);
                            callbackContext.error(0);// TODO : error enum
                        }
                        if (!retval.isEmpty()) {
                            Log.i("HLMS", "LMS service call success");
                            callbackContext.success(retval);
                        } else {
                            Log.i("HLMS", "LMS service call failed");
                            callbackContext.error(0);// TODO : error enum
                        }
                    } catch (Exception e) {
                        Log.e("HLMS", "exception", e);
                        callbackContext.error(e.getMessage());
                        return;
                    }
                } else {
                    Log.i("LMS", "Unsupported action call !!");
                    callbackContext.error(0);
                    return;
                }
            }
        });
    }
    return true;
}

From source file:com.grottworkshop.gwswizardpager.ui.ImageFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_page_image, container, false);
    ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle());

    imageView = (ImageView) rootView.findViewById(R.id.imageView);

    String imageData = mPage.getData().getString(Page.SIMPLE_DATA_KEY);
    if (!TextUtils.isEmpty(imageData)) {
        Uri imageUri = Uri.parse(imageData);
        imageView.setImageURI(imageUri);
    } else {/*from   w w  w  .j a  va 2 s  .com*/
        imageView.setImageResource(R.drawable.ic_person);
    }

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DialogFragment pickPhotoSourceDialog = new DialogFragment() {
                @NonNull
                @Override
                public Dialog onCreateDialog(Bundle savedInstanceState) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setItems(R.array.image_photo_sources, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            switch (which) {
                            case 0:
                                // Gallery
                                Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, GALLERY_REQUEST_CODE);
                                break;

                            default:
                                // Camera
                                mNewImageUri = getActivity().getContentResolver().insert(
                                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
                                Intent photoFromCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                photoFromCamera.putExtra(MediaStore.EXTRA_OUTPUT, mNewImageUri);
                                photoFromCamera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
                                startActivityForResult(photoFromCamera, CAMERA_REQUEST_CODE);
                                break;
                            }

                        }
                    });
                    return builder.create();
                }
            };

            pickPhotoSourceDialog.show(getFragmentManager(), "pickPhotoSourceDialog");
        }
    });

    return rootView;
}

From source file:cx.ring.fragments.MediaPreferenceFragment.java

public void performFileSearch(int requestCodeToSet) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("audio/*");
    startActivityForResult(intent, requestCodeToSet);
}