Example usage for android.content Intent FLAG_GRANT_READ_URI_PERMISSION

List of usage examples for android.content Intent FLAG_GRANT_READ_URI_PERMISSION

Introduction

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

Prototype

int FLAG_GRANT_READ_URI_PERMISSION

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

Click Source Link

Document

If set, the recipient of this Intent will be granted permission to perform read operations on the URI in the Intent's data and any URIs specified in its ClipData.

Usage

From source file:nl.sogeti.android.gpstracker.actions.Statistics.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean handled = false;
    Intent intent;/*  w  w  w . ja v a 2  s . c om*/
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        handled = true;
        break;
    case MENU_GRAPHTYPE:
        showDialog(DIALOG_GRAPHTYPE);
        handled = true;
        break;
    case MENU_TRACKLIST:
        intent = new Intent(this, TrackList.class);
        intent.putExtra(Tracks._ID, mTrackUri.getLastPathSegment());
        startActivityForResult(intent, MENU_TRACKLIST);
        break;
    case MENU_SHARE:
        intent = new Intent(Intent.ACTION_RUN);
        intent.setDataAndType(mTrackUri, Tracks.CONTENT_ITEM_TYPE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Bitmap bm = mViewFlipper.getDrawingCache();
        Uri screenStreamUri = ShareTrack.storeScreenBitmap(bm);
        intent.putExtra(Intent.EXTRA_STREAM, screenStreamUri);
        startActivityForResult(Intent.createChooser(intent, getString(R.string.share_track)), MENU_SHARE);
        handled = true;
        break;
    default:
        handled = super.onOptionsItemSelected(item);
    }
    return handled;
}

From source file:net.bluehack.ui.WallpapersActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("ChatBackground", R.string.ChatBackground));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   w w w.  ja va2  s .  co  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                boolean done;
                TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
                if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
                    int width = AndroidUtilities.displaySize.x;
                    int height = AndroidUtilities.displaySize.y;
                    if (width > height) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes,
                            Math.min(width, height));
                    String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                    File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                            fileName);
                    File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                    try {
                        done = AndroidUtilities.copyFile(f, toFile);
                    } catch (Exception e) {
                        done = false;
                        FileLog.e("tmessages", e);
                    }
                } else {
                    if (selectedBackground == -1) {
                        File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg");
                        File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                        done = fromFile.renameTo(toFile);
                    } else {
                        done = true;
                    }
                }

                if (done) {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt("selectedBackground", selectedBackground);
                    editor.putInt("selectedColor", selectedColor);
                    editor.commit();
                    ApplicationLoader.reloadWallpaper();
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    FrameLayout frameLayout = new FrameLayout(context);
    fragmentView = frameLayout;

    backgroundImage = new ImageView(context);
    backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    frameLayout.addView(backgroundImage,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    backgroundImage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));

    progressViewBackground = new View(context);
    progressViewBackground.setBackgroundResource(R.drawable.system_loader);
    progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    ProgressBar progressBar = new ProgressBar(context);
    try {
        progressBar.setIndeterminateDrawable(context.getResources().getDrawable(R.drawable.loading_animation));
    } catch (Exception e) {
        //don't promt
    }
    progressBar.setIndeterminate(true);
    AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    RecyclerListView listView = new RecyclerListView(context);
    listView.setClipToPadding(false);
    listView.setTag(8);
    listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    listView.setLayoutManager(layoutManager);
    listView.setDisallowInterceptTouchEvents(true);
    listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 0) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("Cancel", R.string.Cancel) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                            if (i == 0) {
                                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                File image = AndroidUtilities.generatePicturePath();
                                if (image != null) {
                                    if (Build.VERSION.SDK_INT >= 24) {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                FileProvider.getUriForFile(getParentActivity(),
                                                        BuildConfig.APPLICATION_ID + ".provider", image));
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                    } else {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                Uri.fromFile(image));
                                    }
                                    currentPicturePath = image.getAbsolutePath();
                                }
                                startActivityForResult(takePictureIntent, 10);
                            } else if (i == 1) {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 11);
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                if (position - 1 < 0 || position - 1 >= wallPapers.size()) {
                    return;
                }
                TLRPC.WallPaper wallPaper = wallPapers.get(position - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
            }
        }
    });

    processSelectedBackground();

    return fragmentView;
}

