第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

android開發(fā):調(diào)用照相機(jī)臨時(shí)跳轉(zhuǎn)頁面

標(biāo)簽:
Android

临时相机调用页面

/**
 * 临时照相页面
 */
public class CameraTempActivity extends JCBBaseActivity {

    public static final String USER_ID = "user_id";
    public static final String SESSION_TYPE = "session_type";

    public void start(Context context, String userId, SessionTypeEnum sessiongType){
        Intent it = new Intent();
        it.setClass(context,CameraTempActivity.class);
        it.putExtra(USER_ID,userId);
        it.putExtra(SESSION_TYPE,sessiongType);
        startActivity(it);
    }

    String outPath = UStorage.getWritePath(HString.get32UUID() + ".jpg", StorageType.TYPE_TEMP);
    private static final int REQUEST_CODE_CAMERA = 2;

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        try {
            if (TextUtils.isEmpty(outPath)) {
                toast(getResources().getString(R.string.sdcard_not_enough_error), Toast.LENGTH_LONG);
                finish();
                return;
            }
            File outputFile = new File(outPath);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outputFile));
            startActivityForResult(intent, REQUEST_CODE_CAMERA);
        } catch (ActivityNotFoundException e) {
            finish();
        } catch (Exception e) {
            toast(getResources().getString(R.string.sdcard_not_enough_head_error), Toast.LENGTH_LONG);
            finish();
        }
    }

    @Override
    protected void startView(Bundle savedInstanceState) {

    }

    @Override
    protected int layoutViewId() {
        return R.layout.activity_camera_temp;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            setResult(resultCode);
            finish();
            return;
        }
        onPickedCamera(data, requestCode);
    }

    private void onPickedCamera(Intent data, int code) {
        try {
            String photoPath = pathFromResult(data);
            if (!TextUtils.isEmpty(photoPath)) {
                Intent it = getIntent();
                String userId = it.getStringExtra(USER_ID);
                SessionTypeEnum sessionType = (SessionTypeEnum) it.getSerializableExtra(SESSION_TYPE);
                CameraActivity.start(CameraTempActivity.this,userId,sessionType,photoPath);
            }
            finish();
        } catch (Exception e) {
            toast(getResources().getString(R.string.picker_image_error), Toast.LENGTH_LONG);
            finish();
        }
    }

    private String pathFromResult(Intent data) {
        if (data == null || data.getData() == null) {
            return outPath;
        }

        Uri uri = data.getData();
        Cursor cursor = getContentResolver()
                .query(uri, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
        if (cursor == null) {
            // miui 2.3 有可能为null
            return uri.getPath();
        } else {
            if (uri.toString().contains("content://com.android.providers.media.documents/document/image")) { // htc 某些手机
                // 获取图片地址
                String _id = null;
                String uridecode = uri.decode(uri.toString());
                int id_index = uridecode.lastIndexOf(":");
                _id = uridecode.substring(id_index + 1);
                Cursor mcursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, " _id = " + _id,
                        null, null);
                mcursor.moveToFirst();
                int column_index = mcursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                outPath = mcursor.getString(column_index);
                if (!mcursor.isClosed()) {
                    mcursor.close();
                }
                if (!cursor.isClosed()) {
                    cursor.close();
                }
                return outPath;

            } else {
                cursor.moveToFirst();
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                outPath = cursor.getString(column_index);
                if (!cursor.isClosed()) {
                    cursor.close();
                }
                return outPath;
            }
        }
    }

}
點(diǎn)擊查看更多內(nèi)容
1人點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動(dòng)開發(fā)工程師
手記
粉絲
81
獲贊與收藏
3604

關(guān)注作者,訂閱最新文章

閱讀免費(fèi)教程

感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消