
Hi, Everyone In this Android Example, I am sharing how to attach multiple types of file in android. We are creating a solution for android how to attach a file in the android app. When I click on a button open mobile folder and attach file and show file Path in TextView.
Android How to attach multiple types of file and send to the server. Like I am creating an Email type app a here I am using Attach file like PDF, Image, Video, WorFile, etc. Android sends the attached file to the server. We Create an example for Attaching a file of any type in Android application?.
Attaching a file of any type in Android application?
So let’s start to create a simple example. First of all, Start an android studio and make an android application. in your app create a button and add the on click listener on a button.
Main.Java Class Source Code.
public class MainActivity extends AppCompatActivity {
EditText ticketShortDesc,ticketDescription;
TextView Tecket_Attach;
Uri URI = null;
private static final int PICK_FROM_GALLERY = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_ticket);
FindViewById();
}
public void FindViewById(){
ticketDescription=(EditText)findViewById(R.id.ticketDescription);
Tecket_Attach = (TextView)findViewById(R.id.Tecket_Attach);
Tecket_Attach.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openFolder();
}
});
}
public void openFolder() {
Intent intent = new Intent();
intent.setType("*/*");
// intent.setType("file/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
}
@SuppressLint("MissingSuperCall")
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_FROM_GALLERY && resultCode == RESULT_OK) {
URI = data.getData();
Tecket_Attach.setText(URI.getLastPathSegment());
}
}
activity_main.XML file Source Code.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/edit_card"
android:orientation="vertical">
<EditText
android:id="@+id/Feedback_LongDes"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="10dp"
android:textAppearance="@style/body"
android:gravity="top"
android:hint="Details description for feedback"
android:inputType="textMultiLine"
android:background="@drawable/edit_card"/>
<TextView
android:id="@+id/Feedback_Attach"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:drawablePadding="15dp"
android:text="Attach"
android:drawableLeft="@drawable/attach"/>
</LinearLayout>





