List of usage examples for android.net Uri fromParts
public static Uri fromParts(String scheme, String ssp, String fragment)
From source file:me.piebridge.prevent.ui.PreventActivity.java
private void showTestDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.app_name) + "(" + BuildConfig.VERSION_NAME + ")"); builder.setMessage(R.string.soak_version); builder.setIcon(R.drawable.ic_launcher); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override//from w w w.j a v a 2s. c om public void onCancel(DialogInterface dialog) { finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_DELETE, Uri.fromParts("package", BuildConfig.APPLICATION_ID, null))); finish(); } }); builder.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { init(); } }); builder.create().show(); }
From source file:com.opencabinetlabs.destinycommunityhub.ui.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }// www.j a va 2s. com switch (item.getItemId()) { case R.id.action_licenses: new LicenseDialog().show(getSupportFragmentManager(), DIALOG_LICENSE); return true; case R.id.action_feedback: Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "destinycommunityhub1@gmail.com", null)); emailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.feedback_subject)); startActivity(Intent.createChooser(emailIntent, "Send feedback...")); return true; } return super.onOptionsItemSelected(item); }
From source file:com.wspa.dm.eopiekun.GetLocationAdress.java
/** * Callback received when a permissions request has been completed. *//*from w w w .j av a 2 s .c o m*/ @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { Log.i(TAG, "onRequestPermissionResult"); if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) { if (grantResults.length <= 0) { // If user interaction was interrupted, the permission request is cancelled and you // receive empty arrays. Log.i(TAG, "User interaction was cancelled."); } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // Permission granted. getAddress(); } else { // Permission denied. // Notify the user via a SnackBar that they have rejected a core permission for the // app, which makes the Activity useless. In a real app, core permissions would // typically be best requested during a welcome-screen flow. // Additionally, it is important to remember that a permission might have been // rejected without asking the user for permission (device policy or "Never ask // again" prompts). Therefore, a user interface affordance is typically implemented // when permissions are denied. Otherwise, your app could appear unresponsive to // touches or interactions which have required permissions. showSnackbar(R.string.permission_denied_explanation, R.string.settings, new View.OnClickListener() { @Override public void onClick(View view) { // Build intent that displays the App settings screen. Intent intent = new Intent(); intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null); intent.setData(uri); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); } } }
From source file:me.trashout.fragment.EventDetailFragment.java
@OnClick({ R.id.event_detail_join_btn, R.id.event_detail_phone_layout, R.id.event_detail_email_layout, R.id.event_detail_direction_btn }) public void onClick(View view) { switch (view.getId()) { case R.id.event_detail_join_btn: if (mEvent != null) { if (user == null) { showToast(R.string.event_signToJoin); } else { MaterialDialog dialog = new MaterialDialog.Builder(getActivity()) .title(R.string.global_validation_warning) .content(R.string.event_joinEventConfirmationMessage).positiveText(android.R.string.ok) .negativeText(android.R.string.cancel).autoDismiss(true) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { showProgressDialog(); JoinUserToEventService.startForRequest(getContext(), JOIN_TO_EVENT_REQUEST_ID, mEvent.getId(), Collections.singletonList(user.getId())); }//from ww w. j a va2 s. c o m }).build(); dialog.show(); } } break; case R.id.event_detail_phone_layout: if (mEvent != null && mEvent.getContact() != null && !TextUtils.isEmpty(mEvent.getContact().getPhone())) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", mEvent.getContact().getPhone(), null)); startActivity(intent); } break; case R.id.event_detail_email_layout: if (mEvent != null && mEvent.getContact() != null && !TextUtils.isEmpty(mEvent.getContact().getEmail())) { sendEmail(); } break; case R.id.event_detail_direction_btn: if (mEvent != null) { Uri gmmIntentUri = Uri.parse("http://maps.google.com/maps?daddr=" + mEvent.getGps().getLat() + "," + mEvent.getGps().getLng()); Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); mapIntent.setPackage("com.google.android.apps.maps"); if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(mapIntent); } } break; } }
From source file:com.android.email.activity.zx.MessageView.java
private void onClickSender() { if (mMessage != null) { try {/* w w w.j a v a 2 s. com*/ Address senderEmail = mMessage.getFrom()[0]; Uri contactUri = Uri.fromParts("mailto", senderEmail.getAddress(), null); Intent contactIntent = new Intent(Contacts.Intents.SHOW_OR_CREATE_CONTACT); contactIntent.setData(contactUri); // Pass along full E-mail string for possible create dialog contactIntent.putExtra(Contacts.Intents.EXTRA_CREATE_DESCRIPTION, senderEmail.toString()); // Only provide personal name hint if we have one String senderPersonal = senderEmail.getPersonal(); if (senderPersonal != null) { contactIntent.putExtra(Intents.Insert.NAME, senderPersonal); } startActivity(contactIntent); } catch (MessagingException me) { if (Config.LOGV) { Log.v(Email.LOG_TAG, "loadMessageForViewHeadersAvailable", me); } } } }
From source file:me.trashout.fragment.CollectionPointDetailFragment.java
@OnClick({ R.id.collection_point_detail_phone_layout, R.id.collection_point_detail_email_layout }) public void onClick(View view) { switch (view.getId()) { case R.id.collection_point_detail_phone_layout: if (mCollectionPoint != null && !TextUtils.isEmpty(mCollectionPoint.getPhone())) { Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", mCollectionPoint.getPhone(), null)); startActivity(intent);//from w w w. j av a 2 s.c o m } break; case R.id.collection_point_detail_email_layout: if (mCollectionPoint != null && !TextUtils.isEmpty(mCollectionPoint.getEmail())) { ShareCompat.IntentBuilder.from(getActivity()).setType("message/rfc822") .addEmailTo(mCollectionPoint.getEmail()).setChooserTitle(R.string.global_sendEmail) .startChooser(); } break; } }
From source file:com.garlicg.screenrecord4cm.SettingsActivity.java
/** * ????????/* w w w . java 2 s . c om*/ */ private void showPermissionRationale(String reason) { AlertDialog.Builder ab = new AlertDialog.Builder(this); ab.setMessage(reason); ab.setPositiveButton(R.string.settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts("package", getPackageName(), null); intent.setData(uri); startActivity(intent); } }); ab.create().show(); }
From source file:com.android.server.telecom.testapps.TestConnectionService.java
@Override public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount, final ConnectionRequest request) { PhoneAccountHandle accountHandle = request.getAccountHandle(); ComponentName componentName = new ComponentName(this, TestConnectionService.class); if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) { final TestConnection connection = new TestConnection(false); final Bundle extras = request.getExtras(); final Uri providedHandle = extras.getParcelable(EXTRA_HANDLE); Uri handle = providedHandle == null ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(false), null) : providedHandle;/*from ww w . j ava 2 s. co m*/ connection.setAddress(handle, TelecomManager.PRESENTATION_ALLOWED); connection.setDialing(); addCall(connection); return connection; } else { return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR, "Invalid inputs: " + accountHandle + " " + componentName)); } }
From source file:com.google.android.apps.muzei.settings.SettingsChooseSourceFragment.java
private void redrawSources() { if (mSourceContainerView == null || !isAdded()) { return;//from w ww . j a v a 2 s. co m } mSourceContainerView.removeAllViews(); for (final Source source : mSources) { source.rootView = LayoutInflater.from(getActivity()).inflate(R.layout.settings_choose_source_item, mSourceContainerView, false); source.selectSourceButton = source.rootView.findViewById(R.id.source_image); source.selectSourceButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (source.componentName.equals(mSelectedSource)) { ((Callbacks) getActivity()).onRequestCloseActivity(); } else if (source.setupActivity != null) { mCurrentInitialSetupSource = source.componentName; launchSourceSetup(source); } else { mSourceManager.selectSource(source.componentName); } } }); source.selectSourceButton.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { final String pkg = source.componentName.getPackageName(); if (TextUtils.equals(pkg, getActivity().getPackageName())) { // Don't open Muzei's app info return false; } // Otherwise open third party extensions try { startActivity(new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", pkg, null))); } catch (final ActivityNotFoundException e) { return false; } return true; } }); source.rootView.setAlpha(ALPHA_UNSELECTED); source.icon.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP); source.selectSourceButton.setBackground(source.icon); TextView titleView = (TextView) source.rootView.findViewById(R.id.source_title); titleView.setText(source.label); titleView.setTextColor(source.color); updateSourceStatusUi(source); source.settingsButton = source.rootView.findViewById(R.id.source_settings_button); CheatSheet.setup(source.settingsButton); source.settingsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { launchSourceSettings(source); } }); animateSettingsButton(source.settingsButton, false, false); mSourceContainerView.addView(source.rootView); } updateSelectedItem(false); }
From source file:com.charabia.SmsViewActivity.java
@Override public void onActivityResult(int reqCode, int resultCode, Intent data) { super.onActivityResult(reqCode, resultCode, data); switch (reqCode) { case SMS_KEY_CONTACT: if (resultCode == RESULT_OK) { Uri uri = data.getData();/* ww w. ja v a 2 s . co m*/ ContentResolver cr = getContentResolver(); Cursor cursor = cr.query(uri, new String[] { Contacts.LOOKUP_KEY }, null, null, null); String lookup = null; if (cursor.moveToFirst()) { lookup = cursor.getString(0); } cursor.close(); if (lookup == null) { Toast.makeText(this, R.string.unexpected_error, Toast.LENGTH_LONG).show(); return; } cursor = cr.query(Data.CONTENT_URI, new String[] { Phone.NUMBER }, Data.MIMETYPE + "=? AND " + Data.LOOKUP_KEY + "=?", new String[] { Phone.CONTENT_ITEM_TYPE, lookup }, null); ArrayList<String> options = new ArrayList<String>(); while (cursor.moveToNext()) { options.add(cursor.getString(0)); } cursor.close(); final String[] phoneList = options.toArray(new String[0]); Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.send_invit_on_phone); builder.setItems(phoneList, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { keypair = tools.loadKeyPair(); RSAPublicKey pubKey = (RSAPublicKey) keypair.getPublic(); byte[] encoded = pubKey.getModulus().toByteArray(); byte[] data = new byte[3 + encoded.length]; data[0] = Tools.MAGIC[0]; data[1] = Tools.MAGIC[1]; data[2] = Tools.PUBLIC_KEY_TYPE; System.arraycopy(encoded, 0, data, 3, encoded.length); tools.sendData(phoneList[i], Tools.INVITATION, "", data); } }); builder.create().show(); } else { Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show(); } break; case IntentIntegrator.REQUEST_CODE: if (resultCode == RESULT_OK) { try { String contents = data.getStringExtra("SCAN_RESULT"); @SuppressWarnings("unused") String format = data.getStringExtra("SCAN_RESULT_FORMAT"); // Handle successful scan // TODO: add more tests control String[] infos = contents.split("\n"); Cipher rsaCipher = Cipher.getInstance(Tools.RSA_CIPHER_ALGO); if (mode == MODE_ESCLAVE) { // Save key and show crypted key on QRCode key = tools.generateKeyAES().getEncoded(); KeyFactory keyFact = KeyFactory.getInstance("RSA"); PublicKey pubkey = keyFact.generatePublic( new RSAPublicKeySpec(new BigInteger(infos[1]), new BigInteger(infos[2]))); rsaCipher.init(Cipher.ENCRYPT_MODE, pubkey); int blockSize = rsaCipher.getBlockSize(); int nbBlock = key.length / blockSize; int reste = key.length % blockSize; byte[] cryptedKey = new byte[(nbBlock + 1) * rsaCipher.getOutputSize(blockSize)]; int offset = 0; for (int i = 0; i < nbBlock; i++) { offset += rsaCipher.doFinal(key, i * blockSize, blockSize, cryptedKey, offset); } rsaCipher.doFinal(key, nbBlock * blockSize, reste, cryptedKey, offset); IntentIntegrator.shareText(SmsViewActivity.this, prefPhoneNumber + "\n" + Base64.encodeToString(cryptedKey, Base64.NO_WRAP)); } else { // We have read crypted key, so decode it rsaCipher.init(Cipher.DECRYPT_MODE, keypair.getPrivate()); byte[] cryptedData = Base64.decode(infos[1], Base64.NO_WRAP); int blockSize = rsaCipher.getBlockSize(); int nbBlock = cryptedData.length / blockSize; int offset = 0; byte[] tempKey = new byte[(nbBlock + 1) * blockSize]; for (int i = 0; i < nbBlock; i++) { offset += rsaCipher.doFinal(cryptedData, i * blockSize, blockSize, tempKey, offset); } key = new byte[offset]; System.arraycopy(tempKey, 0, key, 0, offset); } phoneNumber = infos[0]; // store the key // TODO dialog to confirm add contact in mode SLAVE try { new Tools(this).updateOrCreateContactKey(phoneNumber, key); } catch (NoContactException e) { e.printStackTrace(); // propose to add contact Intent newIntent = new Intent(Intents.SHOW_OR_CREATE_CONTACT); newIntent.setData(Uri.fromParts("tel", phoneNumber, null)); startActivityForResult(newIntent, ADD_CONTACT); return; } Toast.makeText(this, getString(R.string.contact_added) + "\n" + phoneNumber, Toast.LENGTH_LONG) .show(); } catch (Exception e) { e.printStackTrace(); Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show(); } } else { // TODO: string Toast.makeText(this, R.string.fail_reading_tag, Toast.LENGTH_LONG).show(); } break; case ADD_CONTACT: try { tools.updateOrCreateContactKey(phoneNumber, key); Toast.makeText(this, getString(R.string.contact_added) + "\n" + phoneNumber, Toast.LENGTH_LONG) .show(); } catch (NoContactException e) { e.printStackTrace(); Toast.makeText(this, R.string.error_create_key, Toast.LENGTH_LONG).show(); } break; } }