gpt4 book ai didi

Android: deviceId null (TelephonyManager)

转载 作者:行者123 更新时间:2023-11-29 18:06:23 25 4
gpt4 key购买 nike

我对 TelephonyManager 有疑问。 DeviceId 为空/空白。这是我的代码。我哪里错了?

这是我的java代码

RegistryActivity.java

package android.tennis.app;

import android.tennis.library.UserFunctions;
//import android.tennis.library.InfoPhoneAndroid;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.provider.Settings.Secure;

[...]

public class RegisterActivity extends Activity {

private String deviceID = null, androidID = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.register);

[..]

final TelephonyManager telephonyManager = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
deviceID = telephonyManager.getDeviceId();

[..]

btnRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {

[..]

UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(nome, email, password, username, citta, data_di_nascita, cognome, deviceID);
}

当registerUser调用index.php时,deviceId为null。为什么?

我的 list 文件是:

<uses-sdk android:minSdkVersion="8" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".DashboardActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- Login Activity -->
<activity
android:label="Login"
android:name=".LoginActivity">

</activity>

<!-- Register Activity -->
<activity
android:label="Register New Account"
android:name=".RegisterActivity"></activity>
</application>

<!-- Allow to connect with internet -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />

我用的是模拟器。如果我输入 *#60#,输出为:00000000

最佳答案

不是所有的 android 设备都有 3G 模块,所以他们没有 telephonyManager.getDeviceId();你应该使用其他一些 uid

关于Android: deviceId null (TelephonyManager),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13232215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com