我正在开发一个应用程序,该应用程序将阻止特定时间段内的所有呼叫,但是在执行该应用程序时遇到了一些问题,它没有阻止任何呼叫。因此,请告诉我代码中的问题是什么,它阻止了呼叫,但没有阻止特定时间..我正在发布代码。
public class Pervasive_2Activity extends Activity {
/** Called when the activity is first created. */
private PhoneCallReceiver1 action;
int hours;
int minutes;
int seconds;
int hour1;
int minutes1;
int hour2;
int minutes2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
action= new PhoneCallReceiver1();
Date dt = new Date();
hours = dt.getHours();
minutes = dt.getMinutes();
seconds = dt.getSeconds();
Button OK = (Button) findViewById(R.id.widget39);
OK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TimePicker tp1 = (TimePicker)findViewById(R.id.timePicker1);
hour1 = tp1.getCurrentHour();
minutes1 =tp1.getCurrentMinute();
TimePicker tp2 = (TimePicker)findViewById(R.id.timePicker2);
hour2 = tp2.getCurrentHour();
minutes2 =tp2.getCurrentMinute();
}
});
if((hours>hour1 && hours<hour2)&& (minutes>minutes1 && minutes<minutes2))
{
Context context = this.getApplicationContext();
Intent intent = this.getIntent();
action.onReceive(context, intent);
}
}
}
2级
public class PhoneCallReceiver1 extends BroadcastReceiver {
Context context = null;
private static final String TAG = "Phone call";
private ITelephony telephonyService;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving....");
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
try {
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
telephonyService = (ITelephony) m.invoke(telephony);
// telephonyService.silenceRinger();
telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
}
}
}
3级
public interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
void call(String number);
}
最佳答案
尝试输入您的登录名
try{
// First block call here
for(int i=0;i<10;i++){
Thread.sleep(1000);
}
// after 10 seconds unblock call here
}catch(Exception e){
}
希望以上代码对您有帮助...