Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

In this page you can find the example usage for android.content Intent getIntExtra.

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:fr.univsavoie.ltp.client.MainActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Le code de requte est utilis pour identifier lactivit enfant
    switch (requestCode) {
    // Cas si authentification
    case 1:/* w  ww.j a  va  2 s . co  m*/
        switch (resultCode) {
        case RESULT_OK:
            Toast.makeText(this, R.string.auth_ok, Toast.LENGTH_LONG).show();
            finish();
            startActivity(getIntent());
            return;

        case RESULT_CANCELED:
            Toast.makeText(this, R.string.auth_fail, Toast.LENGTH_LONG).show();
            return;

        case ROUTE_REQUEST:
            if (resultCode == RESULT_OK) {
                int nodeId = data.getIntExtra("NODE_ID", 0);
                map.getController().setCenter(mRoad.mNodes.get(nodeId).mLocation);
                roadNodeMarkers.showBubbleOnItem(nodeId, map);
            }
            break;

        case POIS_REQUEST:
            if (resultCode == RESULT_OK) {
                int id = data.getIntExtra("ID", 0);
                map.getController().setCenter(mPOIs.get(id).mLocation);
                poiMarkers.showBubbleOnItem(id, map);
            }
            break;

        default:
            // Faire quelque chose
            return;
        }

        // Cas si paramtres utilisateur
    case 2:
        switch (resultCode) {
        case RESULT_OK:
            // On relance l'activit car on doit rafraichir la map !
            finish();
            startActivity(getIntent());
            return;

        case RESULT_CANCELED:
            Toast.makeText(this, R.string.prefs_update_error, Toast.LENGTH_LONG).show();
            return;

        default:
            // Faire quelque chose
            return;
        }

        // Cas si inscription
    case 3:
        switch (resultCode) {
        case RESULT_OK:
            Toast.makeText(this, R.string.signup_ok, Toast.LENGTH_LONG).show();
            return;
        case RESULT_CANCELED:
            Toast.makeText(this, R.string.signup_fail, Toast.LENGTH_LONG).show();
            return;
        default:
            // Faire quelque chose
            return;
        }

        // Aucune activit en retour...
    default:
        // Faire quelque chose
        return;
    }
}

From source file:uk.co.senab.photoview.sample.ViewPagerActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1001) {
        int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
        final String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
        String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
        new Thread(new Runnable() {
            public void run() {
                //Thread.sleep(5*1000);
                try {
                    Bundle ownedItems = mservice.getPurchases(3, getPackageName(), "inapp", null);
                    // Check response
                    int responseCode = ownedItems.getInt("RESPONSE_CODE");
                    if (responseCode != 0) {
                        throw new Exception("Error");
                    }/*from  w w w.ja  v a 2s .  c om*/
                    // Get the list of purchased items
                    ArrayList<String> purchaseDataList = ownedItems
                            .getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                    for (String purchaseData : purchaseDataList) {
                        JSONObject o = new JSONObject(purchaseData);
                        String purchaseToken = o.optString("token", o.optString("purchaseToken"));
                        // Consume purchaseToken, handling any errors
                        mservice.consumePurchase(3, getPackageName(), purchaseToken);
                    }
                } catch (RemoteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }).start();
        if (resultCode == RESULT_OK) {
            try {
                JSONObject jo = new JSONObject(purchaseData);
                String sku = jo.getString("productId");
                new Thread(new Runnable() {
                    public void run() {
                        try {
                            Bundle ownedItems = mservice.getPurchases(3, getPackageName(), "inapp", null);
                            // Check response
                            int responseCode = ownedItems.getInt("RESPONSE_CODE");
                            if (responseCode != 0) {
                                throw new Exception("Error");
                            }
                            // Get the list of purchased items
                            ArrayList<String> purchaseDataList = ownedItems
                                    .getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                            for (String purchaseData : purchaseDataList) {
                                JSONObject o = new JSONObject(purchaseData);
                                String purchaseToken = o.optString("token", o.optString("purchaseToken"));
                                // Consume purchaseToken, handling any errors
                                mservice.consumePurchase(3, getPackageName(), purchaseToken);
                            }
                        } catch (RemoteException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }).start();

            } catch (JSONException e) {

                e.printStackTrace();
            }
        }
    }
}

From source file:com.ichi2.anki.NoteEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Timber.d("onCreate()");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.note_editor);
    Intent intent = getIntent();
    if (savedInstanceState != null) {
        mCaller = savedInstanceState.getInt("caller");
        mAddNote = savedInstanceState.getBoolean("addFact");
        mCurrentDid = savedInstanceState.getLong("did");
        mSelectedTags = new ArrayList<>(Arrays.asList(savedInstanceState.getStringArray("tags")));
        mSavedFields = savedInstanceState.getBundle("editFields");
    } else {/*from   w  w w  .  j  av  a 2s. co m*/
        mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER);
        if (mCaller == CALLER_NOCALLER) {
            String action = intent.getAction();
            if (action != null && (ACTION_CREATE_FLASHCARD.equals(action)
                    || ACTION_CREATE_FLASHCARD_SEND.equals(action))) {
                mCaller = CALLER_CARDEDITOR_INTENT_ADD;
            }
        }
    }

    startLoadingCollection();
}