From source file:com.mb.android.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == PURCHASE_REQUEST) {
        if (resultCode == RESULT_OK) {

            if (currentProduct.getEmbyFeatureCode() != null) {

                AppstoreRegRequest request = new AppstoreRegRequest();
                request.setStore(intent.getStringExtra("store"));
                request.setApplication(AppPackageName);
                request.setProduct(currentProduct.getSku());
                request.setFeature(currentProduct.getEmbyFeatureCode());
                request.setType(currentProduct.getProductType().toString());
                if (intent.getStringExtra("storeId") != null)
                    request.setStoreId(intent.getStringExtra("storeId"));
                request.setStoreToken(intent.getStringExtra("storeToken"));
                request.setEmail(purchaseEmail);
                request.setAmt(currentProduct.getPrice());

                RespondToWebView(String.format("window.IapManager.onPurchaseComplete("
                        + jsonSerializer.SerializeToString(request) + ");"));
            } else {
                // no emby feature - just report success
                RespondToWebView(String.format("window.IapManager.onPurchaseComplete(true);"));
            }//from   ww w .  j a va  2  s  . c om
        } else {
            RespondToWebView(String.format("window.IapManager.onPurchaseComplete(false);"));
        }
    }

    else if (requestCode == REQUEST_DIRECTORY_SAF && resultCode == Activity.RESULT_OK) {

        Uri uri = intent.getData();
        final int takeFlags = intent.getFlags()
                & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        // Check for the freshest data.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getContentResolver().takePersistableUriPermission(uri, takeFlags);
        }
        RespondToWebviewWithSelectedPath(uri);
    } else if (requestCode == REQUEST_DIRECTORY && resultCode == RESULT_OK) {

        if (intent.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
            // For JellyBean and above
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                ClipData clip = intent.getClipData();

                if (clip != null) {
                    for (int i = 0; i < clip.getItemCount(); i++) {
                        Uri uri = clip.getItemAt(i).getUri();
                        RespondToWebviewWithSelectedPath(uri);
                    }
                }
                // For Ice Cream Sandwich
            } else {
                ArrayList<String> paths = intent.getStringArrayListExtra(FilePickerActivity.EXTRA_PATHS);

                if (paths != null) {
                    for (String path : paths) {
                        Uri uri = Uri.parse(path);
                        RespondToWebviewWithSelectedPath(uri);
                    }
                }
            }

        } else {
            Uri uri = intent.getData();
            // Do something with the URI
            if (uri != null) {
                RespondToWebviewWithSelectedPath(uri);
            }
        }
    }

    else if (requestCode == VIDEO_PLAYBACK) {

        /*boolean completed = resultCode == RESULT_OK;
        boolean error = resultCode == RESULT_OK ? false : (intent == null ? true : intent.getBooleanExtra("error", false));
                
        long positionMs = intent == null || completed ? 0 : intent.getLongExtra("position", 0);
        String currentSrc = intent == null ? null : intent.getStringExtra(VideoPlayerActivity.PLAY_EXTRA_ITEM_LOCATION);
                
        if (currentSrc == null) {
        currentSrc = "";
        }
                
        RespondToWebView(String.format("VideoRenderer.Current.onActivityClosed(%s, %s, %s, '%s');", !completed, error, positionMs, currentSrc));*/
    }
}

From source file:ru.dublgis.androidhelpers.DesktopUtils.java

