डिवाइस मॉडल नाम प्राप्त करना
यह सरल उदाहरण दिखाता है कि android.os.Build.MODEL का उपयोग करके एंड्रॉइड डिवाइस का मार्केटिंग नाम (जैसे "Pixel 7", "Galaxy S23") कैसे प्राप्त करें।
चरण 1: नया प्रोजेक्ट बनाएं
Android Studio में File → New Project चुनें।
चरण 2: लेआउट XML (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:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="18sp" />
</RelativeLayout>
चरण 3: 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;
}
}
चरण 4: 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 प्रॉपर्टीज
| प्रॉपर्टी | विवरण |
|---|---|
Build.MANUFACTURER | निर्माता नाम (जैसे "Google", "Samsung") |
Build.BRAND | ब्रांड नाम |
Build.DEVICE | डिवाइस कोडनेम |
Build.PRODUCT | उत्पाद नाम |
Build.VERSION.RELEASE | एंड्रॉइड वर्जन (जैसे "14") |
Build.VERSION.SDK_INT | API लेवल (जैसे 34) |
आउटपुट
ऐप चलाने पर स्क्रीन पर डिवाइस का मॉडल नाम दिखाई देगा।
