Android phone calls directly to take pictures

Android directly calls the camera method natively

Some time ago, there was a need for h5 to call the camera function of the mobile phone, which caused my brain pain. Finally, I created a method on the Android shell. I can directly use the input configuration ( Android ios directly call the phone camera function )
today is the time to meet with the leader who will ask for the needs, all the staff are seated (actually only 3 people, ^ v ^), we will not discuss the content , Anyway, the final result is unacceptable. They need to call the camera using native Android methods. As a front-end, I am confused and obsessed with o((⊙﹏⊙))o, we don't understand, we don't dare to ask, we don't dare to say. The most important thing is that the company does not have Android development. Uncomfortable.
Finally I asked my friend about the method. I make a simple record.

// 打开相机
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//用来打开相机的Intent
if(takePhotoIntent.resolveActivity(getPackageManager())!=null){
    
    //这句作用是如果没有相机则该应用不会闪退,要是不加这句则当系统没有相机应用的时候该应用会闪退
    startActivityForResult(takePhotoIntent,REQ_CODE);//启动相机
}
// 获取结果
@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
    
     if(requestCode==REQ_CODE&&resultCode==RESULT_OK){
    
    
         /*缩略图信息是储存在返回的intent中的Bundle中的,
         * 对应Bundle中的键为data,因此从Intent中取出
         * Bundle再根据data取出来Bitmap即可*/
         Bundle extras = data.getExtras();
         Bitmap bitmap = (Bitmap) extras.get("data");
         mPicture.setImageBitmap(bitmap);
     }
 }

Guess you like

Origin blog.csdn.net/lbchenxy/article/details/100114406