incomming 통화 브로드 캐스트를 수신하려고하지만 작동하지 않습니다. 수신 전화 브로드 캐스트 리시버가 작동하지 않음 (Android 4.1)
이
내 매니페스트입니다 : 이것은 내 방송 수신기package com.test.bgPicture;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
public class PhoneStateBroadcastReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
}
}
그리고 청취자가
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.bgPicture"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.front"
android:required="false" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
<receiver android:name=".PhoneStateBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
입니다 ..
package com.test.bgPicture;
import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class CustomPhoneStateListener extends PhoneStateListener {
//private static final String TAG = "PhoneStateChanged";
Context context; //Context to make Toast if required
public CustomPhoneStateListener(Context context) {
super();
this.context = context;
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
//when Idle i.e no call
Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//when Off hook i.e in call
//Make intent and start your service here
Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
//when Ringing
Toast.makeText(context, "Phone state Ringing", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}
하지만 토스트는 아니다 표시됨, 그럴 생각이야?
편집 : 안드로이드 2.3.6을 사용하는 다른 휴대 전화로 시도해 보았지만 거기에서 작동했지만 첫 번째 장치 (안드로이드 4.1)에서는 작동하지 않았습니다. 왜 이럴 수 있니?
Log.v ("onCallStateChanged", "전화 상태 유휴")'을 시도,'당신이 토스트를 보여주는에 사용하는 어쩌면 가능한 상황 도움이되지 않았다 –
사용할 수 없기 때문에 로그 캣을 확인 .. 내가 그랬어 그것이 안드로이드 2.3.6에서 작동하지만 안드로이드 4.1, 어떤 생각에 안된다는 통지? –