【发布时间】:2014-08-25 18:32:40
【问题描述】:
我正在开发一个应用程序,它会在特定时间段内阻止所有呼叫,但是在执行此应用程序时遇到了一些问题,它不会阻止任何呼叫。所以请告诉我我的代码有什么问题,它正在阻塞调用,但不是在特定时间..我正在发布我的代码。
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);
}
【问题讨论】:
标签: java android timer phone-call