From source file:com.droid.app.fotobot.FotoBot.java

/**
 *  ? ?. ?  ,     battery_level.//from   www  . j a  v a2 s . c  om
 */
public void batteryLevel() {

    BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            //context.unregisterReceiver(this);

            int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
            battery_temperature = ((float) intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1)) / 10.0f;
            battery_level = -1;
            if (rawlevel >= 0 && scale > 0) {
                battery_level = (rawlevel * 100) / scale;
            }

            //   int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
            //  isPlugged = plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB;
            //   if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN) {
            //       isPlugged = isPlugged || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
            //   }

        }
    };

    IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(batteryLevelReceiver, batteryLevelFilter);

}

From source file:com.android.calendar.AllInOneActivity.java

private long parseViewAction(final Intent intent) {
    long timeMillis = -1;
    Uri data = intent.getData();/*from w  w w  .  j  a va2  s .  c  o m*/
    if (data != null && data.isHierarchical()) {
        List<String> path = data.getPathSegments();
        if (path.size() == 2 && path.get(0).equals("events")) {
            try {
                mViewEventId = Long.valueOf(data.getLastPathSegment());
                if (mViewEventId != -1) {
                    mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0);
                    mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0);
                    mIntentAttendeeResponse = intent.getIntExtra(ATTENDEE_STATUS,
                            Attendees.ATTENDEE_STATUS_NONE);
                    mIntentAllDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false);
                    timeMillis = mIntentEventStartMillis;
                }
            } catch (NumberFormatException e) {
                // Ignore if mViewEventId can't be parsed
            }
        }
    }
    return timeMillis;
}

From source file:com.ccxt.whl.activity.ChatActivity.java

