我对android很新。我开发了一个应用程序Text Off.Text Off应用程序阻止了不受欢迎的调用和文本。它可以顺利地用于4.2或更低版本,但它的文本块功能不适用于kitkat 4.4版本和调用断开连接一圈之后。我完全是黑人,我是做什么的。我正在使用以下代码。
这是服务页面代码ServiceReciever.java
package com.rsoft.callListener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
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)
{
if(firstTime)
{
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
firstTime=false;
}
}
public void stopListening()
{
telephony.listen(phoneListener, PhoneStateListener.LISTEN_NONE);
firstTime=true;
}
}
SMS Receiver的此页面
public void onReceive(Context context, Intent intent)
{
this.context=context;
blockSms(intent);
}
public void blockSms(Intent intent)
{
String MSG_TYPE=intent.getAction();
final String android_id = Secure.getString(context.getApplicationContext()
.getContentResolver(), Secure.ANDROID_ID);
// Toast toast = Toast.makeText(context,"SMS Received: "+MSG_TYPE , Toast.LENGTH_LONG);
//toast.show();
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
final SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++)
{
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
//final BlockedContact cn=CallBlockerService.blackList.get(smsMessage[0].getOriginatingAddress());
//final BlockedContact cn=CallBlockerService.blackList.get(android_id);
//if(cn!=null && cn.getName().equals("1")||cn!=null && cn.getName().equals("3"))
final String Status=TextOffService.deviceStatus;
if(Status!=null && Status.equals("1")||Status!=null && Status.equals("3")|| Status != null
&& Status.equals("5"))
{
abortBroadcast();
//final String android_id = Secure.getString(context.getApplicationContext()
//.getContentResolver(), Secure.ANDROID_ID);
Thread t=new Thread(new Runnable()
{
@Override
public void run()
{
DateFormat dateFormat=new SimpleDateFormat("yyyy/MM/dd - HH:mm:ss");
Date date=new Date();
String currentDate=dateFormat.format(date);
//LOG FORMAT --> TITLE;;MESSAGE;;NAME;;NUMBER;;HOUR;;BODYMESSAGE;;SEPARATOR
String message="Text Blocked;;A message from "+smsMessage[0].getOriginatingAddress().replace("+", "")+" was blocked at "+currentDate+";;"+smsMessage[0].getOriginatingAddress().replace("+", "")+";;"+currentDate+";;"+smsMessage[0].getMessageBody().replace("\n", "")+";;\r\n";
sendSmsByManager(smsMessage[0].getOriginatingAddress().toString(),"I can't reply to your text at this time Driving ");
writeInLog(message);
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("DeviceUniqueID",android_id));
params.add(new BasicNameValuePair("MyLog", message));
params.add(new BasicNameValuePair("ContactNo", smsMessage[0].getOriginatingAddress().replace("+", "")));
params.add(new BasicNameValuePair("Created_Date", currentDate));
// getting JSON string from URL
JSONObject json = jsonParser.makeHttpRequest(
url_create_product, "POST", params);
// check log cat for response
Log.d("Create SMS log", json.toString());
}
});
t.start();
}
现在此页面注册接收器CallBlockerService.java
service = new ServiceReciever(getApplicationContext());
sms = new SmsReceiver();
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);
请帮助我如何限制来电和短信
答案 0 :(得分:0)
可以阻止来电的Android的最新版本是Android 2.2
在Android 2.3中,您无法管理来电。
对于阻止呼叫,您应将联系人的语音邮件选项设置为“1”,并提供不存在的语音信箱号码。