এই টিউটোরিয়ালে আমরা শিখব কীভাবে android.os.Build ক্লাস ব্যবহার করে ডিভাইসের মডেল নাম প্রোগ্রাম্যাটিক্যালি পেতে হয়।
প্রয়োজনীয় ধাপগুলো
ধাপ ১: নতুন প্রজেক্ট তৈরি করুন
Android Studio-তে File → New Project এ যান এবং প্রয়োজনীয় বিবরণ পূরণ করে একটি নতুন প্রজেক্ট তৈরি করুন।
ধাপ ২: লেআউট ফাইল তৈরি করুন
res/layout/activity_main.xml ফাইলে নিচের কোড যোগ করুন:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="https://schemas.android.com/apk/res/android"
xmlns:tools="https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
tools:context=".MainActivity">
<TextView
android:gravity="center"
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="18sp" />
</RelativeLayout>
ধাপ ৩: মেইন এক্টিভিটিতে মডেল নাম পান
src/MainActivity.java ফাইলে নিচের কোড যোগ করুন:
package app.tutorialspoint.com.sample;
import android.os.Build;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
textView.setText(getPhoneModel());
}
private String getPhoneModel() {
return Build.MODEL;
}
}
ধাপ ৪: ম্যানিফেস্ট কনফিগার করুন
AndroidManifest.xml ফাইল:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="app.tutorialspoint.com.sample">
<uses-permission android:name="android.permission.CALL_PHONE" />
<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>
Build ক্লাসের অন্যান্য útil فیل্ডগুলো
Build.MANUFACTURER- নির্মাতার নাম (যেমন: Samsung, Xiaomi)Build.BRAND- ব্র্যান্ড নামBuild.DEVICE- ডিভাইস কোডনেমBuild.VERSION.RELEASE- অ্যান্ড্রয়েড ভার্সন (যেমন: 13, 14)Build.VERSION.SDK_INT- API লেভেল (যেমন: 33, 34)
এই তথ্য ডিবাগিং, অ্যানালিটিক্স, বা ডিভাইস-স্পেসিফিক ফিচার হ্যান্ডলিং-এর জন্য খুব কাজে আসে।