/**
 * onActivityResult
 *//*  w ww .  jav a 2  s .c om*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            if (copyMsg.getType() == EMMessage.Type.IMAGE) {
                ImageMessageBody imageBody = (ImageMessageBody) copyMsg.getBody();
                // ???
                clipboard.setText(COPY_IMAGE + imageBody.getLocalUrl());
            } else {
                // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
                // ((TextMessageBody) copyMsg.getBody()).getMessage()));
                clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            }
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VOICE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_PICTURE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_LOCATION) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (requestCode == REQUEST_CODE_ADD_TO_CONTACT) { // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            String sendstr = data.getStringExtra("edittext");
            if (CommonUtils.isNullOrEmpty(sendstr)) {
                sendstr = "";
            }
            //addUserToBlacklist(deleteMsg.getFrom());
            addContact(deleteMsg.getFrom(), sendstr);
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}

From source file:com.dan.wizardduel.MainActivity.java

@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    Log.e("tag", "activity result: " + request + " , " + response);
    if (request == RC_INVITATION_INBOX) {
        if (response != Activity.RESULT_OK) {
            mMainMenuFragment.stopLoading();
            return;
        }/* w ww.ja  va 2 s.  co  m*/

        // get the selected invitation
        Bundle extras = data.getExtras();
        Invitation invitation = extras.getParcelable(GamesClient.EXTRA_INVITATION);

        // accept it!
        RoomConfig roomConfig = makeBasicRoomConfigBuilder()
                .setInvitationIdToAccept(invitation.getInvitationId()).build();
        getGamesClient().joinRoom(roomConfig);

        // prevent screen from sleeping during handshake
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        // go to game screen
    } else if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            mMainMenuFragment.stopLoading();
            return;
        }

        // get the invitee list
        Bundle extras = data.getExtras();
        final ArrayList<String> invitees = data.getStringArrayListExtra(GamesClient.EXTRA_PLAYERS);

        // get automatch criteria
        Bundle autoMatchCriteria = null;
        int minAutoMatchPlayers = data.getIntExtra(GamesClient.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
        int maxAutoMatchPlayers = data.getIntExtra(GamesClient.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);

        if (minAutoMatchPlayers > 0) {
            autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1, 1, 0);//minAutoMatchPlayers, maxAutoMatchPlayers, 0);
        } else {
            autoMatchCriteria = null;
        }

        // create the room and specify a variant if appropriate
        RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
        roomConfigBuilder.addPlayersToInvite(invitees);
        if (autoMatchCriteria != null) {
            roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
        }
        RoomConfig roomConfig = roomConfigBuilder.build();
        getGamesClient().createRoom(roomConfig);

        // prevent screen from sleeping during handshake
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    } else if (request == RC_WAITING_ROOM) {
        if (response != Activity.RESULT_OK) {
            mMainMenuFragment.stopLoading();
            return;
        }
    } else if (request == RC_LEADERBOARD) {
        mMainMenuFragment.stopLoading();
    }
}

From source file:com.android.gallery3d.app.Gallery.java

private void startViewAction(Intent intent) {
    Boolean slideshow = intent.getBooleanExtra(EXTRA_SLIDESHOW, false);
    getStateManager().setLaunchGalleryOnTop(true);
    if (slideshow) {
        getActionBar().hide();/*from ww  w .  j  a v  a2 s . c  o  m*/
        DataManager manager = getDataManager();
        Path path = manager.findPathByUri(intent.getData());
        if (path == null || manager.getMediaObject(path) instanceof MediaItem) {
            path = Path.fromString(manager.getTopSetPath(DataManager.INCLUDE_IMAGE));
        }
        Bundle data = new Bundle();
        data.putString(SlideshowPage.KEY_SET_PATH, path.toString());
        data.putBoolean(SlideshowPage.KEY_RANDOM_ORDER, true);
        data.putBoolean(SlideshowPage.KEY_REPEAT, true);
        getStateManager().startState(SlideshowPage.class, data);
    } else {
        Bundle data = new Bundle();
        DataManager dm = getDataManager();
        Uri uri = intent.getData();
        String contentType = getContentType(intent);
        if (contentType == null) {
            Toast.makeText(this, R.string.no_such_item, Toast.LENGTH_LONG).show();
            finish();
            return;
        }
        if (uri == null) {
            int typeBits = GalleryUtils.determineTypeBits(this, intent);
            data.putInt(KEY_TYPE_BITS, typeBits);
            data.putString(AlbumSetPage.KEY_MEDIA_PATH, getDataManager().getTopSetPath(typeBits));
            getStateManager().setLaunchGalleryOnTop(true);
            getStateManager().startState(AlbumSetPage.class, data);
        } else if (contentType.startsWith(ContentResolver.CURSOR_DIR_BASE_TYPE)) {
            int mediaType = intent.getIntExtra(KEY_MEDIA_TYPES, 0);
            if (mediaType != 0) {
                uri = uri.buildUpon().appendQueryParameter(KEY_MEDIA_TYPES, String.valueOf(mediaType)).build();
            }
            Path setPath = dm.findPathByUri(uri);
            MediaSet mediaSet = null;
            if (setPath != null) {
                mediaSet = (MediaSet) dm.getMediaObject(setPath);
            }
            if (mediaSet != null) {
                if (mediaSet.isLeafAlbum()) {
                    data.putString(AlbumPage.KEY_MEDIA_PATH, setPath.toString());
                    getStateManager().startState(AlbumPage.class, data);
                } else {
                    data.putString(AlbumSetPage.KEY_MEDIA_PATH, setPath.toString());
                    getStateManager().startState(AlbumSetPage.class, data);
                }
            } else {
                startDefaultPage();
            }
        } else {
            Path itemPath = dm.findPathByUri(uri);
            Path albumPath = dm.getDefaultSetOf(itemPath);
            // TODO: Make this parameter public so other activities can reference it.
            boolean singleItemOnly = intent.getBooleanExtra("SingleItemOnly", false);
            if (!singleItemOnly && albumPath != null) {
                data.putString(PhotoPage.KEY_MEDIA_SET_PATH, albumPath.toString());
            }
            data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, itemPath.toString());
            getStateManager().startState(PhotoPage.class, data);
        }
    }
}

