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.chaos.fx.cnbeta.preferences.PreferencesFragment.java

private void composeEmail(String address, String subject) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, new String[] { address });
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_TEXT, "\n\n\n\nApp Version" + BuildConfig.VERSION_NAME
            + "\nAndroid Version: " + Build.VERSION.RELEASE + "\nDevice Model: " + Build.MODEL);
    if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivity(intent);// w w w  .ja  v  a2 s  . c  o  m
    }
}

From source file:org.openmrs.mobile.activities.addeditpatient.AddEditPatientFragment.java

@NeedsPermission({ Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE })
public void capturePhoto() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getContext().getPackageManager()) != null) {
        File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        output = new File(dir, getUniqueImageFileName());
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(output));
        startActivityForResult(takePictureIntent, IMAGE_REQUEST);
    }//from ww w .j a va2s .  co m
}

From source file:com.app_software.chromisstock.ProductDetailFragment.java

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }//from   w  w w . java  2 s .co  m
}

From source file:com.becapps.easydownloader.ShareActivity.java

public static void NotificationHelper() {
    pt1 = mContext.getString(R.string.notification_downloading_pt1);
    pt2 = mContext.getString(R.string.notification_downloading_pt2);
    noDownloads = mContext.getString(R.string.notification_no_downloads);

    mBuilder = new NotificationCompat.Builder(mContext);

    mBuilder.setSmallIcon(R.drawable.icon_nb).setContentTitle(mContext.getString(R.string.title_activity_share))
            .setContentText(mContext.getString(R.string.notification_downloading_pt1) + " " + sequence.size()
                    + " " + mContext.getString(R.string.notification_downloading_pt2));

    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    Intent notificationIntent = new Intent(android.app.DownloadManager.ACTION_VIEW_DOWNLOADS);
    if (notificationIntent.resolveActivity(mContext.getPackageManager()) != null) {
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    } else {/*from  w w w  .  j a v a2 s.  c o  m*/
        Log.e(DEBUG_TAG, "notificationIntent not resolved");
    }
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
    mBuilder.setContentIntent(contentIntent);
    mId = 1;
    mNotificationManager.notify(mId, mBuilder.build());
}

From source file:selfie.time.HelloFacebookSampleActivity.java

protected void initCapturePhoto(int request_type) {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, request_type);
    }/*  w  w w.j ava 2s. c o m*/
}

From source file:com.pizidea.imagepicker.util.AndroidImagePicker.java

/**
 * take picture/*from w w  w  .j av  a  2  s.  co m*/
 */
public void takePicture(Fragment fragment, int requestCode) throws IOException {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //Intent takePictureIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    takePictureIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(fragment.getContext().getPackageManager()) != null) {
        // Create the File where the photo should go
        //File photoFile = createImageFile();
        File photoFile = createImageSaveFile(fragment.getContext());
        // Continue only if the File was successfully created
        if (photoFile != null) {
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            Log.i(TAG, "=====file ready to take photo:" + photoFile.getAbsolutePath());
        }
    }
    fragment.startActivityForResult(takePictureIntent, requestCode);
}

From source file:fr.kwiatkowski.apktrack.ui.AppViewHolder.java

/**
 * Sets the right status icon when the app is currently downloading or has downloaded an APK.
 * @param info The object containing the information about the download.
 * @param ctx The context of the application.
 * @return Whether an icon was set./*from   w w w  .  j  a  va 2  s .  c  o m*/
 */
private boolean _set_action_icon_download(final DownloadInfo info, final Context ctx) {
    switch (info.get_status()) {
    case DownloadManager.STATUS_SUCCESSFUL: // APK was downloaded. Install on click.
        File apk = new File(info.get_local_path());
        if (apk.exists()) {
            _action_icon.setImageDrawable(ContextCompat.getDrawable(ctx, R.drawable.install));
            _action_icon.setVisibility(View.VISIBLE);
            _action_icon.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i = new Intent(Intent.ACTION_VIEW);
                    i.setDataAndType(Uri.parse(info.get_local_uri()),
                            "application/vnd.android.package-archive");
                    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    if (i.resolveActivity(ctx.getPackageManager()) != null) {
                        ctx.startActivity(i);
                    } else {
                        Log.v(MainActivity.TAG, "Could not find anyone to receive ACTION_VIEW for "
                                + "the downloaded APK. (" + info.get_local_uri() + ")");
                    }
                }
            });
            return true;
        } else { // For some reason the APK is not present anymore. Remove the download information.
            return false;
        }
    case DownloadManager.STATUS_PENDING:
    case DownloadManager.STATUS_RUNNING:
        _action_icon.setImageDrawable(ContextCompat.getDrawable(ctx, android.R.drawable.stat_sys_download));
        ((Animatable) _action_icon.getDrawable()).start();
        _action_icon.setVisibility(View.VISIBLE);
        return true;
    default:
        return false;
    }
}

