অ্যান্ড্রয়েড ডিভাইসের ইউনিক আইডি (Android ID) বের করা
এই উদাহরণে দেখানো হয়েছে কীভাবে Settings.Secure.ANDROID_ID ব্যবহার করে ডিভাইসের ইউনিক আইডি পেতে হয়।
প্রথম ধাপ: প্রজেক্ট তৈরি করুন
Android Studio-তে নতুন প্রজেক্ট তৈরি করুন।
দ্বিতীয় ধাপ: লেআউট ফাইল
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"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="24sp"
android:textStyle="bold"/>
</RelativeLayout>
তৃতীয় ধাপ: মেইন এক্টিভিটিতে ডিভাইস আইডি বের করার কোড
src/MainActivity.java:
import android.provider.Settings;
import android.support.v7.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);
// Android ID বের করা - এটি ডিভাইসের প্রথম বুটে জেনারেট হয়
String ID = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
textView.setText("Device ID: " + ID);
}
}
চতুর্থ ধাপ: ম্যানিফেস্ট ফাইল
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="https://schemas.android.com/apk/res/android"
package="app.com.sample">
<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_ID ৬৪-বিট হেক্সাডেসিমেল স্ট্রিং (উদাহরণ:
a1b2c3d4e5f6g7h8) - এটি ডিভাইসের প্রথম বুটে র্যান্ডমলি জেনারেট হয়
- ফ্যাক্টরি রিসেট করলে এটি পরিবর্তিত হতে পারে
- Android 8.0 (API 26) থেকে প্রতিটি অ্যাপের জন্য আলাদা Android ID থাকে (Scoped Storage)
- IMEI বা Serial Number ব্যবহারের জন্য বিশেষ পারমিশন লাগে (Android 10+) - তাই Android ID আরও নিরাপদ
অ্যাপ্লিকেশন চালান
Run করলে ডিভাইসের ইউনিক আইডি টেক্সটভিউতে দেখাবে।
