我对 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 为空。为什么?
我的清单文件是:
<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