Android PhoneStateListener不';不打电话
这是我的全部代码 BroadcastExample.java AndroidManifest.xmlAndroid PhoneStateListener不';不打电话,android,android-emulator,phone-state-listener,Android,Android Emulator,Phone State Listener,这是我的全部代码 BroadcastExample.java AndroidManifest.xml - - - - - - - - - -- - - - 监听器是在使用后创建的。上述程序不起作用…..请查找是否有任何错误…@user533863:如果您不打算花时间解释“不起作用”,很少有人会花时间随机猜测什么“不起作用”.好的..上面的程序没有进入phonestatelistener..这就是我发现的。。。。。 package com.example.broadcast; > im
-
-
-
-
-
-
-
-
-
--
-
-
-
监听器是在使用后创建的。上述程序不起作用…..请查找是否有任何错误…@user533863:如果您不打算花时间解释“不起作用”,很少有人会花时间随机猜测什么“不起作用”.好的..上面的程序没有进入phonestatelistener..这就是我发现的。。。。。
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) {
}
}
}
-<?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>