Example usage for android.app Activity RESULT_OK

List of usage examples for android.app Activity RESULT_OK

Introduction

In this page you can find the example usage for android.app Activity RESULT_OK.

Prototype

int RESULT_OK

To view the source code for android.app Activity RESULT_OK.

Click Source Link

Document

Standard activity result: operation succeeded.

Usage

From source file:com.ichi2.anki2.DeckPicker.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    mDontSaveOnStop = false;/*from w ww .j  a v a  2 s  .  com*/
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (!AnkiDroidApp.getLanguage().equals(newLanguage)) {
            AnkiDroidApp.setLanguage(newLanguage);
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

From source file:com.nit.vicky.DeckPicker.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    mDontSaveOnStop = false;//from  w w  w . ja  v  a 2  s . com
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
        addNote();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

From source file:com.hichinaschool.flashcards.anki.DeckPicker.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    mDontSaveOnStop = false;/*from   w  ww . j a  v  a 2  s.c  o m*/
    if (resultCode == RESULT_MEDIA_EJECTED) {
        showDialog(DIALOG_SD_CARD_NOT_MOUNTED);
        return;
    } else if (resultCode == RESULT_DB_ERROR) {
        handleDbError();
        return;
    }
    if (requestCode == SHOW_STUDYOPTIONS && resultCode == RESULT_OK) {
        loadCounts();
    } else if (requestCode == ADD_NOTE && resultCode != RESULT_CANCELED) {
        loadCounts();
    } else if (requestCode == BROWSE_CARDS
            && (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED)) {
        loadCounts();
    } else if (requestCode == ADD_CRAM_DECK) {
        // TODO: check, if ok has been clicked
        loadCounts();
    } else if (requestCode == REPORT_ERROR) {
        showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 4);
    } else if (requestCode == SHOW_INFO_UPGRADE_DECKS) {
        if (intent != null && intent.hasExtra(Info.TYPE_UPGRADE_STAGE)) {
            int type = intent.getIntExtra(Info.TYPE_UPGRADE_STAGE, Info.UPGRADE_SCREEN_BASIC1);
            if (type == Info.UPGRADE_CONTINUE) {
                showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()), 3);
            } else {
                showUpgradeScreen(true, type, !intent.hasExtra(Info.TYPE_ANIMATION_RIGHT));
            }
        } else {
            if (resultCode == RESULT_OK) {
                if (mOpenCollectionDialog != null && mOpenCollectionDialog.isShowing()) {
                    mOpenCollectionDialog.dismiss();
                }
                if (AnkiDroidApp.colIsOpen()) {
                    AnkiDroidApp.closeCollection(true);
                }
                AnkiDroidApp.openCollection(AnkiDroidApp.getCollectionPath());
                loadCounts();
            } else {
                finishWithAnimation();
            }
        }
    } else if (requestCode == SHOW_INFO_WELCOME || requestCode == SHOW_INFO_NEW_VERSION) {
        if (resultCode == RESULT_OK) {
            showStartupScreensAndDialogs(AnkiDroidApp.getSharedPrefs(getBaseContext()),
                    requestCode == SHOW_INFO_WELCOME ? 1 : 2);
        } else {
            finishWithAnimation();
        }
    } else if (requestCode == PREFERENCES_UPDATE) {
        String oldPath = mPrefDeckPath;
        SharedPreferences pref = restorePreferences();
        String newLanguage = pref.getString("language", "");
        if (AnkiDroidApp.setLanguage(newLanguage)) {
            mInvalidateMenu = true;
        }
        if (mNotMountedDialog != null && mNotMountedDialog.isShowing()
                && pref.getBoolean("internalMemory", false)) {
            showStartupScreensAndDialogs(pref, 0);
        } else if (!mPrefDeckPath.equals(oldPath)) {
            loadCollection();
        }
        // if (resultCode == StudyOptions.RESULT_RESTART) {
        // setResult(StudyOptions.RESULT_RESTART);
        // finishWithAnimation();
        // } else {
        // SharedPreferences preferences = PrefSettings.getSharedPrefs(getBaseContext());
        // BackupManager.initBackup();
        // if (!mPrefDeckPath.equals(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory())) ||
        // mPrefDeckOrder != Integer.parseInt(preferences.getString("deckOrder", "0"))) {
        // // populateDeckList(preferences.getString("deckPath", AnkiDroidApp.getStorageDirectory()));
        // }
        // }
    } else if (requestCode == REPORT_FEEDBACK && resultCode == RESULT_OK) {
    } else if (requestCode == LOG_IN_FOR_SYNC && resultCode == RESULT_OK) {
        sync();
    } else if (requestCode == LOG_IN_FOR_SHARED_DECK && resultCode == RESULT_OK) {
        addSharedDeck();
    } else if (requestCode == ADD_SHARED_DECKS) {
        if (intent != null) {
            mImportPath = intent.getStringExtra("importPath");
        }
        if (AnkiDroidApp.colIsOpen() && mImportPath != null) {
            DeckTask.launchDeckTask(DeckTask.TASK_TYPE_IMPORT, mImportAddListener,
                    new TaskData(AnkiDroidApp.getCol(), mImportPath, true));
            mImportPath = null;
        }
    } else if (requestCode == REQUEST_REVIEW) {
        // Log.i(AnkiDroidApp.TAG, "Result code = " + resultCode);
        switch (resultCode) {
        default:
            // do not reload counts, if activity is created anew because it has been before destroyed by android
            loadCounts();
            break;
        case Reviewer.RESULT_NO_MORE_CARDS:
            mDontSaveOnStop = true;
            Intent i = new Intent();
            i.setClass(this, StudyOptionsActivity.class);
            i.putExtra("onlyFnsMsg", true);
            startActivityForResult(i, SHOW_STUDYOPTIONS);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(this, ActivityTransitionAnimation.RIGHT);
            }
            break;
        }

    }

    // workaround for hidden dialog on return
    BroadcastMessages.showDialog();
}

From source file:com.rfo.basic.Run.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_CONNECT_DEVICE_SECURE:
        // When DeviceListActivity returns with a device to connect
        if ((resultCode == Activity.RESULT_OK) && (mInterpreter != null)) {
            mInterpreter.connectDevice(data, bt_Secure);
        }//w  ww  .  j  av a 2  s . c o  m
        break;
    case REQUEST_CONNECT_DEVICE_INSECURE:
        // When DeviceListActivity returns with a device to connect
        if ((resultCode == Activity.RESULT_OK) && (mInterpreter != null)) {
            mInterpreter.connectDevice(data, false);
        }
        break;
    case REQUEST_ENABLE_BT:
        // When the request to enable Bluetooth returns
        if (resultCode == Activity.RESULT_OK) {
            // Bluetooth is now enabled, so set up a chat session
            bt_enabled = 1;
        } else {
            bt_enabled = -1;
        }
        break;
    case VOICE_RECOGNITION_REQUEST_CODE:
        if (resultCode == RESULT_OK) {
            sttResults = new ArrayList<String>();
            sttResults = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        }
        sttDone = true;
        break;
    }
}

From source file:com.if3games.chessonline.DroidFish.java

private void handleSelectPlayersResult(int response, Intent data, int variant) {
    if (response != Activity.RESULT_OK) {
        //Log.w(TAG, "*** select players UI cancelled, " + response);
        switchToMainScreen();/*from  w  ww. j ava2 s.co m*/
        return;
    }

    Log.d(TAG, "Select players UI succeeded.");

    // get the invitee list
    final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
    //Log.d(TAG, "Invitee count: " + invitees.size());

    // get the automatch criteria
    Bundle autoMatchCriteria = null;
    int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
    int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
    if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
        autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        //Log.d(TAG, "Automatch criteria: " + autoMatchCriteria);
    }

    // create the room
    Log.d(TAG, "Creating room...");
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
    rtmConfigBuilder.addPlayersToInvite(invitees);
    rtmConfigBuilder.setMessageReceivedListener(this);
    rtmConfigBuilder.setRoomStatusUpdateListener(this);
    if (autoMatchCriteria != null) {
        rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
    }
    rtmConfigBuilder.setVariant(variant);
    switchToScreen(R.id.screen_wait);
    keepScreenOn();
    resetGameVars();
    resetGameBoolVars();
    Games.RealTimeMultiplayer.create(getApiClient(), rtmConfigBuilder.build());
    Log.d(TAG, "Room created, waiting for it to be ready...");
}

From source file:com.if3games.chessonline.DroidFish.java

private void handleInvitationInboxResult(int response, Intent data) {
    if (response != Activity.RESULT_OK) {
        Log.w(TAG, "*** invitation inbox UI cancelled, " + response);
        switchToMainScreen();//from  www.  jav  a 2  s .  c  o  m
        return;
    }

    Log.d(TAG, "Invitation inbox UI succeeded.");
    Invitation inv = data.getExtras().getParcelable(Multiplayer.EXTRA_INVITATION);

    // accept invitation
    acceptInviteToRoom(inv.getInvitationId());
}

