Example usage for android.content Intent ACTION_OPEN_DOCUMENT

List of usage examples for android.content Intent ACTION_OPEN_DOCUMENT

Introduction

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

Prototype

String ACTION_OPEN_DOCUMENT

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

Click Source Link

Document

Activity Action: Allow the user to select and return one or more existing documents.

Usage

From source file:ru.innopolis.architecture.gstar.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mUsername = ANONYMOUS;//from   ww  w . ja  v  a 2 s  . c  om

    // Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();

    if (mFirebaseUser == null) {
        // Not signed in, launch the Sign In activity
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
    }

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API).build();

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);

    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class,
            R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {

        @Override
        protected FriendlyMessage parseSnapshot(DataSnapshot snapshot) {
            FriendlyMessage friendlyMessage = super.parseSnapshot(snapshot);
            if (friendlyMessage != null) {
                friendlyMessage.setId(snapshot.getKey());
            }
            return friendlyMessage;
        }

        @Override
        protected void populateViewHolder(final MessageViewHolder viewHolder, FriendlyMessage friendlyMessage,
                int position) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            if (friendlyMessage.getText() != null) {
                viewHolder.messageTextView.setText(friendlyMessage.getText());
                viewHolder.messageTextView.setVisibility(TextView.VISIBLE);
                viewHolder.messageImageView.setVisibility(ImageView.GONE);
            } else {
                String imageUrl = friendlyMessage.getImageUrl();
                if (imageUrl.startsWith("gs://")) {
                    StorageReference storageReference = FirebaseStorage.getInstance()
                            .getReferenceFromUrl(imageUrl);
                    storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
                        @Override
                        public void onComplete(@NonNull Task<Uri> task) {
                            if (task.isSuccessful()) {
                                String downloadUrl = task.getResult().toString();
                                Glide.with(viewHolder.messageImageView.getContext()).load(downloadUrl)
                                        .into(viewHolder.messageImageView);
                            } else {
                                Log.w(TAG, "Getting download url was not successful.", task.getException());
                            }
                        }
                    });
                } else {
                    Glide.with(viewHolder.messageImageView.getContext()).load(friendlyMessage.getImageUrl())
                            .into(viewHolder.messageImageView);
                }
                viewHolder.messageImageView.setVisibility(ImageView.VISIBLE);
                viewHolder.messageTextView.setVisibility(TextView.GONE);
            }

            viewHolder.messengerTextView.setText(friendlyMessage.getName());
            if (friendlyMessage.getPhotoUrl() == null) {
                viewHolder.messengerImageView.setImageDrawable(
                        ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_account_circle_black_36dp));
            } else {
                Glide.with(MainActivity.this).load(friendlyMessage.getPhotoUrl())
                        .into(viewHolder.messengerImageView);
            }

            if (friendlyMessage.getText() != null) {
                // write this message to the on-device index
                FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage));
            }

            // log a view action on it
            FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage));
        }
    };

    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // If the recycler view is initially being loaded or the user is at the bottom of the list, scroll
            // to the bottom of the list to show the newly added message.
            if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1)
                    && lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });

    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);

    // Initialize Firebase Measurement.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    // Initialize Firebase Remote Config.
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

    // Define Firebase Remote Config Settings.
    FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder()
            .setDeveloperModeEnabled(true).build();

    // Define default config values. Defaults are used when fetched config values are not
    // available. Eg: if an error occurred fetching values from the server.
    Map<String, Object> defaultConfigMap = new HashMap<>();
    defaultConfigMap.put("friendly_msg_length", 100L);

    // Apply config settings and default values.
    mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings);
    mFirebaseRemoteConfig.setDefaults(defaultConfigMap);

    // Fetch remote config.
    fetchConfig();

    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
            mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
    mMessageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    mAddMessageImageView = (ImageView) findViewById(R.id.addMessageImageView);
    mAddMessageImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, REQUEST_IMAGE);
        }
    });

    mSendButton = (Button) findViewById(R.id.sendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(),
                    mUsername, mPhotoUrl, null);
            mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage);
            mMessageEditText.setText("");
            mFirebaseAnalytics.logEvent(MESSAGE_SENT_EVENT, null);
        }
    });
}

From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java

@Override
public void onStart() {
    super.onStart(); //super.onStart() is where dialog.show() is actually called on the underlying dialog, so we have to do it after this point

    final AlertDialog d = (AlertDialog) getDialog();
    if (d != null) {

        d.findViewById(R.id.router_add_privkey).setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.KITKAT)
            @Override/*w  w w  . j  a  va  2 s . c  o  m*/
            public void onClick(View view) {
                //Open up file picker

                // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
                // browser.
                final Intent intent = new Intent();

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
                } else {
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                }

                // Filter to only show results that can be "opened", such as a
                // file (as opposed to a list of contacts or timezones)
                intent.addCategory(Intent.CATEGORY_OPENABLE);

                // search for all documents available via installed storage providers
                intent.setType("*/*");

                AbstractRouterMgmtDialogFragment.this.startActivityForResult(intent, READ_REQUEST_CODE);
            }
        });

        d.getButton(Dialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Validate form
                boolean validForm = validateForm(d);

                if (validForm) {
                    // Now check actual connection to router ...
                    new CheckRouterConnectionAsyncTask(
                            ((EditText) d.findViewById(R.id.router_add_ip)).getText().toString(),
                            getSherlockActivity()
                                    .getSharedPreferences(DEFAULT_SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)
                                    .getBoolean(ALWAYS_CHECK_CONNECTION_PREF_KEY, true)).execute(d);
                }
                ///else dialog stays open. 'Cancel' button can still close it.
            }
        });
    }
}