public static boolean sendEmail(final Context ctx, final String to, final String subject, final String body,
        final String[] attachment, final String authorities) {
    try {/*from   w  w  w.j  a  va2s. co  m*/
        final String[] recipients = new String[] { to };

        final Intent intent = new Intent(
                attachment.length > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SENDTO);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL, recipients);
        intent.putExtra(Intent.EXTRA_SUBJECT, subject);
        intent.putExtra(Intent.EXTRA_TEXT, body);

        boolean grant_permissions_workaround = false;
        final ArrayList<Uri> uri = new ArrayList<>();
        if (attachment.length > 0) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                for (final String fileName : attachment) {
                    uri.add(Uri.fromFile(new File(fileName)));
                }
            } else {
                // Android 6+: going the longer route.
                // For more information, please see:
                // http://stackoverflow.com/questions/32981194/android-6-cannot-share-files-anymore
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                grant_permissions_workaround = true;
                for (final String fileName : attachment) {
                    uri.add(FileProvider.getUriForFile(ctx, authorities, new File(fileName)));
                }
            }
            // Should not put array with only one element into intent because of a bug in GMail.
            if (uri.size() == 1) {
                intent.putExtra(Intent.EXTRA_STREAM, uri.get(0));
            } else {
                intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uri);
            }
        }

        final IntentResolverInfo mailtoIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
        mailtoIntentResolvers
                .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", to, null)));

        final Intent chooserIntent;

        if (mailtoIntentResolvers.isEmpty()) {
            chooserIntent = Intent.createChooser(intent, null);
        } else {
            final IntentResolverInfo messageIntentResolvers = new IntentResolverInfo(ctx.getPackageManager());
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mms", "", null)));
            messageIntentResolvers
                    .appendResolvers(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("tel", "", null)));

            mailtoIntentResolvers.removeSamePackages(messageIntentResolvers.getResolveInfos());

            final List<Intent> intentList = new ArrayList<>();

            for (final ActivityInfo activityInfo : mailtoIntentResolvers.getResolveInfos()) {
                final String packageName = activityInfo.getPackageName();
                final String name = activityInfo.getName();

                // Some mail clients will not read the URI unless this is done.
                // See here: https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial
                if (grant_permissions_workaround) {
                    for (int i = 0; i < uri.size(); ++i) {
                        try {
                            ctx.grantUriPermission(packageName, uri.get(i),
                                    Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        } catch (final Throwable e) {
                            Log.e(TAG, "grantUriPermission error: ", e);
                        }
                    }
                }

                final Intent cloneIntent = (Intent) intent.clone();
                cloneIntent.setComponent(new ComponentName(packageName, name));
                intentList.add(cloneIntent);
            }

            final Intent targetIntent = intentList.get(0);
            intentList.remove(0);

            chooserIntent = Intent.createChooser(targetIntent, null);
            if (!intentList.isEmpty()) {
                final Intent[] extraIntents = intentList.toArray(new Intent[intentList.size()]);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, extraIntents);
                } else {
                    chooserIntent.putExtra(Intent.EXTRA_ALTERNATE_INTENTS, extraIntents);
                }
            }
        }

        chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        ctx.startActivity(chooserIntent);

        return true;
    } catch (final Throwable exception) {
        Log.e(TAG, "sendEmail exception: ", exception);
        return false;
    }
}

From source file:nl.sogeti.android.gpstracker.viewer.TrackList.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    boolean handled = false;
    AdapterView.AdapterContextMenuInfo info;
    try {/*from   w  w w. j a v  a  2  s. c  om*/
        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
        Log.e(this, "Bad menuInfo", e);
        return handled;
    }

    Object listItem = getListAdapter().getItem(info.position);
    if (listItem instanceof Cursor) {
        Cursor cursor = (Cursor) listItem;
        mDialogTrackUri = ContentUris.withAppendedId(Tracks.CONTENT_URI, cursor.getLong(0));
        mDialogCurrentName = cursor.getString(1);
        mDialogCurrentName = mDialogCurrentName != null ? mDialogCurrentName : "";
        switch (item.getItemId()) {
        case MENU_DELETE: {
            showDialog(DIALOG_DELETE);
            handled = true;
            break;
        }
        case MENU_SHARE: {
            Intent actionIntent = new Intent(Intent.ACTION_RUN);
            actionIntent.setDataAndType(mDialogTrackUri, Tracks.CONTENT_ITEM_TYPE);
            actionIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            startActivity(Intent.createChooser(actionIntent, getString(R.string.share_track)));
            handled = true;
            break;
        }
        case MENU_RENAME: {
            showDialog(DIALOG_RENAME);
            handled = true;
            break;
        }
        case MENU_STATS: {
            Intent actionIntent = new Intent(this, Statistics.class);
            actionIntent.setData(mDialogTrackUri);
            startActivity(actionIntent);
            handled = true;
            break;
        }
        default:
            handled = super.onContextItemSelected(item);
            break;
        }
    }
    return handled;
}

