static boolean sendFile(String remoteUri, String filePath) { final Engine engine = (Engine) Engine.getInstance(); final INgnSipService sipService = engine.getSipService(); final IScreenService screenService = engine.getScreenService(); final String validUri = NgnUriUtils.makeValidSipUri(remoteUri); if (validUri == null) { Log.e(TAG, "failed to normalize sip uri '" + remoteUri + "'"); return false; } final NgnMsrpSession msrpSession = NgnMsrpSession.createOutgoingSession( sipService.getSipStack(), NgnMediaType.FileTransfer, validUri); if (msrpSession == null) { Log.e(TAG, "Failed to create MSRP session"); return false; } if (msrpSession.sendFile(filePath)) { screenService.show(ScreenFileTransferView.class, Long.toString(msrpSession.getId())); return true; } else { Log.e(TAG, "Failed to send file"); return false; } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_filetrans_view); super.mId = getIntent().getStringExtra("id"); if (NgnStringUtils.isNullOrEmpty(super.mId)) { Log.e(TAG, "Invalid MSRP session"); finish(); return; } mSession = NgnMsrpSession.getSession(NgnStringUtils.parseLong(super.mId, -1)); if (mSession == null) { Log.e(TAG, String.format("Cannot find MSRP session with id=%s", super.mId)); finish(); return; } mSession.incRef(); mSession.setContext(this); mRelativeLayout = (RelativeLayout) findViewById(R.id.screen_filetrans_view_relativeLayout); mIvPreview = (ImageView) findViewById(R.id.screen_filetrans_view_imageView_preview); mProgressBar = (ProgressBar) findViewById(R.id.screen_filetrans_view_progressBar); mBtAccept = (Button) findViewById(R.id.screen_filetrans_view_button_accept); mBtAbort = (Button) findViewById(R.id.screen_filetrans_view_button_abort); mTvInfo = (TextView) findViewById(R.id.screen_filetrans_view_textView_info); mTvByteRange = (TextView) findViewById(R.id.screen_filetrans_view_textView_byteRange); mTvRemoteParty = (TextView) findViewById(R.id.screen_filetrans_view_textView_remoteParty); mTvFileName = (TextView) findViewById(R.id.screen_filetrans_view_textView_cname); String remoteParty = NgnUriUtils.getDisplayName(mSession.getRemotePartyUri()); if (NgnStringUtils.isNullOrEmpty(remoteParty)) { remoteParty = NgnStringUtils.nullValue(); } mTvRemoteParty.setText(remoteParty); mTvInfo.setText(mSession.isOutgoing() ? "Sending Content..." : "Receiving Content..."); mBtAccept.setVisibility( mSession.isOutgoing() || mSession.isConnected() ? View.GONE : View.VISIBLE); mBtAbort.setText( mSession.isConnected() ? "Abort" : (mSession.isOutgoing() ? "Cancel" : "Decline")); final String fileName = mSession.getFileName(); final String filePath = mSession.getFilePath(); if (!NgnStringUtils.isNullOrEmpty(fileName)) { mTvFileName.setText(fileName); } if (mSession.isOutgoing()) { mStringFormat = "%d/%d Bytes sent"; if (filePath != null) { try { mIvPreview.setImageURI(new Uri.Builder().path(filePath).build()); } catch (Exception e) { mIvPreview.setImageResource(R.drawable.document_up_128); } } } else { mStringFormat = "%d/%d Bytes received"; mIvPreview.setImageResource(R.drawable.document_down_128); } updateProgressBar(mSession.getStart(), mSession.getEnd(), mSession.getTotal()); if (mSession.isConnected()) { mRelativeLayout.setBackgroundResource(R.drawable.grad_bkg_incall); } mSipAndMsrpBroadCastRecv = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { handleSipAndMsrpEvent(intent); } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(NgnInviteEventArgs.ACTION_INVITE_EVENT); intentFilter.addAction(NgnMsrpEventArgs.ACTION_MSRP_EVENT); registerReceiver(mSipAndMsrpBroadCastRecv, intentFilter); mBtAbort.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (!mSession.hangUp()) { scheduleSuicide(); } } }); mBtAccept.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mSession.accept(); } }); }