Search in sources :

Example 1 with FileInfo

use of org.awesomeapp.messenger.util.SystemServices.FileInfo in project Zom-Android by zom.

the class ImUrlActivity method sendOtrInBand.

private void sendOtrInBand(String username, long providerId, long accountId) {
    try {
        IImConnection conn = ((ImApp) getApplication()).getConnection(providerId, accountId);
        if (conn == null)
            // can't send without a connection
            return;
        mChatSessionManager = conn.getChatSessionManager();
        IChatSession session = getChatSession(username);
        if (mSendText != null)
            session.sendMessage(mSendText, false);
        else if (mSendUri != null) {
            try {
                String offerId = UUID.randomUUID().toString();
                // Log.i(TAG, "mSendUrl " +mSendUrl);
                Uri vfsUri = null;
                if (SecureMediaStore.isVfsUri(mSendUri)) {
                    vfsUri = mSendUri;
                    boolean sent = session.offerData(offerId, vfsUri.toString(), mSendType);
                    if (sent)
                        return;
                } else {
                    InputStream is = getContentResolver().openInputStream(mSendUri);
                    String fileName = mSendUri.getLastPathSegment();
                    FileInfo importInfo = SystemServices.getFileInfoFromURI(this, mSendUri);
                    if (!TextUtils.isEmpty(importInfo.type)) {
                        if (importInfo.type.startsWith("image"))
                            vfsUri = SecureMediaStore.resizeAndImportImage(this, session.getId() + "", mSendUri, importInfo.type);
                        else
                            vfsUri = SecureMediaStore.importContent(session.getId() + "", fileName, is);
                        boolean sent = session.offerData(offerId, vfsUri.toString(), importInfo.type);
                        if (sent)
                            return;
                    }
                }
            } catch (Exception e) {
                Log.e(TAG, "error sending external file", e);
            }
            Toast.makeText(this, R.string.unable_to_securely_share_this_file, Toast.LENGTH_LONG).show();
        }
    } catch (RemoteException e) {
        Log.e(TAG, "Error sending data", e);
    }
}
Also used : IImConnection(org.awesomeapp.messenger.service.IImConnection) FileInfo(org.awesomeapp.messenger.util.SystemServices.FileInfo) InputStream(java.io.InputStream) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) Uri(android.net.Uri) RemoteException(android.os.RemoteException)

Aggregations

Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1 InputStream (java.io.InputStream)1 IChatSession (org.awesomeapp.messenger.service.IChatSession)1 IImConnection (org.awesomeapp.messenger.service.IImConnection)1 FileInfo (org.awesomeapp.messenger.util.SystemServices.FileInfo)1