我已经编写了一个简单的 android 应用程序来获取电话号码......这个应用程序在 Android 模拟器中运行......但它不能在 Android 手机中运行(在三星 Galaxy s3 和三星 ace 中)。
这是源代码。
PhoneNumberActivity.java
public class PhoneNumberActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone_number);
final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getLine1Number();
final Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
TextView textView = (TextView) findViewById(R.id.phoneNumber);
textView.setText("Phone Number is :- "+telephonyManager.getLine1Number());
button.setVisibility(Button.INVISIBLE);
textView.setVisibility(TextView.VISIBLE);
}
});
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pervazive.phonenumber"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.phonenumber.PhoneNumberActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:theme="@style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
请让我知道有什么问题。