From source file:kr.wdream.ui.WallpapersActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");

    actionBar.setBackButtonImage(kr.wdream.storyshop.R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(/*w  w  w  .j av a  2 s .  c  o  m*/
            LocaleController.getString("ChatBackground", kr.wdream.storyshop.R.string.ChatBackground));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                boolean done;
                TLRPC.WallPaper wallPaper = wallpappersByIds.get(selectedBackground);
                if (wallPaper != null && wallPaper.id != 1000001 && wallPaper instanceof TLRPC.TL_wallPaper) {
                    int width = AndroidUtilities.displaySize.x;
                    int height = AndroidUtilities.displaySize.y;
                    if (width > height) {
                        int temp = width;
                        width = height;
                        height = temp;
                    }
                    TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(wallPaper.sizes,
                            Math.min(width, height));
                    String fileName = size.location.volume_id + "_" + size.location.local_id + ".jpg";
                    File f = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE),
                            fileName);
                    File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                    try {
                        done = AndroidUtilities.copyFile(f, toFile);
                    } catch (Exception e) {
                        done = false;
                        FileLog.e("tmessages", e);
                    }
                } else {
                    if (selectedBackground == -1) {
                        File fromFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper-temp.jpg");
                        File toFile = new File(ApplicationLoader.getFilesDirFixed(), "wallpaper.jpg");
                        done = fromFile.renameTo(toFile);
                    } else {
                        done = true;
                    }
                }

                if (done) {
                    SharedPreferences preferences = ApplicationLoader.applicationContext
                            .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
                    SharedPreferences.Editor editor = preferences.edit();
                    editor.putInt("selectedBackground", selectedBackground);
                    editor.putInt("selectedColor", selectedColor);
                    editor.commit();
                    ApplicationLoader.reloadWallpaper();
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, kr.wdream.storyshop.R.drawable.ic_done,
            AndroidUtilities.dp(56));

    FrameLayout frameLayout = new FrameLayout(context);
    fragmentView = frameLayout;

    backgroundImage = new ImageView(context);
    backgroundImage.setScaleType(ImageView.ScaleType.CENTER_CROP);
    frameLayout.addView(backgroundImage,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    backgroundImage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.INVISIBLE);
    frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 52));

    progressViewBackground = new View(context);
    progressViewBackground.setBackgroundResource(kr.wdream.storyshop.R.drawable.system_loader);
    progressView.addView(progressViewBackground, LayoutHelper.createFrame(36, 36, Gravity.CENTER));

    ProgressBar progressBar = new ProgressBar(context);
    try {
        progressBar.setIndeterminateDrawable(
                context.getResources().getDrawable(kr.wdream.storyshop.R.drawable.loading_animation));
    } catch (Exception e) {
        //don't promt
    }
    progressBar.setIndeterminate(true);
    AndroidUtilities.setProgressBarAnimationDuration(progressBar, 1500);
    progressView.addView(progressBar, LayoutHelper.createFrame(32, 32, Gravity.CENTER));

    RecyclerListView listView = new RecyclerListView(context);
    listView.setClipToPadding(false);
    listView.setTag(8);
    listView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
    LinearLayoutManager layoutManager = new LinearLayoutManager(context);
    layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    listView.setLayoutManager(layoutManager);
    listView.setDisallowInterceptTouchEvents(true);
    listView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 102, Gravity.LEFT | Gravity.BOTTOM));
    listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position == 0) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                CharSequence[] items = new CharSequence[] {
                        LocaleController.getString("FromCamera", kr.wdream.storyshop.R.string.FromCamera),
                        LocaleController.getString("FromGalley", kr.wdream.storyshop.R.string.FromGalley),
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel) };

                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        try {
                            if (i == 0) {
                                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                                File image = AndroidUtilities.generatePicturePath();
                                if (image != null) {
                                    if (Build.VERSION.SDK_INT >= 24) {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                FileProvider.getUriForFile(getParentActivity(),
                                                        BuildConfig.APPLICATION_ID + ".provider", image));
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                        takePictureIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                    } else {
                                        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                                Uri.fromFile(image));
                                    }
                                    currentPicturePath = image.getAbsolutePath();
                                }
                                startActivityForResult(takePictureIntent, 10);
                            } else if (i == 1) {
                                Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                                photoPickerIntent.setType("image/*");
                                startActivityForResult(photoPickerIntent, 11);
                            }
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                    }
                });
                showDialog(builder.create());
            } else {
                if (position - 1 < 0 || position - 1 >= wallPapers.size()) {
                    return;
                }
                TLRPC.WallPaper wallPaper = wallPapers.get(position - 1);
                selectedBackground = wallPaper.id;
                listAdapter.notifyDataSetChanged();
                processSelectedBackground();
            }
        }
    });

    processSelectedBackground();

    return fragmentView;
}