From source file:com.nextgis.mobile.activity.MainActivity.java

public void addLocalLayer() {
    // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
    // browser.//from w w w.j  ava  2s.  c  o m
    // https://developer.android.com/guide/topics/providers/document-provider.html#client
    Intent intent;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
    } else {
        intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    }
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_file)), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        //TODO: open select local resource dialog
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, getString(R.string.warning_install_file_manager), Toast.LENGTH_SHORT).show();
    }
}

From source file:fishlinghu.sporttogether.ChatActivity.java

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

    // get the room key
    Intent myIntent = getIntent();//from w w  w .j  a va 2s.  co  m
    roomKey = myIntent.getStringExtra("roomKey");

    setContentView(R.layout.activity_chat);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // Set default username is anonymous.
    mUsername = ANONYMOUS;

    // Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();
    AccountEmail = mFirebaseUser.getEmail();
    AccountEmailKey = AccountEmail.replace(".", ",");

    if (mFirebaseUser == null) {
        // Not signed in, launch the Sign In activity
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        if (mFirebaseUser.getPhotoUrl() != null) {
            mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
        }
    }

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API).build();

    // Initialize ProgressBar and RecyclerView.
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);// why is progress bar keep rolling when there is no message?
    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);
    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);

    // New child entries
    // This code initially adds all existing messages
    // then listens for new child entries under the messages path in your Firebase Realtime Database.
    // It adds a new element to the UI for each message.
    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();

    // show the room information
    mSportTextView = (TextView) findViewById(R.id.textView16);
    mTimeTextView = (TextView) findViewById(R.id.textview_time);
    mLocationTextView = (TextView) findViewById(R.id.textview_location);

    Query query = mFirebaseDatabaseReference.child("chatrooms").child(roomKey);
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                RoomData = dataSnapshot.getValue(Chatroom.class);
                mSportTextView.setText(RoomData.getSport());
                mTimeTextView.setText(RoomData.getIntendedDate() + RoomData.getIntendedTime());
                mLocationTextView.setText(RoomData.getLocation());
                Eventlongitude = RoomData.getLongitude();
                Eventlatitude = RoomData.getLatitude();
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class,
            R.layout.item_message, MessageViewHolder.class,
            mFirebaseDatabaseReference.child("chatrooms").child(roomKey).child("messages")) {

        @Override
        protected void populateViewHolder(final MessageViewHolder viewHolder, FriendlyMessage friendlyMessage,
                int position) {

            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            if (friendlyMessage.getText() != null) {
                viewHolder.messageTextView.setText(friendlyMessage.getText());
                viewHolder.messageTextView.setVisibility(TextView.VISIBLE);
                viewHolder.messageImageView.setVisibility(ImageView.GONE);
            } else {
                String imageUrl = friendlyMessage.getImageUrl();
                if (imageUrl.startsWith("gs://")) {
                    StorageReference storageReference = FirebaseStorage.getInstance()
                            .getReferenceFromUrl(imageUrl);
                    storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
                        @Override
                        public void onComplete(@NonNull Task<Uri> task) {
                            if (task.isSuccessful()) {
                                String downloadUrl = task.getResult().toString();
                                Glide.with(viewHolder.messageImageView.getContext()).load(downloadUrl)
                                        .into(viewHolder.messageImageView);
                            } else {
                                Log.w(TAG, "Getting download url was not successful.", task.getException());
                            }
                        }
                    });
                } else {
                    Glide.with(viewHolder.messageImageView.getContext()).load(friendlyMessage.getImageUrl())
                            .into(viewHolder.messageImageView);
                }
                viewHolder.messageImageView.setVisibility(ImageView.VISIBLE);
                viewHolder.messageTextView.setVisibility(TextView.GONE);
            }

            viewHolder.messengerTextView.setText(friendlyMessage.getName());
            if (friendlyMessage.getPhotoUrl() == null) {
                viewHolder.messengerImageView.setImageDrawable(
                        ContextCompat.getDrawable(ChatActivity.this, R.drawable.ic_account_circle_black_36dp));
            } else {
                Glide.with(ChatActivity.this).load(friendlyMessage.getPhotoUrl())
                        .into(viewHolder.messengerImageView);
            }

        }

    };

    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // If the recycler view is initially being loaded or the
            // user is at the bottom of the list, scroll to the bottom
            // of the list to show the newly added message.
            if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1)
                    && lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });

    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);

    mMessageRecyclerView.setAdapter(mFirebaseAdapter);

    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
            mSharedPreferences.getInt(CodelabPreferences.FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
    mMessageEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });

    mSendButton = (Button) findViewById(R.id.sendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Send messages on click.
            FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(),
                    mUsername, mPhotoUrl, null);
            mFirebaseDatabaseReference.child("chatrooms").child(roomKey).child("messages").push()
                    .setValue(friendlyMessage);
            mMessageEditText.setText("");
        }
    });

    mLeaveButton = (Button) findViewById(R.id.leaveButton);
    mLeaveButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // remove user's room key
            mFirebaseDatabaseReference.child("users").child(AccountEmailKey).child("roomKey").setValue("");
            mFirebaseDatabaseReference.child("chatrooms").child(roomKey).child("users").child(AccountEmailKey)
                    .removeValue();
            // leave the room, go to home page
            Intent myIntent = new Intent(ChatActivity.this, MainPageActivity.class);
            startActivity(myIntent);
        }
    });

    mGoButton = (Button) findViewById(R.id.goButton);
    mGoButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(ChatActivity.this, ReviewActivity.class);
            myIntent.putExtra("roomKey", roomKey);
            startActivity(myIntent);
        }
    });

    mMapButton = (Button) findViewById(R.id.button_map);
    mMapButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent myIntent = new Intent(ChatActivity.this, EventMap.class);
            ArrayList<Double> Pointdata = new ArrayList<Double>();
            Pointdata.add(Eventlatitude);
            Pointdata.add(Eventlongitude);

            myIntent.putExtra("point", Pointdata);
            startActivity(myIntent);
        }
    });

    mAddMessageImageView = (ImageView) findViewById(R.id.addMessageImageView);
    mAddMessageImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Select image for image message on click.
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("image/*");
            startActivityForResult(intent, REQUEST_IMAGE);
        }
    });
}

