Android IMEI 问题

问题描述 投票:0回答:1

问题:我正在尝试使用作为系统特权应用程序安装的 Android 应用程序从设备获取 IMEI 号码。但是,每当我尝试访问 IMEI 号码时,我都会遇到安全异常并且应用程序崩溃。

采取的步骤:

  • 在 Android Studio 中创建了一个应用程序
  • 获得证书platform.p8和platform.x509.pem
  • 使用 Keytool 生成密钥库文件
  • 使用此密钥库在 build.gradle 文件中签署我的构建并生成构建
  • AOSP(我猜是黑客方式)
  • 将生成的构建安装到 /system/priv-app/{App}/{App}.apk 中
  • 重新启动我的手机并将我的应用程序安装为系统应用程序
  • 但是当我运行应用程序时,它崩溃了并且日志显示发生安全异常

任何帮助将不胜感激

android kotlin gradle system android-source
1个回答
0
投票
        class MainActivity : AppCompatActivity() {
       lateinit var button: Button
       lateinit var textView: TextView
       private lateinit var IMEINumber: String
       private val REQUEST_CODE = 101
       override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          title = "KotlinApp"
          textView = findViewById(R.id.textView)
          button = findViewById(R.id.button)
          button.setOnClickListener {
             val telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as
             TelephonyManager
             if (ActivityCompat.checkSelfPermission(this@MainActivity,
             Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this@MainActivity,
                arrayOf(Manifest.permission.READ_PHONE_STATE), REQUEST_CODE)
                return@setOnClickListener
             }  
             IMEINumber = telephonyManager.deviceId
             textView.text = IMEINumber
          }
       }
       override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String?>,
       grantResults: IntArray) {
          when (requestCode) {
             REQUEST_CODE -> {
                if (grantResults.isNotEmpty() && grantResults[0] ==
                PackageManager.PERMISSION_GRANTED) {
                   Toast.makeText(this, "Permission granted.", Toast.LENGTH_SHORT).show()
                } else {
                   Toast.makeText(this, "Permission denied.", Toast.LENGTH_SHORT).show()
                }
             }
          }
       }
    }


<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.q11">
   <uses-permission android:name="android.permission.READ_PHONE_STATE" />
   <uses-permission android:name="android.permission.READ_PRIVILEGED_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>
© www.soinside.com 2019 - 2024. All rights reserved.