App-Attachment is an easy,flexible library for you Android attachment feature, you can use it as dialog or just api, you can get images, different files from camera,internal storage or google drive.
in project level build.gradle
allprojects {
repositories {
google()
jcenter()
//...
maven { url 'https://jitpack.io' }
}
}dependencies {
implementation 'com.github.MohammedSDev:app-attachment:1.x.x'
}To use as dialog .. you need to provide your layout design & you should use appAttachment ids for each button.
<itemname="appAttachmentDialogCameraBtn"type="id" />
<itemname="appAttachmentDialogGalleryBtn"type="id" />
<itemname="appAttachmentDialogOtherBtn"type="id" />for example here a design with all attachment options {camera,gallery,other}, the ids using from app-attachmentR.layout.attachment_dialog_layout
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"xmlns:app="http://schemas.android.com/apk/res-auto"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="wrap_content"android:paddingStart="20dp"android:paddingTop="30dp"android:paddingBottom="30dp"android:paddingEnd="20dp"android:background="#fff"
>
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="18sp"android:fontFamily="sans-serif"android:textStyle="bold"android:textColor="#222222"android:letterSpacing="0.03"android:lineSpacingExtra="12sp"android:text="Add attachment"
/>
<Buttonandroid:id="@id/appAttachmentDialogCameraBtn"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="18sp"android:fontFamily="sans-serif"android:textStyle="normal"android:textColor="#3e3f42"android:lineSpacingExtra="6sp"android:text="take_photo"android:layout_marginTop="40dp"android:layout_marginStart="5dp"
/>
<Buttonandroid:id="@id/appAttachmentDialogGalleryBtn"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="18sp"android:fontFamily="sans-serif"android:textStyle="normal"android:textColor="#3e3f42"android:lineSpacingExtra="6sp"android:text="open_gallery"android:layout_marginTop="20dp"android:layout_marginStart="5dp"
/>
<Buttonandroid:id="@id/appAttachmentDialogOtherBtn"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="18sp"android:fontFamily="sans-serif"android:textStyle="normal"android:textColor="#3e3f42"android:lineSpacingExtra="6sp"android:text="other_type"android:layout_marginTop="20dp"android:layout_marginStart="5dp"
/>
</LinearLayout>AppAttachmentDialog(R.layout.attachment_type_dialog_layout
,AppAttachmentType.ALL)
.onResult { code, file ->
displasyImage(file)
}
.prepare {
//Optional:you can pass you custom authority //this.authority = ""//Optional:you can pass your custom file//this.cameraPictureFile = File("...")//Note: if your custom file in shared storage.you need to set `requestStorageRunTimePermission` true//this.requestStorageRunTimePermission = true
}
.onExplainRequired { permission, reTry ->//to show user an explain, then call reTry()
reTry()
}
.show(supportFragmentManager,"AppAttachmentDialog")overridefunonActivityResult(requestCode:Int, resultCode:Int, data:Intent?) {
super.onActivityResult(requestCode, resultCode, data)
AppAttachmentDialog.onActivityResult(requestCode,resultCode,data,this) { code, file ->
displasyImage(file)
}overridefunonRequestPermissionsResult(requestCode:Int, permissions:Array<outString>, grantResults:IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
AppAttachmentDialog.onRequestPermissionsResult(requestCode,permissions,grantResults,this)
}1- if you have FileProvider in Manifest, yout must use your custom authority or add the fallowning lines in your fileProvider xml resource.
<files-pathname="my_images"path="."/>
<cache-pathname="my_cache_images"path="." />
<external-pathname="external"path="." />2- you can use openCamera,openGallery,openFileManager & getPath apis without AppAttachmentDialog.
3- check also compressBitmapFile,scaleDonwImage apis
Enjoy using app-attachment library,report any bugs you found, or even drop me an (Arabic/English) email gg.goo.mobile@gmail.com