Example usage for android.content Intent resolveActivity

List of usage examples for android.content Intent resolveActivity

Introduction

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

Prototype

public ComponentName resolveActivity(@NonNull PackageManager pm) 

Source Link

Document

Return the Activity component that should be used to handle this intent.

Usage

From source file:org.intakers.intake.helper.SelectImageActivity.java

public void takePhoto(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // Save the photo taken to a temporary file.
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        try {/*from   www .  ja  va2  s  .c  om*/
            File file = File.createTempFile("IMG_", ".jpg", storageDir);
            mUriPhotoTaken = Uri.fromFile(file);
            //mUriPhotoTaken = FileProvider.getUriForFile(SelectImageActivity.this, BuildConfig.APPLICATION_ID + ".provider", file);
            Log.d("FileName in TakePhoto", file.getAbsolutePath());
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken);
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        } catch (IOException e) {
            setInfo(e.getMessage());
        }
    }
}

From source file:com.beesham.popularmovies.ReviewAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final DetailsFragment.Reviews reviews = getItem(position);

    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_review, parent, false);
    }//w w  w .  j  av  a  2s.c  o  m
    ButterKnife.bind(this, convertView);

    reviewAuthorTextView.setText(reviews.getAuthor());

    readReviewButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(reviews.getUrl()));
            if (intent.resolveActivity(getContext().getPackageManager()) != null) {
                getContext().startActivity(intent);
            }
        }
    });

    return convertView;
}

From source file:net.mjc.zip.domain.IdCheck.java

public Intent createIntent(Context context) {
    try {//from   www .j a va  2s  .c  o m
        Intent intent = new Intent(context, Class.forName(getActivityClass()));
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            return intent;
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.xbm.android.matisse.internal.utils.MediaStoreCompat.java

public void dispatchCaptureIntent(Context context, int requestCode) {
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (captureIntent.resolveActivity(context.getPackageManager()) != null) {
        File photoFile = null;//from   w w  w  . j  a v  a 2 s  . c  o m
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (photoFile != null) {
            mCurrentPhotoPath = photoFile.getAbsolutePath();
            mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), mCaptureStrategy.authority,
                    photoFile);
            captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
            captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(captureIntent,
                        PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    context.grantUriPermission(packageName, mCurrentPhotoUri,
                            Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            }
            if (mFragment != null) {
                mFragment.get().startActivityForResult(captureIntent, requestCode);
            } else {
                mContext.get().startActivityForResult(captureIntent, requestCode);
            }
        }
    }
}

From source file:org.intakers.intake.helper.SelectImageActivity.java

public void selectImageInAlbum(View view) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_SELECT_IMAGE_IN_ALBUM);
    }// w w  w.j  av a2  s.  co  m
}

From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java

@SuppressWarnings("deprecation")
@Override/*from  ww w.  ja  v  a 2s  .  c  o  m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Perform different actions depending on how this activity was launched
    switch (getIntent().getAction()) {
    case Intent.ACTION_MAIN:
        Intent selector = getIntent().getSelector();
        Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();

        if (categories.contains(Intent.CATEGORY_APP_MAPS)) {
            SharedPreferences pref = U.getSharedPreferences(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                    && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(this, false, false);
            }

            Intent startStopIntent;

            if (pref.getBoolean("taskbar_active", false))
                startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
            else
                startStopIntent = new Intent("com.farmerbb.taskbar.START");

            startStopIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(startStopIntent);
        } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR))
            U.lockDevice(this);

        break;
    case Intent.ACTION_ASSIST:
        if (U.isServiceRunning(this, StartMenuService.class)) {
            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU"));
        } else {
            Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST");
            if (intent.resolveActivity(getPackageManager()) == null)
                intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);

            if (intent.resolveActivity(getPackageManager()) != null) {
                SharedPreferences pref = U.getSharedPreferences(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                        && isInMultiWindowMode()) {
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    U.launchAppMaximized(getApplicationContext(), intent);
                } else {
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            }
        }
        break;
    }

    finish();
}

From source file:ui.SelectImageActivity.java

public void takePhoto(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // Save the photo taken to a temporary file.
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        try {/*from ww w  .  j  a va 2 s . c o m*/
            File file = File.createTempFile("IMG_", ".jpg", storageDir);
            mUriPhotoTaken = Uri.fromFile(file);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken);
            startActivityForResult(intent, REQUEST_TAKE_PHOTO);
        } catch (IOException e) {
            setInfo(e.getMessage());
        }
    }
}

From source file:udatraining.dyomin.com.udaproj1.MainActivity.java

private void openPreferredLocationInMap() {
    String location = Utility.getPreferredLocation(this);

    // Using the URI scheme for showing a location found on a map.  This super-handy
    // intent can is detailed in the "Common Intents" page of Android's developer site:
    // http://developer.android.com/guide/components/intents-common.html#Maps
    Uri geoLocation = Uri.parse("geo:0,0?").buildUpon().appendQueryParameter("q", location).build();

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geoLocation);/*www .  j a v  a 2 s . co m*/

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    } else {
        Log.d(LOG_TAG, "Couldn't call " + location + ", no receiving apps installed!");
    }
}

From source file:com.microsoft.projectoxford.visionsample.helper.SelectImageActivity.java

public void takePhoto(View view) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        // Save the photo taken to a temporary file.
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        try {//from   w ww .  j  a  va2 s .  co  m
            mFilePhotoTaken = File.createTempFile("IMG_", /* prefix */
                    ".jpg", /* suffix */
                    storageDir /* directory */
            );

            // Create the File where the photo should go
            // Continue only if the File was successfully created
            if (mFilePhotoTaken != null) {
                mUriPhotoTaken = FileProvider.getUriForFile(this,
                        "com.microsoft.projectoxford.visionsample.fileprovider", mFilePhotoTaken);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken);

                // Finally start camera activity
                startActivityForResult(intent, REQUEST_TAKE_PHOTO);
            }
        } catch (IOException e) {
            setInfo(e.getMessage());
        }
    }
}

From source file:io.syng.fragment.ConsoleFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.fab_send:
        Intent intent1 = new Intent(Intent.ACTION_VIEW);
        intent1.setData(Uri.parse(ACTION_SEND));
        if (intent1.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivity(intent1);/*from w ww  .  j  a  va2 s .c om*/
        }
        break;
    case R.id.fab_receive:
        Intent intent2 = new Intent(Intent.ACTION_VIEW);
        intent2.setData(Uri.parse(ACTION_RECEIVE));
        if (intent2.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivity(intent2);
        }
        break;
    }
}