android - Basic camera in app -


i trying activate camera in app have done following , kept simple possible.

androidmanifest file

<uses-permission android:name="android.permission.camera"/> <uses-feature android:name="android.hardware.camera" /> <uses-feature android:name="android.hardware.camera.autofocus" /> ...     <activity         android:name=".cameraact"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> 

cameraact.class

   public class cameraact extends appcompatactivity {         public void oncreate(bundle savedinstancestate) {           super.oncreate(savedinstancestate);           setcontentview(r.layout.activity_camera);          // have camera?         if (!getpackagemanager()                 .hassystemfeature(packagemanager.feature_camera)) {             toast.maketext(this, "no camera on device", toast.length_long)                     .show();         } else {             cameraid = findfrontfacingcamera();             if (cameraid < 0) {                 toast.maketext(this, "no front facing camera found.",                         toast.length_long).show();             } else {                 camera = camera.open(cameraid);             }           }        }         private int findfrontfacingcamera() {           int cameraid = -1;           // search front facing camera           int numberofcameras = camera.getnumberofcameras();           (int = 0; < numberofcameras; i++) {              camerainfo info = new camerainfo();              camera.getcamerainfo(i, info);              if (info.facing == camerainfo.camera_facing_front) {                 log.d(debug_tag, "camera found");                 cameraid = i;                 break;             }           }         return cameraid;     } 

activity_camera.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">  </relativelayout> 

the activity opens , on log see debug_tag: camera found in logcat dont see camera on screen. see when activity launches: enter image description here


Comments

Post a Comment

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -