Kotlinを使用してAndroidデバイスのシリアル番号を見つける方法は?
この例は、Kotlinを使用してAndroidデバイスのシリアル番号を見つける方法を示しています。
ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。
ステップ2 −次のコードを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:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_marginTop="50dp" android:text="Tutorials Point" android:textAlignment="center" android:textColor="@android:color/holo_green_dark" android:textSize="32sp" android:textStyle="bold" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button" android:layout_centerInParent="true" android:layout_marginTop="16sp" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:onClick="showDeviceInfo" android:text="Get Serial Number" /> </RelativeLayout>
ステップ3 −次のコードをsrc / MainActivity.kt
に追加しますimport android.Manifest
import android.app.AlertDialog
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.telephony.TelephonyManager
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
class MainActivity : AppCompatActivity() {
private val requestState = 100
private var checkedPermission = PackageManager.PERMISSION_DENIED
lateinit var manager: TelephonyManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
title = "KotlinApp"
checkedPermission = ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_PHONE_STATE);
if (Build.VERSION.SDK_INT >= 23 && checkedPermission !=
PackageManager.PERMISSION_GRANTED) {
requestPermission();
} else
checkedPermission = PackageManager.PERMISSION_GRANTED;
}
private fun requestPermission() {
Toast.makeText(this, "Requesting permission", Toast.LENGTH_SHORT).show()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
this.requestPermissions(arrayOf(Manifest.permission.READ_PHONE_STATE), requestState)
}
}
fun showDeviceInfo(view: View) {
manager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val dBuilder: AlertDialog.Builder = AlertDialog.Builder(this)
val stringBuilder = StringBuilder()
if (checkedPermission != PackageManager.PERMISSION_DENIED) {
dBuilder.setTitle("Device Info")
stringBuilder.append("""
SERIAL : ${Build.SERIAL}
""".trimIndent())
} else {
dBuilder.setTitle("Permission denied")
stringBuilder.append("Can't access device info !")
}
dBuilder.setMessage(stringBuilder)
dBuilder.show()
}
override fun onRequestPermissionsResult(requestCode: Int, vararg permissions: String?, grantResults: IntArray) {
when (requestCode) {
requestState -> if (grantResults.isNotEmpty() && grantResults[0] == PackageManager
.PERMISSION_GRANTED) {
checkedPermission = PackageManager.PERMISSION_GRANTED
}
}
}
} ステップ4 −次のコードをandroidManifest.xmlに追加します
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="app.com.q11"> <uses-permission android:name="android.permission.READ_PHONE_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モバイルデバイスをコンピューターに接続していると思います。 Android Studioからアプリを実行するには、プロジェクトのアクティビティファイルの1つを開き、[実行]アイコンをクリックします ツールバーから
。オプションとしてモバイルデバイスを選択し、デフォルトの画面を表示するモバイルデバイスを確認します
-
AndroidデバイスのGPSが有効になっているかどうかを確認するにはどうすればよいですか?
この例は、AndroidデバイスのGPSが有効になっているかどうかを確認する方法を示しています。 ステップ1 − Android Studioで新しいプロジェクトを作成し、[ファイル]⇒[新しいプロジェクト]に移動して、新しいプロジェクトを作成するために必要なすべての詳細を入力します。 ステップ2 −次のコードをres / layout/activity_main.xmlに追加します。 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="
-
iPhoneまたはiPadでシリアル番号を見つける方法
iPhone、iPad、またはiPodtouchのシリアル番号を調べる必要がある理由はたくさんあります。 Appleサポートから技術的な問題について助けを得るのにそれが必要かもしれません。保証のステータスを確認することをお勧めします。持っているiPhoneのモデルを知りたいだけかもしれません。 理由に関係なく、私たちはお手伝いします。この記事では、厄介なシリアル番号を見つけるための6つの簡単な(場合によっては非常に簡単な)方法について説明します。デバイスの電源が入らず、パッケージが見つからない場合でも役立ちます。 (ただし、一部のサポートコールなどでは、Appleの従業員は代わりにIMEIか