From source file:com.mediatek.galleryfeature.stereo.fancycolor.FancyColorActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int action = item.getItemId();
    switch (action) {
    case R.id.action_refine:
        mEffectManager.setMaskBufferToSegment();
        Intent intent = new Intent(STEREO_PICK_ACTION);
        intent.setClass(FancyColorActivity.this, StereoRefineActivity.class);
        intent.setDataAndType(mSourceUri, mIntent.getType()).setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivityForResult(intent, REQUEST_STEREO_PICK);
        break;/*from ww  w  .j  a  v  a  2  s. com*/
    default:
        break;
    }
    return true;
}

From source file:com.android.talkback.labeling.LabelManagerSummaryActivity.java

private void addExportCustomLabelClickListener() {
    final Button exportLabel = (Button) findViewById(R.id.export_labels);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        exportLabel.setVisibility(View.GONE);
        return;//from w  w  w.  jav  a2  s  . c om
    }

    exportLabel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            CustomLabelMigrationManager exporter = new CustomLabelMigrationManager(getApplicationContext());
            exporter.exportLabels(new CustomLabelMigrationManager.SimpleLabelMigrationCallback() {
                @Override
                public void onLabelsExported(File file) {
                    if (file == null) {
                        notifyLabelExportFailure();
                        return;
                    }

                    Uri uri = FileProvider.getUriForFile(getApplicationContext(), FILE_AUTHORITY, file);
                    Intent shareIntent = new Intent();
                    shareIntent.setAction(Intent.ACTION_SEND);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    shareIntent.setType("application/json");

                    String activityTitle = getResources().getString(R.string.label_choose_app_to_export);
                    startActivity(Intent.createChooser(shareIntent, activityTitle));
                }

                @Override
                public void onFail() {
                    notifyLabelExportFailure();
                }
            });
            return;
        }
    });
}

From source file:org.cyanogenmod.focal.ui.ReviewDrawer.java

private void editInGallery(final int imageId) {
    if (imageId > 0) {
        Intent editIntent = new Intent(Intent.ACTION_EDIT);

        // Get URI
        Uri uri = null;//from   w w w . j av  a2  s  . c o m
        if (CameraActivity.getCameraMode() == CameraActivity.CAMERA_MODE_VIDEO) {
            uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId))
                    .build();
        } else {
            uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId))
                    .build();
        }

        // Start gallery edit activity
        editIntent.setDataAndType(uri, "image/*");
        editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Context ctx = getContext();
        if (ctx != null) {
            ctx.startActivity(Intent.createChooser(editIntent, null));
        }
    }
}

From source file:com.ktouch.kdc.launcher4.camera.ui.ReviewDrawer.java

private void editInGallery(final int imageId) {
    if (imageId > 0) {
        Intent editIntent = new Intent(Intent.ACTION_EDIT);

        // Get URI
        Uri uri = null;//from  ww w .j  a  v  a2  s  . co m
        if (Gallery.getCameraMode() == Gallery.CAMERA_MODE_VIDEO) {
            uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId))
                    .build();
        } else {
            uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI.buildUpon().appendPath(Integer.toString(imageId))
                    .build();
        }

        // Start gallery edit activity
        editIntent.setDataAndType(uri, "image/*");
        editIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Context ctx = getContext();
        if (ctx != null) {
            ctx.startActivity(Intent.createChooser(editIntent, null));
        }
    }
}