<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.razormist.simpleimagecapture.MainActivity"> <ImageView android:id="@+id/iv_image" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/btn_capture" app:srcCompat="@mipmap/ic_launcher" /> android:id="@+id/btn_capture" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Capture" android:layout_marginBottom="30dp" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.razormist.simpleimagecapture"> <uses-feature android:name="android.hardware.camera2" android:required="true"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:configChanges="orientation" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Button btn_capture; ImageView iv_image; int code = 1;
public void onActivityResult(int code, int resultCode, Intent data) { if(code == this.code){ if(resultCode == RESULT_OK){ Bundle bundle = new Bundle(); bundle = data.getExtras(); Bitmap bmp; bmp = (Bitmap)bundle.get("data"); iv_image.setImageBitmap(bmp); } } }
iv_image = (ImageView)findViewById(R.id.iv_image); @Override Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if(intent.resolveActivity(getPackageManager()) != null){ startActivityForResult(intent, code); } } });
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.