From source file:me.ububble.speakall.fragment.ConversationChatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.gc();//from   ww  w  .j a v  a  2 s  .c  o  m
    if (requestCode == 18 && resultCode == Activity.RESULT_OK && null != data) {
        final ProgressDialog dialogLoader = ProgressDialog.show(activity, "",
                Finder.STRING.CONTACT_PROGRESS.toString(), true);
        Uri selectedVideo = data.getData();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };
        final Cursor cursor = activity.getContentResolver().query(selectedVideo, filePathColumn, null, null,
                null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        final String videoPath = cursor.getString(columnIndex);
        cursor.close();
        System.gc();
        final File fileVideo = new File(videoPath);
        Calendar fecha = Calendar.getInstance();
        final long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Video/Sent");
        pathImage.mkdirs();
        final File file = new File(pathImage, +fechaInMillis + ".mp4");
        cursor.close();
        //runTranscodingUsingLoader(fileVideo.getAbsolutePath(), file.getAbsolutePath());
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap thumbnailVideo = ThumbnailUtils.createVideoThumbnail(videoPath,
                        MediaStore.Video.Thumbnails.MICRO_KIND);
                Bitmap toUpload = scaleDownLargeImageWithAspectRatio(thumbnailVideo, 1280);
                Bitmap binaryData = toUpload;
                Bitmap binaryData2 = BlurImage(toUpload);
                try {
                    FileInputStream inStream = new FileInputStream(fileVideo);
                    FileOutputStream outStream = new FileOutputStream(file);

                    byte[] buffer = new byte[1024];

                    int length;
                    //copy the file content in bytes
                    while ((length = inStream.read(buffer)) > 0) {

                        outStream.write(buffer, 0, length);

                    }

                    inStream.close();
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                final Message msjVideo = new Message();
                try {
                    String id = u.id + contact.idContacto + fechaInMillis + Settings.Secure
                            .getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);

                    msjVideo.mensajeId = id;
                    msjVideo.emisor = u.id;
                    msjVideo.receptor = contact.idContacto;
                    msjVideo.emisorEmail = u.email;
                    msjVideo.receptorEmail = contact.email;
                    msjVideo.emisorLang = u.lang;
                    msjVideo.receptorLang = contact.lang;
                    msjVideo.emitedAt = fechaInMillis;
                    msjVideo.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_VIDEO));
                    if (tiempoMensaje)
                        msjVideo.delay = temporizadorSeek.getValue();
                    else
                        msjVideo.delay = 0;
                    msjVideo.videoName = file.getAbsolutePath();

                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                    byte[] byteArray = stream.toByteArray();
                    msjVideo.photo = byteArray;

                    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                    binaryData2.compress(Bitmap.CompressFormat.JPEG, 60, stream2);
                    byte[] byteArray2 = stream2.toByteArray();
                    msjVideo.photoBlur = byteArray2;
                    if (SpeakSocket.mSocket != null)
                        if (SpeakSocket.mSocket.connected()) {
                            msjVideo.status = 1;
                        } else {
                            msjVideo.status = -1;
                        }
                    msjVideo.fileUploaded = false;
                    msjVideo.save();

                    Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjVideo.receptor)
                            .executeSingle();
                    if (chat == null) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjVideo.receptor).executeSingle();
                        Chats newChat = new Chats();
                        newChat.mensajeId = msjVideo.mensajeId;
                        newChat.idContacto = msjVideo.receptor;
                        newChat.isLockedConversation = false;
                        newChat.lastStatus = msjVideo.status;
                        newChat.email = msjVideo.receptorEmail;
                        if (contact != null) {
                            newChat.photo = contact.photo;
                            newChat.fullName = contact.fullName;
                            newChat.lang = contact.lang;
                            newChat.screenName = contact.screenName;
                            newChat.photoload = true;
                            newChat.phone = contact.phone;
                        } else {
                            newChat.photo = null;
                            newChat.photoload = false;
                            newChat.fullName = msjVideo.receptorEmail;
                            newChat.lang = msjVideo.receptorLang;
                            newChat.screenName = msjVideo.receptorEmail;
                            newChat.phone = null;
                        }
                        newChat.emitedAt = msjVideo.emitedAt;
                        newChat.notRead = 0;
                        newChat.lastMessage = "send Video";
                        newChat.show = true;
                        newChat.save();
                    } else {
                        if (!chat.photoload) {
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", msjVideo.emisor).executeSingle();
                            if (contact != null) {
                                chat.photo = contact.photo;
                                chat.photoload = true;
                            } else {
                                chat.photo = null;
                                chat.photoload = false;
                            }
                        }
                        chat.mensajeId = msjVideo.mensajeId;
                        chat.lastStatus = msjVideo.status;
                        chat.emitedAt = msjVideo.emitedAt;
                        chat.notRead = 0;
                        chat.lastMessage = "send Video";
                        chat.save();
                    }
                    showNewMessage(msjVideo);
                    dialogLoader.dismiss();
                } catch (Exception e) {
                }
                System.gc();
            }
        }).start();

    }

    if (requestCode == 45) {
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
    }

    if (requestCode == 34) {
        if (resultCode == activity.RESULT_OK) {
            Uri contactUri = data.getData();
            try {
                //contactPic.setImageBitmap(getPhoto(contactUri));
                JSONObject contacto = new JSONObject();
                contacto.put("nombre", getName(contactUri));
                contacto.put("telefono", getPhone(contactUri));
                Message msjNew = new Message();
                Calendar fecha = Calendar.getInstance();
                String id = u.id + contact.idContacto + fecha.getTimeInMillis()
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjNew.translation = true;
                msjNew.mensajeId = id;
                msjNew.emisor = u.id;
                msjNew.receptor = contact.idContacto;
                msjNew.mensaje = contacto.toString();
                msjNew.emisorEmail = u.email;
                msjNew.receptorEmail = contact.email;
                msjNew.emisorLang = u.lang;
                msjNew.receptorLang = contact.lang;
                msjNew.emitedAt = fecha.getTimeInMillis();
                msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_CONTACT));
                msjNew.delay = 0;
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        msjNew.status = 1;
                    } else {
                        msjNew.status = -1;
                    }
                msjNew.save();
                Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjNew.receptor)
                        .executeSingle();
                if (chat == null) {
                    Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjNew.receptor)
                            .executeSingle();
                    Chats newChat = new Chats();
                    newChat.mensajeId = msjNew.mensajeId;
                    newChat.idContacto = msjNew.receptor;
                    newChat.isLockedConversation = false;
                    newChat.lastStatus = msjNew.status;
                    newChat.email = msjNew.receptorEmail;
                    if (contact != null) {
                        newChat.photo = contact.photo;
                        newChat.fullName = contact.fullName;
                        newChat.lang = contact.lang;
                        newChat.screenName = contact.screenName;
                        newChat.photoload = true;
                        newChat.phone = contact.phone;
                    } else {
                        newChat.photo = null;
                        newChat.photoload = false;
                        newChat.fullName = msjNew.receptorEmail;
                        newChat.lang = msjNew.receptorLang;
                        newChat.screenName = msjNew.receptorEmail;
                        newChat.phone = null;
                    }
                    newChat.emitedAt = msjNew.emitedAt;
                    newChat.notRead = 0;
                    newChat.lastMessage = "send Contact";
                    newChat.show = true;
                    newChat.save();
                } else {
                    if (!chat.photoload) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjNew.emisor).executeSingle();
                        if (contact != null) {
                            chat.photo = contact.photo;
                            chat.photoload = true;
                        } else {
                            chat.photo = null;
                            chat.photoload = false;
                        }
                    }
                    chat.mensajeId = msjNew.mensajeId;
                    chat.lastStatus = msjNew.status;
                    chat.emitedAt = msjNew.emitedAt;
                    chat.notRead = 0;
                    chat.lastMessage = "send Contact";
                    chat.save();
                }
                showNewMessage(msjNew);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        System.gc();
    }
    if (requestCode == 1 && null != data) {
        Uri selectedImage = data.getData();
        InputStream imageStream = null;
        try {
            imageStream = activity.getContentResolver().openInputStream(selectedImage);
        } catch (FileNotFoundException e) {
        }
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        Bitmap bitmapRotate = C.rotateBitmapAndScale(picturePath);
        cursor.close();
        System.gc();
        Calendar fecha = Calendar.getInstance();
        long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        pathImage.mkdirs();
        Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
        System.gc();
        Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
        System.gc();
        Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
        System.gc();
        File file = new File(pathImage, +fechaInMillis + ".png");
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
            outputStream.flush();
            outputStream.close();
            System.gc();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            final Message msjPhoto = new Message();
            String id = u.id + contact.idContacto + fechaInMillis
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msjPhoto.mensajeId = id;
            msjPhoto.emisor = u.id;
            msjPhoto.receptor = contact.idContacto;
            msjPhoto.emisorEmail = u.email;
            msjPhoto.receptorEmail = contact.email;
            msjPhoto.emisorLang = u.lang;
            msjPhoto.receptorLang = contact.lang;
            msjPhoto.emitedAt = fechaInMillis;
            msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_PHOTO));
            if (tiempoMensaje)
                msjPhoto.delay = temporizadorSeek.getValue();
            else
                msjPhoto.delay = 0;
            msjPhoto.photoName = file.getAbsolutePath();

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
            byte[] byteArray = stream.toByteArray();
            msjPhoto.photo = byteArray;

            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
            byte[] byteArray2 = stream2.toByteArray();
            msjPhoto.photoBlur = byteArray2;
            if (SpeakSocket.mSocket != null)
                if (SpeakSocket.mSocket.connected()) {
                    msjPhoto.status = 1;
                } else {
                    msjPhoto.status = -1;
                }
            msjPhoto.fileUploaded = false;
            msjPhoto.save();
            Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjPhoto.receptor)
                    .executeSingle();
            if (chat == null) {
                Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjPhoto.receptor)
                        .executeSingle();
                Chats newChat = new Chats();
                newChat.mensajeId = msjPhoto.mensajeId;
                newChat.idContacto = msjPhoto.receptor;
                newChat.isLockedConversation = false;
                newChat.lastStatus = msjPhoto.status;
                newChat.email = msjPhoto.receptorEmail;
                if (contact != null) {
                    newChat.photo = contact.photo;
                    newChat.fullName = contact.fullName;
                    newChat.lang = contact.lang;
                    newChat.screenName = contact.screenName;
                    newChat.photoload = true;
                    newChat.phone = contact.phone;
                } else {
                    newChat.photo = null;
                    newChat.photoload = false;
                    newChat.fullName = msjPhoto.receptorEmail;
                    newChat.lang = msjPhoto.receptorLang;
                    newChat.screenName = msjPhoto.receptorEmail;
                    newChat.phone = null;
                }
                newChat.emitedAt = msjPhoto.emitedAt;
                newChat.notRead = 0;
                newChat.lastMessage = "send Image";
                newChat.show = true;
                newChat.save();
            } else {
                if (!chat.photoload) {
                    Contact contact = new Select().from(Contact.class).where("id_contact = ?", msjPhoto.emisor)
                            .executeSingle();
                    if (contact != null) {
                        chat.photo = contact.photo;
                        chat.photoload = true;
                    } else {
                        chat.photo = null;
                        chat.photoload = false;
                    }
                }
                chat.mensajeId = msjPhoto.mensajeId;
                chat.lastStatus = msjPhoto.status;
                chat.emitedAt = msjPhoto.emitedAt;
                chat.notRead = 0;
                chat.lastMessage = "send Image";
                chat.save();
            }
            showNewMessage(msjPhoto);

        } catch (Exception e) {
        }
        System.gc();
    }
    if (requestCode == 23) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmapRotate = C
                    .rotateBitmapAndScale(Environment.getExternalStorageDirectory().getAbsolutePath()
                            + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            System.gc();
            Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
            System.gc();
            Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
            System.gc();
            Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
            System.gc();
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(file);
                toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
                outputStream.flush();
                outputStream.close();
                System.gc();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                final Message msjPhoto = new Message();
                String id = u.id + contact.idContacto + dateToCamera
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjPhoto.mensajeId = id;
                msjPhoto.emisor = u.id;
                msjPhoto.receptor = contact.idContacto;
                msjPhoto.emisorEmail = u.email;
                msjPhoto.receptorEmail = contact.email;
                msjPhoto.emisorLang = u.lang;
                msjPhoto.receptorLang = contact.lang;
                msjPhoto.emitedAt = dateToCamera;
                msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_PHOTO));
                if (tiempoMensaje)
                    msjPhoto.delay = temporizadorSeek.getValue();
                else
                    msjPhoto.delay = 0;
                msjPhoto.photoName = file.getAbsolutePath();

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                byte[] byteArray = stream.toByteArray();
                msjPhoto.photo = byteArray;

                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
                byte[] byteArray2 = stream2.toByteArray();
                msjPhoto.photoBlur = byteArray2;
                if (SpeakSocket.mSocket != null)
                    if (SpeakSocket.mSocket.connected()) {
                        msjPhoto.status = 1;
                    } else {
                        msjPhoto.status = -1;
                    }
                msjPhoto.fileUploaded = false;
                msjPhoto.save();
                Chats chat = new Select().from(Chats.class).where("idContacto = ?", msjPhoto.receptor)
                        .executeSingle();
                if (chat == null) {
                    Contact contact = new Select().from(Contact.class)
                            .where("id_contact = ?", msjPhoto.receptor).executeSingle();
                    Chats newChat = new Chats();
                    newChat.mensajeId = msjPhoto.mensajeId;
                    newChat.idContacto = msjPhoto.receptor;
                    newChat.isLockedConversation = false;
                    newChat.lastStatus = msjPhoto.status;
                    newChat.email = msjPhoto.receptorEmail;
                    if (contact != null) {
                        newChat.photo = contact.photo;
                        newChat.fullName = contact.fullName;
                        newChat.lang = contact.lang;
                        newChat.screenName = contact.screenName;
                        newChat.photoload = true;
                        newChat.phone = contact.phone;
                    } else {
                        newChat.photo = null;
                        newChat.photoload = false;
                        newChat.fullName = msjPhoto.receptorEmail;
                        newChat.lang = msjPhoto.receptorLang;
                        newChat.screenName = msjPhoto.receptorEmail;
                        newChat.phone = null;
                    }
                    newChat.emitedAt = msjPhoto.emitedAt;
                    newChat.notRead = 0;
                    newChat.lastMessage = "send Image";
                    newChat.show = true;
                    newChat.save();
                } else {
                    if (!chat.photoload) {
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", msjPhoto.emisor).executeSingle();
                        if (contact != null) {
                            chat.photo = contact.photo;
                            chat.photoload = true;
                        } else {
                            chat.photo = null;
                            chat.photoload = false;
                        }
                    }
                    chat.mensajeId = msjPhoto.mensajeId;
                    chat.lastStatus = msjPhoto.status;
                    chat.emitedAt = msjPhoto.emitedAt;
                    chat.notRead = 0;
                    chat.lastMessage = "send Image";
                    chat.save();
                }
                showNewMessage(msjPhoto);
            } catch (Exception e) {
            }
            System.gc();
        }
    }
}

