/**
* Creates the activity, sets the view, and checks if Telephony is enabled.
* Telephony enabled:
* Checks for phone permission.
* Sets the PhoneStateListener.
* Telephony not enabled: Disables the call button and shows the Retry button.
*
* @param savedInstanceState Instance state
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a telephony manager.
mTelephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
// Check to see if Telephony is enabled.
if (isTelephonyEnabled()) {
Log.d(TAG, getString(R.string.telephony_enabled));
// Check for phone permission.
checkForPhonePermission();
// Register the PhoneStateListener to monitor phone activity.
mListener = new MyPhoneCallListener();
mTelephonyManager.listen(mListener, PhoneStateListener.LISTEN_CALL_STATE);
} else {
Toast.makeText(this,
R.string.telephony_not_enabled, Toast.LENGTH_LONG).show();
Log.d(TAG, getString(R.string.telephony_not_enabled));
// Disable the call button.
disableCallButton();
}
}
MainActivity.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:android-fundamentals-phone-sms
作者:
评论列表
文章目录