मैं एक incomming कॉल प्रसारण पकड़ने की कोशिश कर रहा हूँ, लेकिन यह काम नहीं कर रहा रिसीवर।इनकमिंग कॉल प्रसारण (Android 4.1) काम नहीं कर रहा
यह मेरा प्रकट है:
<?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.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);
}
}
और श्रोता है ..
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 के साथ एक और फोन के साथ की कोशिश की और यह वहाँ काम किया, लेकिन पहले डिवाइस पर (Android 4.1) यह काम नहीं किया। यह क्यों हो सकता है?
'Log.v (" onCallStateChanged "," फोन राज्य निष्क्रिय ") करने के लिए कोशिश;' और logcat जाँच क्योंकि शायद संभव संदर्भ आप टोस्ट दिखाने के लिए उपयोग कर रहे हैं उपलब्ध –
नहीं है मदद नहीं की कि .. मैंने किया ध्यान दें कि यह एंड्रॉइड 2.3.6 पर काम करता है लेकिन एंड्रॉइड 4.1 पर नहीं, कोई विचार? –