Java Code Examples for android.content.Intent.ACTION_OPEN_DOCUMENT

The following are Jave code examples for showing how to use ACTION_OPEN_DOCUMENT of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: PubkeyListActivity.java   View Source Code Vote up 7 votes
/**
 * Fires an intent to spin up the "file chooser" UI and select a private key.
 */
@TargetApi(19)
public boolean importExistingKeyKitKat() {
	// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
	// browser.
	Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

	// 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);

	// PKCS#8 MIME types aren't widely supported, so we'll try */* fro now.
	intent.setType("*/*");

	try {
		startActivityForResult(intent, REQUEST_CODE_PICK_FILE);
		return true;
	} catch (ActivityNotFoundException e) {
		return false;
	}
}
 
Example 2
Project: file.io-app   File: MainActivity.java   View Source Code Vote up 7 votes
@NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void chooseFile(Intent dataIntent) {
    /* Check for network connectivity */
    if (isConnectedToActiveNetwork(this)) {
        // if upload was chosen from the app
        if (dataIntent == null) {
            // Use system file browser
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.setType("*/*");
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            startActivityForResult(Intent.createChooser(intent, "Choose the file to Upload.."), INTENT_FILE_REQUEST);

        } else {
            // If Intent received from implicit intent
            onActivityResult(INTENT_FILE_REQUEST, RESULT_OK, dataIntent);
        }
    } else {
        /* Show no network dialog */
        NoNetworkDialogFragment noNetworkDialogFragment = new NoNetworkDialogFragment();
        noNetworkDialogFragment.show(getSupportFragmentManager(), getString(R.string.no_net_dialog_fragment_tag));
    }
}
 
Example 3
Project: aos-Video   File: BrowserCategoryVideo.java   View Source Code Vote up 7 votes
/**
 * Override the base class because we need a special treatment for the Movies category,
 * that is using the ActionBar list navigation to switch between various fragments
 */
@Override
public void setFragment(String path){
    if(mSelectedItemId == ITEM_ID_PROVIDER){
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("video/*");
        startActivityForResult(intent, FILE_CHOOSER_ACTIVITY_REQUEST_CODE);
        //restore browser
        mSelectedItemId = mOldSelectedItemId;
        return ;
    }
    else if (mSelectedItemId == ITEM_ID_MOVIES) {
        setupMovieActionBarNavigation(true);
        // refresh the category list

    }
    else {
        //default case is no navigation in action bar
        ((MainActivity)getActivity()).hideSeachView();
        setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
        // and it is handled by the parent class
        super.setFragment(path);
    }

}
 
Example 4
Project: CodeCompilerApp   File: MainActivity.java   View Source Code Vote up 7 votes
public void OpenFile(View view) {

        if (Device.hasKitKatApi()  && PreferenceHelper.getUseStorageAccessFramework(this)) {
            // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
            // browser.
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

            // 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);

            // Filter to show only images, using the image MIME data type.
            // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
            // To search for all documents available via installed storage providers,
            // it would be "*/*".
            intent.setType("*/*");

            startActivityForResult(intent, READ_REQUEST_CODE);
        } else {
            Intent subActivity = new Intent(MainActivity.this, SelectFileActivity.class);
            subActivity.putExtra("action", SelectFileActivity.Actions.SelectFile);
            AnimationUtils.startActivityWithScale(this, subActivity, true, SELECT_FILE_CODE, view);
        }
    }
 
Example 5
Project: Ucount   File: MainActivity.java   View Source Code Vote up 6 votes
public void selectPictureFromGallery() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    // 设置选择类型为图片类型
    intent.setType("image/*");
    // 打开图片选择
    startActivityForResult(intent, SELECT_GALLERY_PIC);

}
 
Example 6
Project: arduator   File: MainActivity.java   View Source Code Vote up 6 votes
private void performFileSearch() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");

    startActivityForResult(intent, READ_REQUEST_CODE);
}
 
Example 7
Project: Aardvark   File: GUI_MainActivity.java   View Source Code Vote up 6 votes
private void openFileBrowser()
{
    String returnVal = new String();

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); //START INTENT TO CHOOSE FILE USING DEVICE' DEFAULT FILE BROWSER
    intent.addCategory(Intent.CATEGORY_OPENABLE);//SHOW ONLY FILES THAT CAN BE OPENED
    intent.setType("text/plain"); //only plain txt file can be accessed

    startActivityForResult(intent, READ_REQUEST_CODE);
}
 
Example 8
Project: foco   File: ImportExportUtils.java   View Source Code Vote up 6 votes
/**
 * This method starts open document system activity.
 * @param activity
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void importBookmarks(Activity activity) {
    // choose a file via the system's file browser
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    // show only results that can be "opened", such as a file
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    // filter to show only plain text
    intent.setType(MIME_TYPE);

    activity.startActivityForResult(intent, READ_REQUEST_CODE);
}
 
Example 9
Project: Android-BitherCompress-master   File: MainActivity.java   View Source Code Vote up 6 votes
public void pickFromGallery(View v) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        startActivityForResult(new Intent(Intent.ACTION_GET_CONTENT).setType("image/*"),
                REQUEST_PICK_IMAGE);
    } else {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_KITKAT_PICK_IMAGE);
    }
}
 
Example 10
Project: Daedalus   File: RuleConfigFragment.java   View Source Code Vote up 6 votes
@TargetApi(Build.VERSION_CODES.KITKAT)
private void performFileSearch() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);

    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*");
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);

    startActivityForResult(intent, READ_REQUEST_CODE);
}
 
Example 11
Project: VideoApplication   File: VideoPlayActivity.java   View Source Code Vote up 5 votes
protected void moveToGallery() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("video/mp4");
    startActivityForResult(intent, 1000);
}
 
Example 12
Project: social-journal   File: MainActivity.java   View Source Code Vote up 5 votes
private void addPicture() {
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    startActivityForResult(intent, SELECT_IMAGE);
}
 
Example 13
Project: music_player   File: RecommendFragment.java   View Source Code Vote up 4 votes
public static void openSAF(Activity context) {

        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        context.startActivityForResult(intent, 42);

    }