From source file:me.ububble.speakall.fragment.ConversationGroupFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    System.gc();//  w w  w . j av a  2 s.c o  m
    if (requestCode == 34) {
        if (resultCode == activity.RESULT_OK) {
            Uri contactUri = data.getData();
            try {
                //contactPic.setImageBitmap(getPhoto(contactUri));
                JSONObject contactoSend = new JSONObject();
                contactoSend.put("nombre", getName(contactUri));
                contactoSend.put("telefono", getPhone(contactUri));
                MsgGroups msjNew = new MsgGroups();
                Calendar fecha = Calendar.getInstance();
                JSONArray targets = new JSONArray();
                JSONArray contactos = new JSONArray(grupo.targets);
                String contactosId = null;
                if (SpeakSocket.mSocket != null) {
                    if (SpeakSocket.mSocket.connected()) {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", 1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    } else {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", -1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    }
                }
                msjNew.grupoId = grupo.grupoId;
                msjNew.mensajeId = u.id + grupo.grupoId + fecha.getTimeInMillis()
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjNew.emisor = u.id;
                msjNew.receptores = targets.toString();
                msjNew.mensaje = contactoSend.toString();
                msjNew.emisorEmail = u.email;
                msjNew.emisorLang = u.lang;
                msjNew.translation = false;
                msjNew.emitedAt = fecha.getTimeInMillis();
                msjNew.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_CONTACT));
                msjNew.delay = 0;
                msjNew.save();
                showNewMessage(msjNew);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        System.gc();
    }

    if (requestCode == 1 && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
        Bitmap bitmapRotate = C.rotateBitmapAndScale(picturePath);
        cursor.close();
        System.gc();
        Calendar fecha = Calendar.getInstance();
        long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Image/Sent");
        pathImage.mkdirs();
        Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
        System.gc();
        Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
        System.gc();
        Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
        System.gc();
        File file = new File(pathImage, +fechaInMillis + ".png");
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
            outputStream.flush();
            outputStream.close();
            System.gc();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            final MsgGroups msjPhoto = new MsgGroups();
            JSONArray targets = new JSONArray();
            JSONArray contactos = new JSONArray(grupo.targets);
            String contactosId = null;
            if (SpeakSocket.mSocket != null) {
                if (SpeakSocket.mSocket.connected()) {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", 1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                } else {
                    for (int i = 0; i < contactos.length(); i++) {
                        JSONObject contacto = contactos.getJSONObject(i);
                        JSONObject newContact = new JSONObject();
                        Contact contact = new Select().from(Contact.class)
                                .where("id_contact = ?", contacto.getString("name")).executeSingle();
                        if (contact != null) {
                            if (!contact.idContacto.equals(u.id)) {
                                if (translate)
                                    newContact.put("lang", contact.lang);
                                else
                                    newContact.put("lang", u.lang);
                                newContact.put("name", contact.idContacto);
                                newContact.put("screen_name", contact.screenName);
                                newContact.put("status", -1);
                                contactosId += contact.idContacto;
                                targets.put(targets.length(), newContact);
                            }
                        }
                    }
                }
            }
            msjPhoto.grupoId = grupo.grupoId;
            msjPhoto.mensajeId = u.id + grupo.grupoId + fechaInMillis
                    + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
            msjPhoto.emisor = u.id;
            msjPhoto.receptores = targets.toString();
            msjPhoto.mensaje = "send Image";
            msjPhoto.emisorEmail = u.email;
            msjPhoto.emisorLang = u.lang;
            msjPhoto.translation = false;
            msjPhoto.emitedAt = fechaInMillis;
            msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO));
            msjPhoto.delay = 0;
            msjPhoto.photoName = file.getAbsolutePath();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
            byte[] byteArray = stream.toByteArray();
            msjPhoto.photo = byteArray;

            ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
            binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
            byte[] byteArray2 = stream2.toByteArray();
            msjPhoto.photoBlur = byteArray2;
            msjPhoto.fileUploaded = false;
            msjPhoto.save();
            showNewMessage(msjPhoto);
        } catch (Exception e) {
        }
        System.gc();
    }

    if (requestCode == 23) {
        if (resultCode == Activity.RESULT_OK) {
            Bitmap bitmapRotate = C
                    .rotateBitmapAndScale(Environment.getExternalStorageDirectory().getAbsolutePath()
                            + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            System.gc();
            Bitmap toUpload = scaleDownLargeImageWithAspectRatio(bitmapRotate, 1280);
            System.gc();
            Bitmap binaryData = scaleDownLargeImageWithAspectRatio(toUpload, 500);
            System.gc();
            Bitmap binaryData2 = BlurImage(scaleDownLargeImageWithAspectRatio(toUpload, 400));
            System.gc();
            File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
                    + "/SpeakOn/Image/Sent/" + dateToCamera + ".png");
            OutputStream outputStream = null;
            try {
                outputStream = new FileOutputStream(file);
                toUpload.compress(Bitmap.CompressFormat.JPEG, 60, outputStream);
                outputStream.flush();
                outputStream.close();
                System.gc();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                final MsgGroups msjPhoto = new MsgGroups();
                JSONArray targets = new JSONArray();
                JSONArray contactos = new JSONArray(grupo.targets);
                String contactosId = null;
                if (SpeakSocket.mSocket != null) {
                    if (SpeakSocket.mSocket.connected()) {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", 1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    } else {
                        for (int i = 0; i < contactos.length(); i++) {
                            JSONObject contacto = contactos.getJSONObject(i);
                            JSONObject newContact = new JSONObject();
                            Contact contact = new Select().from(Contact.class)
                                    .where("id_contact = ?", contacto.getString("name")).executeSingle();
                            if (contact != null) {
                                if (!contact.idContacto.equals(u.id)) {
                                    if (translate)
                                        newContact.put("lang", contact.lang);
                                    else
                                        newContact.put("lang", u.lang);
                                    newContact.put("name", contact.idContacto);
                                    newContact.put("screen_name", contact.screenName);
                                    newContact.put("status", -1);
                                    contactosId += contact.idContacto;
                                    targets.put(targets.length(), newContact);
                                }
                            }
                        }
                    }
                }
                msjPhoto.grupoId = grupo.grupoId;
                msjPhoto.mensajeId = u.id + grupo.grupoId + dateToCamera
                        + Settings.Secure.getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                msjPhoto.emisor = u.id;
                msjPhoto.receptores = targets.toString();
                msjPhoto.mensaje = "send Image";
                msjPhoto.emisorEmail = u.email;
                msjPhoto.emisorLang = u.lang;
                msjPhoto.translation = false;
                msjPhoto.emitedAt = dateToCamera;
                msjPhoto.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_PHOTO));
                msjPhoto.delay = 0;
                msjPhoto.photoName = file.getAbsolutePath();
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                byte[] byteArray = stream.toByteArray();
                msjPhoto.photo = byteArray;

                ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                binaryData2.compress(Bitmap.CompressFormat.JPEG, 40, stream2);
                byte[] byteArray2 = stream2.toByteArray();
                msjPhoto.photoBlur = byteArray2;
                msjPhoto.fileUploaded = false;
                msjPhoto.save();
                showNewMessage(msjPhoto);
            } catch (Exception e) {
            }
            System.gc();
        }
    }

    System.gc();
    if (requestCode == 18 && resultCode == Activity.RESULT_OK && null != data) {
        final ProgressDialog dialogLoader = ProgressDialog.show(activity, "",
                Finder.STRING.CONTACT_PROGRESS.toString(), true);
        Uri selectedVideo = data.getData();
        String[] filePathColumn = { MediaStore.Video.Media.DATA };
        final Cursor cursor = activity.getContentResolver().query(selectedVideo, filePathColumn, null, null,
                null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        final String videoPath = cursor.getString(columnIndex);
        cursor.close();
        System.gc();
        final File fileVideo = new File(videoPath);
        Calendar fecha = Calendar.getInstance();
        final long fechaInMillis = fecha.getTimeInMillis();
        File pathImage = new File(
                Environment.getExternalStorageDirectory().getAbsolutePath() + "/SpeakOn/Video/Sent");
        pathImage.mkdirs();
        final File file = new File(pathImage, +fechaInMillis + ".mp4");
        cursor.close();
        //runTranscodingUsingLoader(fileVideo.getAbsolutePath(), file.getAbsolutePath());
        new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap thumbnailVideo = ThumbnailUtils.createVideoThumbnail(videoPath,
                        MediaStore.Video.Thumbnails.MICRO_KIND);
                Bitmap toUpload = scaleDownLargeImageWithAspectRatio(thumbnailVideo, 1280);
                Bitmap binaryData = toUpload;
                Bitmap binaryData2 = BlurImage(toUpload);
                try {
                    FileInputStream inStream = new FileInputStream(fileVideo);
                    FileOutputStream outStream = new FileOutputStream(file);

                    byte[] buffer = new byte[1024];

                    int length;
                    //copy the file content in bytes
                    while ((length = inStream.read(buffer)) > 0) {

                        outStream.write(buffer, 0, length);

                    }

                    inStream.close();
                    outStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                try {
                    final MsgGroups msjVideo = new MsgGroups();
                    JSONArray targets = new JSONArray();
                    JSONArray contactos = new JSONArray(grupo.targets);
                    String contactosId = null;
                    if (SpeakSocket.mSocket != null) {
                        if (SpeakSocket.mSocket.connected()) {
                            for (int i = 0; i < contactos.length(); i++) {
                                JSONObject contacto = contactos.getJSONObject(i);
                                JSONObject newContact = new JSONObject();
                                Contact contact = new Select().from(Contact.class)
                                        .where("id_contact = ?", contacto.getString("name")).executeSingle();
                                if (contact != null) {
                                    if (!contact.idContacto.equals(u.id)) {
                                        if (translate)
                                            newContact.put("lang", contact.lang);
                                        else
                                            newContact.put("lang", u.lang);
                                        newContact.put("name", contact.idContacto);
                                        newContact.put("screen_name", contact.screenName);
                                        newContact.put("status", 1);
                                        contactosId += contact.idContacto;
                                        targets.put(targets.length(), newContact);
                                    }
                                }
                            }
                        } else {
                            for (int i = 0; i < contactos.length(); i++) {
                                JSONObject contacto = contactos.getJSONObject(i);
                                JSONObject newContact = new JSONObject();
                                Contact contact = new Select().from(Contact.class)
                                        .where("id_contact = ?", contacto.getString("name")).executeSingle();
                                if (contact != null) {
                                    if (!contact.idContacto.equals(u.id)) {
                                        if (translate)
                                            newContact.put("lang", contact.lang);
                                        else
                                            newContact.put("lang", u.lang);
                                        newContact.put("name", contact.idContacto);
                                        newContact.put("screen_name", contact.screenName);
                                        newContact.put("status", -1);
                                        contactosId += contact.idContacto;
                                        targets.put(targets.length(), newContact);
                                    }
                                }
                            }
                        }
                    }
                    msjVideo.grupoId = grupo.grupoId;
                    msjVideo.mensajeId = u.id + grupo.grupoId + fechaInMillis + Settings.Secure
                            .getString(activity.getContentResolver(), Settings.Secure.ANDROID_ID);
                    msjVideo.emisor = u.id;
                    msjVideo.receptores = targets.toString();
                    msjVideo.mensaje = "send Video";
                    msjVideo.emisorEmail = u.email;
                    msjVideo.emisorLang = u.lang;
                    msjVideo.translation = false;
                    msjVideo.emitedAt = fechaInMillis;
                    msjVideo.tipo = Integer.parseInt(getString(R.string.MSG_TYPE_GROUP_VIDEO));
                    msjVideo.delay = 0;
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    binaryData.compress(Bitmap.CompressFormat.JPEG, 60, stream);
                    byte[] byteArray = stream.toByteArray();
                    msjVideo.photo = byteArray;
                    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                    binaryData2.compress(Bitmap.CompressFormat.JPEG, 60, stream2);
                    byte[] byteArray2 = stream2.toByteArray();
                    msjVideo.photoBlur = byteArray2;
                    msjVideo.fileUploaded = false;
                    msjVideo.videoName = file.getAbsolutePath();
                    msjVideo.save();
                    showNewMessage(msjVideo);
                    dialogLoader.dismiss();
                } catch (Exception e) {
                }
                System.gc();
            }
        }).start();

    }

    if (requestCode == 45) {
        milocManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        List<String> allProviders = milocManager.getAllProviders();
        boolean gpsProvider = false;
        boolean netProvider = false;
        for (String providerName : allProviders) {
            if (providerName.equals(LocationManager.GPS_PROVIDER)) {
                gpsProvider = true;
            }
            if (providerName.equals(LocationManager.NETWORK_PROVIDER)) {
                netProvider = true;
            }
        }
        checkCountryLocation(gpsProvider, netProvider);
    }

}