From source file:RhodesService.java

private void handleCommand(Intent intent, int startId) {
    if (intent == null) {
        return;//from  w ww.j a  va2  s . c o  m
    }
    String source = intent.getStringExtra(INTENT_SOURCE);
    Logger.I(TAG, "handleCommand: startId=" + startId + ", source=" + source);
    if (source == null)
        throw new IllegalArgumentException("Service command received from empty source");

    if (source.equals(BaseActivity.INTENT_SOURCE)) {
        Logger.D(TAG, "New activity was created");
    } else if (source.equals(PushContract.INTENT_SOURCE)) {
        int type = intent.getIntExtra(PushContract.INTENT_TYPE, PushContract.INTENT_TYPE_UNKNOWN);
        switch (type) {
        case PushContract.INTENT_TYPE_REGISTRATION_ID: {
            String id = intent.getStringExtra(PushContract.INTENT_REGISTRATION_ID);
            String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT);
            if (id == null)
                throw new IllegalArgumentException("Empty registration id received in service command");
            Logger.I(TAG, "Received PUSH registration id: " + id);
            setPushRegistrationId(pushType, id);
        }
            break;
        case PushContract.INTENT_TYPE_MESSAGE:
            if (intent.hasExtra(PushContract.INTENT_MESSAGE_EXTRAS)) {
                final String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT);
                final Bundle extras = intent.getBundleExtra(PushContract.INTENT_MESSAGE_EXTRAS);
                Logger.D(TAG, "Received PUSH message: " + extras);
                RhodesApplication.runWhen(RhodesApplication.AppState.AppStarted,
                        new RhodesApplication.StateHandler(true) {
                            @Override
                            public void run() {
                                handlePushMessage(pushType, extras);
                            }
                        });
                break;
            } else if (intent.hasExtra(PushContract.INTENT_MESSAGE_JSON)) {
                final String pushType = intent.getStringExtra(PushContract.INTENT_PUSH_CLIENT);
                final String json = intent.getStringExtra(PushContract.INTENT_MESSAGE_JSON);
                if (json != null) {
                    Logger.D(TAG, "Received PUSH message (JSON): " + json);
                    RhodesApplication.runWhen(RhodesApplication.AppState.AppStarted,
                            new RhodesApplication.StateHandler(true) {
                                @Override
                                public void run() {
                                    handlePushMessage(pushType, json);
                                }
                            });
                }
                break;
            }
        default:
            Logger.W(TAG, "Unknown command type received from " + source + ": " + type);
        }
    }
}

From source file:com.aidigame.hisun.imengstar.huanxin.ChatActivity.java

