gpt4 book ai didi

android - PhoneStateListener 不调用

转载 作者:搜寻专家 更新时间:2023-11-01 07:40:32 27 4
gpt4 key购买 nike

这是我的全部代码......

广播示例.java

 package com.example.broadcast;

> import android.app.Activity; import
> android.content.Context; import
> android.os.Bundle; import
> android.telephony.*; import
> android.util.Log; import
> android.widget.TextView;

public class BroadcastExaple extends Activity {
TextView textOut;
TelephonyManager telephonyManager;
PhoneStateListener listener;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

try {

super.onCreate(savedInstanceState);

// Get the UI
textOut = new TextView(this);
textOut.setText("DEmoBroadCast");
setContentView(textOut);

// Get the telephony manager
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

// Register the listener wit the telephony manager
telephonyManager.listen(listener,PhoneStateListener.LISTEN_CALL_STATE);

// Create a new PhoneStateListener
listener = new PhoneStateListener() {

@Override
public void onCallStateChanged(int state, String incomingNumber) {
Log.d("DEBUG", "Phone listener....");
String stateString = "N/A";
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
stateString = "Idle";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
stateString = "Off Hook";
break;
case TelephonyManager.CALL_STATE_RINGING:
stateString = "Ringing";
break;
}
textOut.append(String.format("\nonCallStateChanged: %s",
stateString));
}
};

} catch (Exception e) {

}

}
}

AndroidManifest.xml

-<?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcast" android:versionCode="1"
android:versionName="1.0">
-<application android:icon="@drawable/icon" android:label="@string/app_name">
-<activity android:name=".BroadcastExaple" android:label="@string/app_name">
-<intent-filter>
-<action android:name="android.intent.action.MAIN" />
-<category android:name="android.intent.category.LAUNCHER" />
-</intent-filter>
-</activity>
--</application>
-<uses-prmission android:name="android.permission.READ_PHONE_STATE" />
-<uses-sdk android:minSdkVersion="7" />
-</manifest>

最佳答案

Listener是使用后创建的。

关于android - PhoneStateListener 不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4378260/

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