From source file:com.github.colorchief.colorchief.MainActivity.java

public void openICCFile(View view) {

    Intent filePickerIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    filePickerIntent.addCategory(Intent.CATEGORY_OPENABLE);

    filePickerIntent.setType("*/*");
    //filePickerIntent.setType("application/vnd.iccprofile/*");

    int requestCode = 0;
    if (view.getId() == R.id.buttonLoadICCin) {
        requestCode = SELECT_ICC_IN;//from   w  w w  . j a  v  a2 s .c o m
    } else if (view.getId() == R.id.buttonLoadICCout) {
        requestCode = SELECT_ICC_OUT;
    }

    startActivityForResult(filePickerIntent, requestCode);
}

From source file:info.papdt.blacklight.ui.statuses.NewPostActivity.java

private void showPicturePicker() {
    new AlertDialog.Builder(this).setItems(getResources().getStringArray(R.array.picture_picker_array),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialogInterface, int id) {
                    switch (id) {
                    case 0:
                        Intent i = new Intent();
                        if (Build.VERSION.SDK_INT >= 19) {
                            i.setAction(Intent.ACTION_OPEN_DOCUMENT);
                            i.addCategory(Intent.CATEGORY_OPENABLE);
                            i.setType("image/*");
                        } else {
                            i.setAction(Intent.ACTION_PICK);
                            i.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        }//w  ww . ja  v  a 2s  .  com
                        startActivityForResult(i, REQUEST_PICK_IMG);
                        break;
                    case 1:
                        Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        Uri uri = Utility.getOutputMediaFileUri();
                        captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
                        startActivityForResult(captureIntent, REQUEST_CAPTURE_PHOTO);
                        break;
                    case 2:
                        Intent multi = new Intent();
                        multi.setAction("us.shandian.blacklight.MULTI_PICK");
                        multi.setClass(NewPostActivity.this, MultiPicturePicker.class);
                        startActivityForResult(multi, 1000);
                        break;
                    }
                }
            }).show();
}

From source file:com.kayzook.bracediary.BaseActivity.java

public void getGallery(View view) {
    if (Build.VERSION.SDK_INT < 19) {
        Intent intent = new Intent();
        intent.setType("image/jpeg");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Photo"), GALLERY_INTENT_CALLED);
    } else {/*from   ww w  . j  a v  a2 s . c o  m*/
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/jpeg");
        startActivityForResult(intent, GALLERY_KITKAT_INTENT_CALLED);
    }
}

From source file:org.mklab.mikity.android.MainActivity.java

/**
 * ??????????/*  www . j av  a2  s.co m*/
 */
public void sendFileChooseIntentForLoadingModel() {
    final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("*/*"); //$NON-NLS-1$
    startActivityForResult(intent, REQUEST_CODE_LOAD_MODEL_DATA_FILE);
}

From source file:org.mklab.mikity.android.MainActivity.java

/**
 * ??????????// ww  w.  j  a  v  a2s  .co  m
 * 
 * @param sourceId ID
 */
public void sendFileChooseIntentForLoadingSource(String sourceId) {
    final Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("*/*"); //$NON-NLS-1$
    this.sourceIdForIntent = sourceId;
    startActivityForResult(intent, REQUEST_CODE_LOAD_SOURCE_DATA_FILE);
}

From source file:com.cenkgun.chatty.MainActivity.java

private void addPhoto() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, REQUEST_IMAGE);
}