List of usage examples for android.content Intent FLAG_GRANT_READ_URI_PERMISSION
int FLAG_GRANT_READ_URI_PERMISSION
To view the source code for android.content Intent FLAG_GRANT_READ_URI_PERMISSION.
Click Source Link
From source file:com.android.gallery3d.app.PhotoPage.java
private void launchSimpleEditor() { MediaItem current = mModel.getMediaItem(0); if (current == null || (current.getSupportedOperations() & MediaObject.SUPPORT_EDIT) == 0) { return;/*from w w w . j a va2 s . co m*/ } Intent intent = new Intent(ACTION_SIMPLE_EDIT); intent.setDataAndType(current.getContentUri(), current.getMimeType()) .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); if (mActivity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY) .size() == 0) { intent.setAction(Intent.ACTION_EDIT); } intent.putExtra(FilterShowActivity.LAUNCH_FULLSCREEN, mActivity.isFullscreen()); ((Activity) mActivity).startActivityForResult(Intent.createChooser(intent, null), REQUEST_EDIT); overrideTransitionToEditor(); }
From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java
private void onFinished(Uri... uris) { Log.d(TAG, "onFinished() " + Arrays.toString(uris)); final Intent intent = new Intent(); if (uris.length == 1) { intent.setData(uris[0]);// w w w.ja v a2s . com } else if (uris.length > 1) { final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0])); for (int i = 1; i < uris.length; i++) { clipData.addItem(new ClipData.Item(uris[i])); } if (Utils.hasJellyBean()) { intent.setClipData(clipData); } else { intent.setData(uris[0]); } } if (mState.action == ACTION_GET_CONTENT || mState.action == ACTION_BROWSE) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } setResult(Activity.RESULT_OK, intent); finish(); }
From source file:org.appspot.apprtc.CallActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILE_CODE && resultCode == Activity.RESULT_OK) { Uri path = intent.getData();//from w w w. java 2 s . c o m long size = 0; String name = ""; ContentResolver cr = this.getContentResolver(); String mime = cr.getType(path); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { size = TokenPeerConnection.getContentSize(path, this); name = TokenPeerConnection.getContentName(path, this); final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. getContentResolver().takePersistableUriPermission(path, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } else { size = TokenPeerConnection.getContentSize(path, this); name = TokenPeerConnection.getContentName(path, this); } // Do something with the result... if (mService != null) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String time = fmt.format(new Date()); FileInfo fileInfo = new FileInfo("", "", name, String.valueOf(size), mime); mService.sendFileMessage(time, mService.getAccountName(), "self", fileInfo, path.toString(), size, name, mime, mFileRecipient, mService.getCurrentRoomName()); ChatItem item = new ChatItem(time, mService.getAccountName(), fileInfo, "self", mFileRecipient); item.setOutgoing(); chatFragment.addOutgoingMessage(item); } } }
From source file:com.xperia64.timidityae.TimidityActivity.java
@SuppressLint("NewApi") @Override// www . ja v a 2s . c o m protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Check which request we're responding to if (requestCode == 1) { if (oldTheme != Globals.theme) { Intent intent = getIntent(); intent.putExtra("justtheme", true); intent.putExtra("needservice", false); finish(); startActivity(intent); } } else if (requestCode == 42) { if (resultCode == RESULT_OK) { Uri treeUri = data.getData(); getContentResolver().takePersistableUriPermission(treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); } initCallback2(); } }
From source file:de.vanita5.twittnuker.util.Utils.java
public static Intent createStatusShareIntent(final Context context, final ParcelableStatus status) { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); final String name = status.user_name, screenName = status.user_screen_name; final String timeString = formatToLongTimeString(context, status.timestamp); final String subject = context.getString(R.string.share_subject_format, name, screenName, timeString); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, status.text_plain); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); return intent; }
From source file:org.telegram.ui.SettingsActivity.java
private void sendLogs() { if (getParentActivity() == null) { return;/*from w ww . ja v a2s . co m*/ } AlertDialog progressDialog = new AlertDialog(getParentActivity(), 3); progressDialog.setCanCacnel(false); progressDialog.show(); Utilities.globalQueue.postRunnable(() -> { try { File sdCard = ApplicationLoader.applicationContext.getExternalFilesDir(null); File dir = new File(sdCard.getAbsolutePath() + "/logs"); File zipFile = new File(dir, "logs.zip"); if (zipFile.exists()) { zipFile.delete(); } File[] files = dir.listFiles(); boolean[] finished = new boolean[1]; BufferedInputStream origin = null; ZipOutputStream out = null; try { FileOutputStream dest = new FileOutputStream(zipFile); out = new ZipOutputStream(new BufferedOutputStream(dest)); byte data[] = new byte[1024 * 64]; for (int i = 0; i < files.length; i++) { FileInputStream fi = new FileInputStream(files[i]); origin = new BufferedInputStream(fi, data.length); ZipEntry entry = new ZipEntry(files[i].getName()); out.putNextEntry(entry); int count; while ((count = origin.read(data, 0, data.length)) != -1) { out.write(data, 0, count); } if (origin != null) { origin.close(); origin = null; } } finished[0] = true; } catch (Exception e) { e.printStackTrace(); } finally { if (origin != null) { origin.close(); } if (out != null) { out.close(); } } AndroidUtilities.runOnUIThread(() -> { try { progressDialog.dismiss(); } catch (Exception ignore) { } if (finished[0]) { Uri uri; if (Build.VERSION.SDK_INT >= 24) { uri = FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", zipFile); } else { uri = Uri.fromFile(zipFile); } Intent i = new Intent(Intent.ACTION_SEND); if (Build.VERSION.SDK_INT >= 24) { i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } i.setType("message/rfc822"); i.putExtra(Intent.EXTRA_EMAIL, ""); i.putExtra(Intent.EXTRA_SUBJECT, "Logs from " + LocaleController.getInstance().formatterStats.format(System.currentTimeMillis())); i.putExtra(Intent.EXTRA_STREAM, uri); getParentActivity() .startActivityForResult(Intent.createChooser(i, "Select email application."), 500); } else { Toast.makeText(getParentActivity(), LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred), Toast.LENGTH_SHORT).show(); } }); } catch (Exception e) { e.printStackTrace(); } }); }
From source file:com.free.searcher.MainFragment.java
/** * After triggering the Storage Access Framework, ensure that folder is really writable. Set preferences * accordingly.//from w w w.ja va 2s . c o m * * @param requestCode The integer request code originally supplied to startActivityForResult(), allowing you to identify who * this result came from. * @param resultCode The integer result code returned by the child activity through its setResult(). * @param data An Intent, which can return result data to the caller (various data can be attached to Intent * "extras"). */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void onActivityResultLollipop(final int requestCode, final int resultCode, @NonNull final Intent data) { if (requestCode == INTENT_WRITE_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { // Get Uri from Storage Access Framework. Uri treeUri = data.getData(); // Persist URI in shared preference so that you can use it later. // Use your own framework here instead of PreferenceUtil. FileUtils.setSharedPreferenceUri(R.string.key_internal_uri_extsdcard, treeUri); // Persist access permissions. final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); System.out.println("treeUri:" + treeUri); System.out.println("takeFlags" + String.valueOf(takeFlags)); System.out.println("data.getFlags()" + String.valueOf(data.getFlags())); activity.getContentResolver().takePersistableUriPermission(treeUri, takeFlags); } } }
From source file:cl.gisred.android.InspActivity.java
private void cerrarFormCrear(boolean bSave, View v, int idR) { if (bSave) {//from w ww . j av a 2s . c o m if (!validarForm(v)) { DialogoConfirmacion oDialog = new DialogoConfirmacion(); oDialog.show(getFragmentManager(), "tagAlert"); return; } else { Resources res = getResources(); InputStream in_s = res.openRawResource(R.raw.index); try { View vAction = getLayoutValidate(v); byte[] b = new byte[in_s.available()]; in_s.read(b); String sHtml = new String(b); HtmlUtils oHtml = new HtmlUtils(getApplicationContext(), sHtml); String sValueNumMed = "null"; for (View view : vAction.getTouchables()) { if (view.getClass().getGenericSuperclass().equals(EditText.class)) { EditText oText = (EditText) view; if (!oText.getText().toString().trim().isEmpty()) { String sMapvalue = HtmlUtils.getMapvalue(oText.getId()); String sValorChr = oText.getText().toString(); oHtml.setValueById(sMapvalue, "txt", sValorChr); if (oText.getId() == R.id.txtOT) { sValueNumMed = sValorChr; } if (sMapvalue != null && sMapvalue.contains("txt_trabajo_cant")) { try { double dValue = Double.valueOf(sValorChr); oHtml.sumHH += dValue; } catch (Exception ex) { Log.e("Double Convert", "error: " + ex.getMessage()); } } } } else if (view.getClass().getGenericSuperclass().equals(CheckBox.class)) { CheckBox oCheck = (CheckBox) view; String sCheck = HtmlUtils.getMapvalue(oCheck.getId()); sCheck += oCheck.isChecked() ? "si" : "no"; oHtml.setValueById(sCheck, "chk", ""); } else if (view.getClass().getGenericSuperclass().equals(Spinner.class)) { Spinner oSpinner = (Spinner) view; oHtml.setValueById(HtmlUtils.getMapvalue(oSpinner.getId()), "txt", oSpinner.getSelectedItem().toString()); } else if (view.getClass().getGenericSuperclass().equals(RadioButton.class)) { RadioButton oRadioButton = (RadioButton) view; if (oRadioButton.isChecked()) { String sRadio = HtmlUtils .getMapvalue(((RadioGroup) oRadioButton.getParent()).getId()); sRadio += oRadioButton.getText().toString().toLowerCase().replace(" ", ""); oHtml.setValueById(sRadio, "rad", ""); } } else if (view.getClass().getGenericSuperclass().equals(ImageView.class)) { } } //SUMA TOTAL HH oHtml.setValueById("txt_trabajo_cant_tot", "txt", "" + oHtml.sumHH); //VALIDAR FIRMAS if (valImage(vAction, R.id.imgFirmaIns)) oHtml.setValueById("firm_prop", "img", String.format("%s.jpg", R.id.imgFirmaIns)); if (valImage(vAction, R.id.imgFirmaTec)) oHtml.setValueById("firm_tecn", "img", String.format("%s.jpg", R.id.imgFirmaTec)); if (valImage(vAction, R.id.imgPhoto1)) oHtml.setValueById("foto_1", "img", "foto1.jpg"); if (valImage(vAction, R.id.imgPhoto2)) oHtml.setValueById("foto_2", "img", "foto2.jpg"); if (valImage(vAction, R.id.imgPhoto3)) oHtml.setValueById("foto_3", "img", "foto3.jpg"); oHtml.setTitleHtml(sValueNumMed); String sHtmlFinal = oHtml.getHtmlFinal(); //guardar en disco oHtml.createHtml(sHtmlFinal); //VIA CustomTabs /*String url = oHtml.getPathHtml(); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.launchUrl(this, Uri.parse(url));*/ //VIA CHROME scheme if (Util.isPackageExisted("com.android.chrome", this)) { String url = oHtml.getPathHtml(); File f = new File(url); MimeTypeMap mime = MimeTypeMap.getSingleton(); String ext = f.getName().substring(f.getName().lastIndexOf(".") + 1); String type = mime.getMimeTypeFromExtension(ext); Uri uri = Uri.parse("googlechrome://navigate?url=" + url); Intent in = new Intent(Intent.ACTION_VIEW); //in.setDataAndType(uri, "text/html"); in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); in.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //Uri uriExternal = FileProvider.getUriForFile(getApplicationContext(), "cl.gisred.android", f); in.setDataAndType(uri, type); //startActivity(in); startActivity(Intent.createChooser(in, "Escoja Chrome")); } else { Toast.makeText(this, "Debe instalar Chrome, solo preview disponible", Toast.LENGTH_LONG) .show(); Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(oHtml.getPathHtml())); startActivity(myIntent); } } catch (IOException e) { e.printStackTrace(); } } } menuMultipleActions.setVisibility(View.VISIBLE); menuInspeccionActions.setVisibility(View.VISIBLE); fabShowForm.setVisibility(View.GONE); formCrear.dismiss(); }
From source file:org.appspot.apprtc.CallActivity.java
void handleIntent(Intent intent) { if (intent == null || intent.getAction() == null) { return;/*from w ww .j av a 2 s.co m*/ } if (intent.hasExtra(WebsocketService.EXTRA_ADDRESS)) { mServer = intent.getStringExtra(WebsocketService.EXTRA_ADDRESS); } if (intent.getAction().equals(ACTION_SHARE_FILE)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); mFileRecipient = user.Id; Intent i; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { i = new Intent(); i.setAction(Intent.ACTION_GET_CONTENT); i.setType("*/*"); } else { i = new Intent(Intent.ACTION_OPEN_DOCUMENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); i.setType("*/*"); } startActivityForResult(i, FILE_CODE); } else if (intent.getAction().equals(ACTION_HANG_UP)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); if (mAdditionalPeers.containsKey(user.Id)) { mAdditionalPeers.get(user.Id).getRemoteViews().setId(""); updateRemoteViewList(mAdditionalPeers.get(user.Id).getRemoteViews()); mAdditionalPeers.get(user.Id).close(); mAdditionalPeers.remove(user.Id); } else if (mPeerId.equals(user.Id)) { onCallHangUp(); } } else if (intent.getAction().equals(ACTION_TOGGLE_VIDEO)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); boolean enabled = intent.getBooleanExtra(CallActivity.EXTRA_VIDEO_CALL, true); if (mAdditionalPeers.containsKey(user.Id)) { mAdditionalPeers.get(user.Id).setVideoEnabled(enabled); } else if (mPeerId.equals(user.Id)) { onToggleVideo(); } } else if (intent.getAction().equals(ACTION_TOGGLE_MIC)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); boolean enabled = intent.getBooleanExtra(CallActivity.EXTRA_MIC_ENABLED, true); if (mAdditionalPeers.containsKey(user.Id)) { mAdditionalPeers.get(user.Id).setAudioEnabled(enabled); } else if (mPeerId.equals(user.Id)) { onToggleMic(); } } else if (intent.getAction().equals(ACTION_SEND_MESSAGE)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); String messageText = intent.getStringExtra(CallActivity.EXTRA_MESSAGE); if (mService != null) { SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); fmt.setTimeZone(TimeZone.getTimeZone("GMT")); String time = fmt.format(new Date()); mService.sendChatMessage(time, mService.getAccountName(), "Self", messageText, user.Id, mService.getCurrentRoomName()); } } else if (intent.getAction().equals(ACTION_NEW_CALL)) { String signaling = intent.getStringExtra(EXTRA_SIGNALING); if (signaling != null) { mSignaling = signaling; } if (mSignaling.equals("xmpp")) { mOwnJid = intent.getStringExtra(BroadcastTypes.EXTRA_ACCOUNT_JID); mPeerId = intent.getStringExtra(BroadcastTypes.EXTRA_JID); mPeerName = mPeerId; initiator = true; signalingParameters = new SignalingParameters(WebsocketService.getIceServers(), initiator, "", "", "", null, null); } else { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); if (intent.hasExtra(WebsocketService.EXTRA_USERACTION)) { if (mConferenceId == null) { SessionIdentifierGenerator gen = new SessionIdentifierGenerator(); mConferenceId = mOwnId + "_" + gen.nextSessionId(); } } if (mPeerId.length() == 0) { callUser(user); } else if (!mPeerId.equals(user.Id)) { // don't call if already in call AdditionalPeerConnection additionalPeerConnection = new AdditionalPeerConnection(this, this, this, true, user.Id, WebsocketService.getIceServers(), peerConnectionParameters, rootEglBase, localRender, getRemoteRenderScreen(user.Id, user.displayName, getUrl(user.buddyPicture)), peerConnectionClient.getMediaStream(), "", peerConnectionClient.getPeerConnectionFactory()); mAdditionalPeers.put(user.Id, additionalPeerConnection); updateVideoView(); } } } else if (intent.getAction().equals(WebsocketService.ACTION_ADD_ALL_CONFERENCE)) { ArrayList<User> users = getUsers(); for (User user : users) { boolean added = false; if (!mPeerId.equals(user.Id) && !mAdditionalPeers.containsKey(user.Id) && (mOwnId.compareTo(user.Id) < 0)) { AdditionalPeerConnection additionalPeerConnection = new AdditionalPeerConnection(this, this, this, true, user.Id, WebsocketService.getIceServers(), peerConnectionParameters, rootEglBase, localRender, getRemoteRenderScreen(user.Id, user.displayName, getUrl(user.buddyPicture)), peerConnectionClient.getMediaStream(), mConferenceId, peerConnectionClient.getPeerConnectionFactory()); mAdditionalPeers.put(user.Id, additionalPeerConnection); updateVideoView(); added = true; } } if (mConferenceId == null) { SessionIdentifierGenerator gen = new SessionIdentifierGenerator(); mConferenceId = mOwnId + "_" + gen.nextSessionId(); } } else if (intent.getAction().equals(WebsocketService.ACTION_ADD_CONFERENCE_USER)) { User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); String conferenceId = intent.getStringExtra(WebsocketService.EXTRA_CONFERENCE_ID); mOwnId = intent.getStringExtra(WebsocketService.EXTRA_OWN_ID); String userId = intent.getStringExtra(WebsocketService.EXTRA_ID); if (mConferenceId == null) { mConferenceId = conferenceId; } boolean added = false; if ((!mPeerId.equals(userId) && !mAdditionalPeers.containsKey(userId) && (mOwnId.compareTo(userId) < 0))) { if (user != null) { Log.d(TAG, "Calling conference: " + user.displayName); } if (peerConnectionClient.getMediaStream() != null) { String displayName = getString(R.string.unknown); String imgUrl = ""; if (user != null) { displayName = user.displayName; imgUrl = getUrl(user.buddyPicture); } AdditionalPeerConnection additionalPeerConnection = new AdditionalPeerConnection(this, this, this, true, userId, WebsocketService.getIceServers(), peerConnectionParameters, rootEglBase, localRender, getRemoteRenderScreen(userId, displayName, imgUrl), peerConnectionClient.getMediaStream(), mConferenceId, peerConnectionClient.getPeerConnectionFactory()); mAdditionalPeers.put(userId, additionalPeerConnection); updateVideoView(); added = true; } else if (mPeerId.length() == 0) { // show the call as incoming String displayName = getString(R.string.unknown); String imgUrl = ""; if (user != null) { displayName = user.displayName; imgUrl = getUrl(user.buddyPicture); } mPeerId = userId; mPeerName = displayName; ThumbnailsCacheManager.LoadImage(imgUrl, remoteUserImage, displayName, true, true); initiator = true; signalingParameters = new SignalingParameters(WebsocketService.getIceServers(), initiator, "", "", "", null, null); } else { mQueuedPeers.add(user); } } } else if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_ICE_CANDIDATE)) { SerializableIceCandidate candidate = (SerializableIceCandidate) intent .getParcelableExtra(WebsocketService.EXTRA_CANDIDATE); String id = intent.getStringExtra(WebsocketService.EXTRA_ID); String token = intent.getStringExtra(WebsocketService.EXTRA_TOKEN); if (token != null && token.length() != 0) { if (mTokenPeers.containsKey(candidate.from)) { IceCandidate ic = new IceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp); mTokenPeers.get(candidate.from).addRemoteIceCandidate(ic); } } else if (mAdditionalPeers.containsKey(candidate.from)) { IceCandidate ic = new IceCandidate(candidate.sdpMid, candidate.sdpMLineIndex, candidate.sdp); mAdditionalPeers.get(candidate.from).addRemoteIceCandidate(ic); } else if (id.equals(mSdpId)) { onRemoteIceCandidate(candidate, id, candidate.from); } } else if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_DESCRIPTION)) { SerializableSessionDescription sdp = (SerializableSessionDescription) intent .getSerializableExtra(WebsocketService.EXTRA_REMOTE_DESCRIPTION); String token = intent.getStringExtra(WebsocketService.EXTRA_TOKEN); String id = intent.getStringExtra(WebsocketService.EXTRA_ID); String conferenceId = intent.getStringExtra(WebsocketService.EXTRA_CONFERENCE_ID); String signaling = intent.getStringExtra(EXTRA_SIGNALING); String ownJid = intent.getStringExtra(BroadcastTypes.EXTRA_ACCOUNT_JID); mSid = intent.getStringExtra(BroadcastTypes.EXTRA_SID); User user = (User) intent.getSerializableExtra(WebsocketService.EXTRA_USER); if (mConferenceId == null && conferenceId != null && conferenceId.length() != 0) { mConferenceId = conferenceId; } /*else if (conferenceId != null && mConferenceId != null && !mConferenceId.equals(conferenceId)) { // already in a conference, reject the invite return; }*/ if (ownJid != null) { mOwnJid = ownJid; } if (signaling != null && signaling.equals("xmpp")) { mSignaling = signaling; } if (token != null && token.length() != 0) { if (mTokenPeers.containsKey(sdp.from)) { mTokenPeers.get(sdp.from) .setRemoteDescription(new SessionDescription(sdp.type, sdp.description)); } } else if (mPeerId.length() == 0 || mPeerId.equals(sdp.from)) { mSdpId = id; mPeerId = sdp.from; String imgUrl = ""; if (user != null) { mPeerName = user.displayName; imgUrl = getUrl(user.buddyPicture); } else { mPeerName = getString(R.string.unknown); } ThumbnailsCacheManager.LoadImage(imgUrl, remoteUserImage, mPeerName, true, true); if (peerConnectionClient.isConnected()) { onRemoteDescription(sdp, token, id, conferenceId, "", "", ""); } else { mRemoteSdp = sdp; mToken = token; } } else { if (mAdditionalPeers.containsKey(sdp.from)) { mAdditionalPeers.get(sdp.from) .setRemoteDescription(new SessionDescription(sdp.type, sdp.description)); } else { if (iceConnected && peerConnectionClient.getMediaStream() != null) { addToCall(sdp, user); } else { mQueuedRemoteConnections.add(new RemoteConnection(sdp, user)); } } } } }
From source file:net.bluehack.ui.MediaActivity.java
private void onItemClick(int index, View view, MessageObject message, int a) { if (message == null) { return;//from w ww. jav a2s. c o m } if (actionBar.isActionModeShowed()) { int loadIndex = message.getDialogId() == dialog_id ? 0 : 1; if (selectedFiles[loadIndex].containsKey(message.getId())) { selectedFiles[loadIndex].remove(message.getId()); if (!message.canDeleteMessage(null)) { cantDeleteMessagesCount--; } } else { selectedFiles[loadIndex].put(message.getId(), message); if (!message.canDeleteMessage(null)) { cantDeleteMessagesCount++; } } if (selectedFiles[0].isEmpty() && selectedFiles[1].isEmpty()) { actionBar.hideActionMode(); } else { selectedMessagesCountTextView.setNumber(selectedFiles[0].size() + selectedFiles[1].size(), true); } actionBar.createActionMode().getItem(delete) .setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE); scrolling = false; if (view instanceof SharedDocumentCell) { ((SharedDocumentCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true); } else if (view instanceof SharedPhotoVideoCell) { ((SharedPhotoVideoCell) view).setChecked(a, selectedFiles[loadIndex].containsKey(message.getId()), true); } else if (view instanceof SharedLinkCell) { ((SharedLinkCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true); } } else { if (selectedMode == 0) { PhotoViewer.getInstance().setParentActivity(getParentActivity()); PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, this); } else if (selectedMode == 1 || selectedMode == 4) { if (view instanceof SharedDocumentCell) { SharedDocumentCell cell = (SharedDocumentCell) view; if (cell.isLoaded()) { if (message.isMusic()) { if (MediaController.getInstance().setPlaylist(sharedMediaData[selectedMode].messages, message)) { return; } } File f = null; String fileName = message.messageOwner.media != null ? FileLoader.getAttachFileName(message.getDocument()) : ""; if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) { f = new File(message.messageOwner.attachPath); } if (f == null || f != null && !f.exists()) { f = FileLoader.getPathToMessage(message.messageOwner); } if (f != null && f.exists()) { String realMimeType = null; try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); MimeTypeMap myMime = MimeTypeMap.getSingleton(); int idx = fileName.lastIndexOf('.'); if (idx != -1) { String ext = fileName.substring(idx + 1); realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase()); if (realMimeType == null) { realMimeType = message.getDocument().mime_type; if (realMimeType == null || realMimeType.length() == 0) { realMimeType = null; } } } if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain"); } if (realMimeType != null) { try { getParentActivity().startActivityForResult(intent, 500); } catch (Exception e) { if (Build.VERSION.SDK_INT >= 24) { intent.setDataAndType( FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "text/plain"); } else { intent.setDataAndType(Uri.fromFile(f), "text/plain"); } getParentActivity().startActivityForResult(intent, 500); } } else { getParentActivity().startActivityForResult(intent, 500); } } catch (Exception e) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null); builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.getDocument().mime_type)); showDialog(builder.create()); } } } else if (!cell.isLoading()) { FileLoader.getInstance().loadFile(cell.getMessage().getDocument(), false, false); cell.updateFileExistIcon(); } else { FileLoader.getInstance().cancelLoadFile(cell.getMessage().getDocument()); cell.updateFileExistIcon(); } } } else if (selectedMode == 3) { try { TLRPC.WebPage webPage = message.messageOwner.media.webpage; String link = null; if (webPage != null && !(webPage instanceof TLRPC.TL_webPageEmpty)) { if (Build.VERSION.SDK_INT >= 16 && webPage.embed_url != null && webPage.embed_url.length() != 0) { openWebView(webPage); return; } else { link = webPage.url; } } if (link == null) { link = ((SharedLinkCell) view).getLink(0); } if (link != null) { Browser.openUrl(getParentActivity(), link); } } catch (Exception e) { FileLog.e("tmessages", e); } } } }