/**
 * onActivityResult//ww w.  ja va  2 s. co  m
 */
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_CODE_EXIT_GROUP) {
        setResult(RESULT_OK);
        finish();
        return;
    }
    if (requestCode == REQUEST_CODE_CONTEXT_MENU) {
        switch (resultCode) {
        case RESULT_CODE_COPY: // ??
            EMMessage copyMsg = ((EMMessage) adapter.getItem(data.getIntExtra("position", -1)));
            // clipboard.setText(SmileUtils.getSmiledText(ChatActivity.this,
            // ((TextMessageBody) copyMsg.getBody()).getMessage()));
            clipboard.setText(((TextMessageBody) copyMsg.getBody()).getMessage());
            break;
        case RESULT_CODE_DELETE: // ?
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            conversation.removeMessage(deleteMsg.getMsgId());
            adapter.refresh();
            listView.setSelection(data.getIntExtra("position", adapter.getCount()) - 1);
            break;

        case RESULT_CODE_FORWARD: // ??
            EMMessage forwardMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", 0));
            Intent intent = new Intent(this, ForwardMessageActivity.class);
            intent.putExtra("forward_msg_id", forwardMsg.getMsgId());
            startActivity(intent);

            break;

        default:
            break;
        }
    }
    if (resultCode == RESULT_OK) { // ?
        if (requestCode == REQUEST_CODE_EMPTY_HISTORY) {
            // ?
            EMChatManager.getInstance().clearConversation(toChatUsername);
            adapter.refresh();
        } else if (requestCode == REQUEST_CODE_CAMERA) { // ??
            if (cameraFile != null && cameraFile.exists())
                sendPicture(cameraFile.getAbsolutePath());
        } else if (requestCode == REQUEST_CODE_SELECT_VIDEO) { // ??

            int duration = data.getIntExtra("dur", 0);
            String videoPath = data.getStringExtra("path");
            File file = new File(PathUtil.getInstance().getImagePath(), "thvideo" + System.currentTimeMillis());
            Bitmap bitmap = null;
            FileOutputStream fos = null;
            try {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }
                bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, 3);
                if (bitmap == null) {
                    EMLog.d("chatactivity", "problem load video thumbnail bitmap,use default icon");
                    bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.app_panel_video_icon);
                }
                fos = new FileOutputStream(file);

                bitmap.compress(CompressFormat.JPEG, 100, fos);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    fos = null;
                }
                if (bitmap != null) {
                    bitmap.recycle();
                    bitmap = null;
                }

            }
            sendVideo(videoPath, file.getAbsolutePath(), duration / 1000);

        } else if (requestCode == REQUEST_CODE_LOCAL) { // ??
            if (data != null) {
                Uri selectedImage = data.getData();
                if (selectedImage != null) {
                    sendPicByUri(selectedImage);
                }
            }
        } else if (requestCode == REQUEST_CODE_SELECT_FILE) { // ??
            if (data != null) {
                Uri uri = data.getData();
                if (uri != null) {
                    sendFile(uri);
                }
            }

        } else if (requestCode == REQUEST_CODE_MAP) { // 
            double latitude = data.getDoubleExtra("latitude", 0);
            double longitude = data.getDoubleExtra("longitude", 0);
            String locationAddress = data.getStringExtra("address");
            if (locationAddress != null && !locationAddress.equals("")) {
                more(more);
                sendLocationMsg(latitude, longitude, "", locationAddress);
            } else {
                Toast.makeText(this, "????", 0).show();
            }
            // ???
        } else if (requestCode == REQUEST_CODE_TEXT || requestCode == REQUEST_CODE_VOICE
                || requestCode == REQUEST_CODE_PICTURE || requestCode == REQUEST_CODE_LOCATION
                || requestCode == REQUEST_CODE_VIDEO || requestCode == REQUEST_CODE_FILE) {
            resendMessage();
        } else if (requestCode == REQUEST_CODE_COPY_AND_PASTE) {
            // 
            if (!TextUtils.isEmpty(clipboard.getText())) {
                String pasteText = clipboard.getText().toString();
                if (pasteText.startsWith(COPY_IMAGE)) {
                    // ??path
                    sendPicture(pasteText.replace(COPY_IMAGE, ""));
                }

            }
        } else if (requestCode == REQUEST_CODE_ADD_TO_BLACKLIST) { // ???
            EMMessage deleteMsg = (EMMessage) adapter.getItem(data.getIntExtra("position", -1));
            addUserToBlacklist(deleteMsg.getFrom());
        } else if (conversation.getMsgCount() > 0) {
            adapter.refresh();
            setResult(RESULT_OK);
        } else if (requestCode == REQUEST_CODE_GROUP_DETAIL) {
            adapter.refresh();
        }
    }
}