List of usage examples for android.content Intent resolveActivity
public ComponentName resolveActivity(@NonNull PackageManager pm)
From source file:com.psu.capstonew17.pdxaslapp.CreateCardActivity.java
private void dispatchTakeVideoIntent() { Intent takeVideoIntent = new Intent(); takeVideoIntent.setAction(MediaStore.ACTION_VIDEO_CAPTURE); if (takeVideoIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takeVideoIntent, GET_VIDEO); } else {/*from w w w. jav a2 s. co m*/ Toast.makeText(getApplicationContext(), R.string.card_record_video_error, Toast.LENGTH_SHORT).show(); } }
From source file:org.exoplatform.utils.ExoDocumentUtils.java
/** * Check if the device has an application to open this type of file. * //from w w w . ja v a 2 s. com * @param context Context (mandatory) * @param mimeType Mime Type to check (mandatory) * @param url file url to guess the mime type from (optional) * @return true if an application can open the given Mime Type */ public static boolean isCallable(Context context, String mimeType, String url) throws IllegalArgumentException { if (context == null || mimeType == null) throw new IllegalArgumentException("Context or mime-type cannot be null."); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setType(mimeType.toLowerCase(Locale.US)); ComponentName activity = intent.resolveActivity(context.getPackageManager()); if (activity == null && url != null) { // Fallback on a guessed mime type if the first one doesn't work String guessedMimeType = URLConnection.guessContentTypeFromName(url); if (guessedMimeType != null) { intent = new Intent(Intent.ACTION_VIEW); intent.setType(guessedMimeType.toLowerCase(Locale.US)); activity = intent.resolveActivity(context.getPackageManager()); } } return activity != null; }
From source file:com.geecko.QuickLyric.fragment.SettingsFragment.java
@Override public boolean onPreferenceClick(Preference preference) { AlertDialog.Builder dialog;/* w w w .j av a 2s . c om*/ switch (preference.getKey()) { case "pref_about": dialog = new AlertDialog.Builder(getActivity()); dialog.setView( getActivity().getLayoutInflater().inflate(R.layout.about_dialog, (ViewGroup) getView(), false)); dialog.create().show(); break; case "pref_contribute": Intent browserIntent = new Intent(Intent.ACTION_VIEW); browserIntent.setData(Uri.parse("https://github.com/geecko86/QuickLyric")); if (browserIntent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(browserIntent); break; case "pref_beta": dialog = new AlertDialog.Builder(getActivity()); dialog.setView( getActivity().getLayoutInflater().inflate(R.layout.beta_dialog, (ViewGroup) getView(), false)); dialog.create().show(); break; case "pref_issues": Intent emailIntent = new Intent(Intent.ACTION_SENDTO); emailIntent.setData(Uri.parse("mailto:")); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "quicklyricapp@gmail.com" }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Issues with QuickLyric"); if (emailIntent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(emailIntent); break; } return true; }
From source file:com.example.android.navigationdrawerexample.LeftDrawerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mHorizonDrawerToggle.onOptionsItemSelected(item)) { return true; }/* w w w. j a v a 2s .c o m*/ // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.example.android.navigationdrawerexample.BottomDrawerActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mVerticalDrawerToggle.onOptionsItemSelected(item)) { return true; }/*from w w w . j a v a2s .co m*/ // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.github.blalasaadri.sprinttopics.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }/* ww w .j a va 2s . c o m*/ // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:dev.dworks.libs.actionbartoggle.demo.SlidingPaneLayoutActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // The action bar home/up action should open or close the drawer. // ActionBarDrawerToggle will take care of this. if (mActionBarToggle.onOptionsItemSelected(item)) { return true; }//from w ww .j av a2s. com // Handle action buttons switch (item.getItemId()) { case R.id.action_websearch: // create intent to perform web search for this planet Intent intent = new Intent(Intent.ACTION_WEB_SEARCH); intent.putExtra(SearchManager.QUERY, getSupportActionBar().getTitle()); // catch event that there's no activity to handle intent if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show(); } return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.saarang.samples.apps.iosched.ui.ExpertsDirectoryActivity.java
private void processJSON(String uname) { JSONArray theArray = null;//from w ww .j a va 2 s. c o m try { JSONObject jObj; jObj = new JSONObject(uname); theArray = jObj.getJSONArray("data"); } catch (JSONException e) { e.printStackTrace(); } if (true) { final String id[] = new String[theArray.length()]; final double priority[] = new double[theArray.length()]; final String tittle[] = new String[theArray.length()]; final String logolink[] = new String[theArray.length()]; final String link[] = new String[theArray.length()]; try { for (int i = 0; i < theArray.length(); i++) { JSONObject jsonInside = theArray.getJSONObject(i); id[i] = jsonInside.getString("id"); priority[i] = jsonInside.getDouble("priority"); tittle[i] = jsonInside.getString("title"); logolink[i] = jsonInside.getString("logo"); link[i] = jsonInside.getString("sponsor_link"); } int input = theArray.length(); for (int index = 0; index < input; index++) { for (int index1 = 0; index1 < input - 1; index1++) { if (priority[index1] > priority[index1 + 1]) { double temp_prio = priority[index1]; String temp_logolink = logolink[index1]; String temp_title = tittle[index1]; String temp_link = link[index1]; priority[index1] = priority[index1 + 1]; logolink[index1] = logolink[index1 + 1]; tittle[index1] = tittle[index1 + 1]; link[index1] = link[index1 + 1]; priority[index1 + 1] = temp_prio; logolink[index1 + 1] = temp_logolink; tittle[index1 + 1] = temp_title; link[index1 + 1] = temp_link; } } } for (int i = 0; i < logolink.length / 2; i++) { String temp = logolink[i]; logolink[i] = logolink[logolink.length - 1 - i]; logolink[logolink.length - 1 - i] = temp; } for (int i = 0; i < tittle.length / 2; i++) { String temp = tittle[i]; tittle[i] = tittle[tittle.length - 1 - i]; tittle[tittle.length - 1 - i] = temp; } for (int i = 0; i < link.length / 2; i++) { String temp = link[i]; link[i] = link[link.length - 1 - i]; link[link.length - 1 - i] = temp; } for (int i = 0; i < input; i++) { Log.d("", String.valueOf(priority[i])); } SponsorsList adapter = new SponsorsList(ExpertsDirectoryActivity.this, id, tittle, logolink, link); ListView list = (ListView) findViewById(R.id.listview); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long useless_id) { String url = link[position]; Uri webpage = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, webpage); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.platform.middlewares.plugins.CameraPlugin.java
@Override public boolean handle(String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) { // GET /_camera/take_picture ////from w w w .ja v a2s .c o m // Optionally pass ?overlay=<id> (see overlay ids below) to show an overlay // in picture taking mode // // Status codes: // - 200: Successful image capture // - 204: User canceled image picker // - 404: Camera is not available on this device // - 423: Multiple concurrent take_picture requests. Only one take_picture request may be in flight at once. // if (target.startsWith("/_camera/take_picture")) { Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod()); final MainActivity app = MainActivity.app; if (app == null) { Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "context is null", baseRequest, response); } if (globalBaseRequest != null) { Log.e(TAG, "handle: already taking a picture: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(423, null, baseRequest, response); } PackageManager pm = app.getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) { Log.e(TAG, "handle: no camera available: "); return BRHTTPHelper.handleError(402, null, baseRequest, response); } if (ContextCompat.checkSelfPermission(app, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(app, Manifest.permission.CAMERA)) { Log.e(TAG, "handle: no camera access, showing instructions"); ((BreadWalletApp) app.getApplication()).showCustomToast(app, app.getString(R.string.allow_camera_access), MainActivity.screenParametersPoint.y / 2, Toast.LENGTH_LONG, 0); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(app, new String[] { Manifest.permission.CAMERA }, BRConstants.CAMERA_REQUEST_GLIDERA_ID); } } else { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(app.getPackageManager()) != null) { app.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } continuation = ContinuationSupport.getContinuation(request); continuation.suspend(response); globalBaseRequest = baseRequest; } return true; } else if (target.startsWith("/_camera/picture/")) { Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod()); final MainActivity app = MainActivity.app; if (app == null) { Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "context is null", baseRequest, response); } String id = target.replace("/_camera/picture/", ""); byte[] pictureBytes = readPictureForId(app, id); if (pictureBytes == null) { Log.e(TAG, "handle: WARNING pictureBytes is null: " + target + " " + baseRequest.getMethod()); return BRHTTPHelper.handleError(500, "pictureBytes is null", baseRequest, response); } byte[] imgBytes = pictureBytes; String b64opt = request.getParameter("base64"); String contentType = "image/jpeg"; if (b64opt != null && !b64opt.isEmpty()) { contentType = "text/plain"; String b64 = "data:image/jpeg;base64," + Base64.encodeToString(pictureBytes, Base64.NO_WRAP); try { imgBytes = b64.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return BRHTTPHelper.handleError(500, null, baseRequest, response); } } return BRHTTPHelper.handleSuccess(200, null, baseRequest, response, contentType); } else return false; }
From source file:com.chrismorais.android.sunshine.app.ForecastFragment.java
private void openPreferredLocationInMap() { if (null != mForecastAdapter) { Cursor c = mForecastAdapter.getCursor(); if (null != c) { c.moveToPosition(0);//w ww . j a v a 2 s . co m String posLat = c.getString(COL_COORD_LAT); String posLong = c.getString(COL_COORD_LONG); Uri geoLocation = Uri.parse("geo:" + posLat + "," + posLong); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(geoLocation); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(intent); } else { Log.d(LOG_TAG, "Couldn't call " + geoLocation.toString() + ", no receiving apps installed!"); } } } }