我对android很新。我开发了一个应用程序文本关闭。它可以顺利地用于4.2或更低版本,但它的文本块功能不适用于kitkat,并且在一次响铃后也可以调用disconnect。我完全是黑人,我是做什么的。我正在使用以下代码。
<{1}} 中的权限
AndroidManifest.xml
BroadcastReceiver服务
TextOffService.java
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
ServiceReciever.java
registerReceiver(service, new IntentFilter(
"android.intent.action.PHONE_STATE"));
registerReceiver(service, new IntentFilter(
"android.intent.action.NEW_OUTGOING_CALL"));
IntentFilter intentSMS = new IntentFilter(
"android.provider.Telephony.SMS_RECEIVED");
intentSMS.setPriority(2147483647);
registerReceiver(sms, intentSMS);
DeviceStateListener.java
public class ServiceReciever extends BroadcastReceiver
{
private static TelephonyManager telephony;
private static DeviceStateListener phoneListener;
private static boolean firstTime=true;
public ServiceReciever(Context context)
{
telephony=(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
phoneListener=new DeviceStateListener(context);
}
@Override
public void onReceive(Context context, Intent intent)
{
DeviceStateListener.outgoing = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if(firstTime)
{
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
firstTime=false;
}
}
public void stopListening()
{
telephony.listen(phoneListener, PhoneStateListener.LISTEN_NONE);
firstTime=true;
}
}
SmsReceiver.java
public class DeviceStateListener extends PhoneStateListener {
private ITelephony telephonyService;
public DeviceStateListener(Context context) {
super();
this.context = context;
initializeTelephonyService();
}
private void initializeTelephonyService() {
try {
TelephonyManager telephonyManager = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
Class clase = Class.forName(telephonyManager.getClass().getName());
Method method = clase.getDeclaredMethod("getITelephony");
method.setAccessible(true);
telephonyService = (ITelephony) method.invoke(telephonyManager);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onCallStateChanged(int state, final String incomingNumber) {
final String android_id = Secure.getString(context
.getApplicationContext().getContentResolver(),
Secure.ANDROID_ID);
super.onCallStateChanged(state, incomingNumber.replace("+", ""));
switch (state) {
case TelephonyManager.CALL_STATE_OFFHOOK:
BlackoutPopUp();
if (outgoing !=null &&!outgoing.equals("911")) {
telephonyService.endCall();
}
break;
case TelephonyManager.CALL_STATE_RINGING:
telephonyService.endCall();
break;
}
}
}
请帮帮我。 感谢