কম্পিউটার টিউটোরিয়াল

এন্ড্রয়েডে ফাইল সংযুক্ত করে ইমেইল পাঠানোর পদ্ধতি

এন্ড্রয়েডে সংযুক্ত ফাইল সহ ইমেইল পাঠানোর ধাপাবলী

এই উদাহরণটি দেখায় কীভাবে একটি এন্ড্রয়েড অ্যাপ্লিকেশনে ইমেইল কম্পোজ করা যায় এবং গ্যালারি থেকে ফাইল নির্বাচন করে সংযুক্ত করা যায়। ইমেইল ক্লায়েন্ট চয়জার ব্যবহার করে পাঠানো হয়।

ধাপ ১: নতুন প্রজেক্ট তৈরি করুন

Android Studio-তে File → New Project এ যান এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।

ধাপ ২: লেআউট ফাইল সংশোধন করুন (res/layout/activity_main.xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="4dp"
    tools:context=".MainActivity">
    <EditText
        android:id="@+id/etTo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:hint="প্রাপকের ইমেইল ঠিকানা!"
        android:inputType="textEmailAddress"
        android:singleLine="true" />
    <EditText
        android:id="@+id/etSubject"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:hint="বিষয় লিখুন"
        android:singleLine="true" />
    <EditText
        android:id="@+id/etMessage"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_margin="5dp"
        android:gravity="top|start"
        android:hint="ইমেইল লিখুন"
        android:inputType="textMultiLine" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/btSend"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:layout_margin="5dp"
            android:text="পাঠান" />
        <Button
            android:id="@+id/btAttachment"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:text="সংযুক্তি" />
    </RelativeLayout>
    <TextView
        android:id="@+id/tvAttachment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:drawableStart="@drawable/ic_attach"
        android:visibility="gone" />
</LinearLayout>

ধাপ ৩: মূল এক্টিভিটি লজিক (src/MainActivity.java)

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    EditText etEmail, etSubject, etMessage;
    Button sendBtn, attachmentBtn;
    TextView tvAttachment;
    String email, subject, message;
    Uri URI = null;
    private static final int PICK_FROM_GALLERY = 101;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        etEmail = findViewById(R.id.etTo);
        etSubject = findViewById(R.id.etSubject);
        etMessage = findViewById(R.id.etMessage);
        attachmentBtn = findViewById(R.id.btAttachment);
        tvAttachment = findViewById(R.id.tvAttachment);
        sendBtn = findViewById(R.id.btSend);

        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendEmail();
            }
        });

        attachmentBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openFolder();
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == PICK_FROM_GALLERY && resultCode == RESULT_OK) {
            URI = data.getData();
            tvAttachment.setText(URI.getLastPathSegment());
            tvAttachment.setVisibility(View.VISIBLE);
        }
    }

    public void sendEmail() {
        try {
            email = etEmail.getText().toString();
            subject = etSubject.getText().toString();
            message = etMessage.getText().toString();
            
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            
            if (URI != null) {
                emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
            }
            
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
            this.startActivity(Intent.createChooser(emailIntent, "ইমেইল পাঠানো হচ্ছে..."));
        } catch (Throwable t) {
            Toast.makeText(this, "অনুরোধ ব্যর্থ: " + t.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void openFolder() {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.putExtra("return-data", true);
        startActivityForResult(Intent.createChooser(intent, "পূর্ণ করুন"), PICK_FROM_GALLERY);
    }
}

ধাপ ৪: ম্যানিফেস্টে অনুমতি যোগ করুন (AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.sample">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <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">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

অ্যাপ্লিকেশন চালান

আপনার আসল এন্ড্রয়েড ডিভাইস কম্পিউটারের সাথে সংযুক্ত আছে অনুমান করি। Android Studio-তে আপনার প্রজেক্টের এক্টিভিটি ফাইল খুলুন এবং টুলবারের Run আইকনে ক্লিক করুন। আপনার মোবাইল ডিভাইস নির্বাচন করুন এবং আপনার ডিভাইসে ডিফল্ট স্ক্রিন দেখুন।

  1. আইফোনে ইমেইলে অ্যাট্যাচমেন্ট পাঠানোর পদ্ধতি

  2. অ্যান্ড্রয়েডে এনক্রিপ্টেড ইমেইল পাঠানোর পদ্ধতি

  3. ইমেইলে এক্সিকিউটেবল ফাইল পাঠানোর পদ্ধতি

  4. বড় ভিডিও ফাইল ইমেইল দিয়ে শেয়ার করুন: ধাপে ধাপে গাইড