From source file:com.getchute.android.photopickerplus.ui.activity.ServicesActivity.java

@Override
public void takePhoto() {
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        NotificationUtil.makeToast(getApplicationContext(), R.string.toast_feature_camera);
        return;//from w  ww .j  a  v  a 2s .  c  om
    }
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        photoFile = AppUtil.getOutputMediaFile(MediaType.IMAGE);
        if (photoFile != null) {
            if (AppUtil.hasImageCaptureBug() == false) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            } else {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            }
            startTheCamera(takePictureIntent, Constants.CAMERA_PIC_REQUEST);
        }
    }
}

From source file:com.downrighttech.dmxdip.MainActivity.java

/**
 * Dialog Callback for a positive click//from   w  w w .ja v  a 2s  .  c o  m
 * @param dialog a DialogFragment
 */
@Override
public void onDialogPositiveClick(DialogFragment dialog) {
    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.putInt("pref_startup_dialog", -1);
    editor.commit();

    // Open the Market
    boolean validIntent = false;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("market://details?id=com.downrighttech.dmxdip"));
    ComponentName str = intent.resolveActivity(getPackageManager());
    if (intent.resolveActivity(getPackageManager()) != null)
        validIntent = true;
    else {
        intent.setData(Uri.parse("http://play.google.com/store/apps/details?id=com.downrighttech.dmxdip"));
        str = intent.resolveActivity(getPackageManager());
        if (intent.resolveActivity(getPackageManager()) != null)
            validIntent = true;
    }

    if (validIntent)
        startActivity(intent);
    else
        Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_SHORT).show();
}

From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java

private void initializeActionButtons() {

    RequestParams reqParams = new RequestParams();
    reqParams.put("licencia", configuration.getLicense());
    reqParams.put("movil", configuration.getMobile());
    reqParams.put("viajeID", serv.getIdServicio());

    AccionesRestModel salidaServ = new AccionesRestModel("Salida del servicio",
            "Seguro que desea dar salida al servicio?", "Salida de servicio cancelada",
            configuration.getUrl() + "/actions/setSalidaMovil", "Dando salida al servicio...");

    AccionesRestModel llegadaServ = new AccionesRestModel("Llegada del servicio",
            "Seguro que desea dar llegada al servicio?", "Llegada de servicio cancelada",
            configuration.getUrl() + "/actions/setLlegadaMovil", "Dando llegada al servicio...");

    doActionServicio(salidaServ, btnSalidaServicio, reqParams);
    doActionServicio(llegadaServ, btnLlegadaServicio, reqParams);

    btnFinalServicio.setOnClickListener(new View.OnClickListener() {
        @Override/* w  w  w. j  av  a2  s  .  c  o m*/
        public void onClick(View view) {
            doStartActivityForResult(FinalServicioActivity.class, 1);
        }
    });

    btnAttachImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dispatchTakePictureIntent(false);
        }
    });

    btnHistoriaClinica.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(getActivity(), HistoriaClinicaActivity.class);
            i.putExtra("viajeId", serv.getIdServicio());
            startActivity(i);
        }
    });

    if (configuration.enabledServiceCancelation()) {
        btnCancelarServicio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                doStartActivityForResult(CancelarServicioActivity.class, 2);
            }
        });
    } else {
        btnCancelarServicio.setVisibility(View.GONE);
    }

    btnDistanciaServicio.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                String whereToGo = String.format("google.navigation:q=%s,%s&mode=d", serv.getLatitud(),
                        serv.getLongitud());
                Uri gmmIntentUri = Uri.parse(whereToGo);
                Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                mapIntent.setPackage("com.google.android.apps.maps");
                if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                    startActivity(mapIntent);
                } else {
                    showToast("Debe instalar Google Maps en su telfono para utilizar este servicio.");
                }
            } catch (Exception ex) {
                showToast("No se pudo iniciar el servicio de distancia de servicio.");
            }
        }
    });

}