Java Code Examples for android.support.v7.app.AppCompatActivity#RESULT_OK

The following examples show how to use android.support.v7.app.AppCompatActivity#RESULT_OK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main2Activity.java    From styT with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void onActivityResultAboveL(int requestCode, int resultCode, Intent intent) {
    if (requestCode != FILE_CHOOSER_RESULT_CODE || uploadMessageAboveL == null) return;
    Uri[] results = null;
    if (resultCode == AppCompatActivity.RESULT_OK) {
        if (intent != null) {
            String dataString = intent.getDataString();
            ClipData clipData = intent.getClipData();
            if (clipData != null) {
                results = new Uri[clipData.getItemCount()];
                for (int i = 0; i < clipData.getItemCount(); i++) {
                    ClipData.Item item = clipData.getItemAt(i);
                    results[i] = item.getUri();
                }
            }
            if (dataString != null)
                results = new Uri[]{Uri.parse(dataString)};
        }
    }
    uploadMessageAboveL.onReceiveValue(results);
    uploadMessageAboveL = null;
}
 
Example 2
Source File: SettingsActivity.java    From blade-player with GNU General Public License v3.0 5 votes vote down vote up
@Override
public final void onActivityResult(final int requestCode, final int resultCode, final Intent resultData)
{
    if (resultCode == AppCompatActivity.RESULT_OK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        //if (requestCode == REQUEST_CODE_STORAGE_ACCESS)
        //{
            // Get Uri from Storage Access Framework.
            Uri treeUri = resultData.getData();

            if(!treeUri.toString().endsWith("%3A"))
            {
                //show the user that we are not happy
                Toast.makeText(this, R.string.please_sd_root, Toast.LENGTH_LONG).show();
                return;
            }

            // Persist URI in shared preference so that you can use it later.
            SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_GENERAL_FILE_NAME, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("sdcard_uri", treeUri.toString());
            editor.apply();

            LibraryService.TREE_URI = treeUri;

            // Persist access permissions, so you dont have to ask again
            final int takeFlags = resultData.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

            Toast.makeText(this, getString(R.string.perm_granted) + " : " + treeUri, Toast.LENGTH_LONG).show();
        //}
    }
}
 
Example 3
Source File: ScreenCapturerActivity.java    From video-quickstart-android with MIT License 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_MEDIA_PROJECTION) {
        if (resultCode != AppCompatActivity.RESULT_OK) {
            Toast.makeText(this, R.string.screen_capture_permission_not_granted,
                    Toast.LENGTH_LONG).show();
            return;
        }
        screenCapturer = new ScreenCapturer(this, resultCode, data, screenCapturerListener);
        startScreenCapture();
    }
}