我创建了一个应用程序来调用警报管理器,每隔1小时重复一次任务,当警报管理器被触发时,我还有其他功能来接收警报管理器。
public void onReceive(Context context, Intent intent) {
loadClassFromAsp();
if (MainActivity.gCountBook >= 1) {
MyNotificationScheduler.showNotification(context, Access.class, "Class Reminder !!", "Don't miss your class on next hour !!");
}
}
public void loadClassFromAsp() {
String Url;
Uri.Builder builder = new Uri.Builder();
builder.scheme("")
.authority("192.168.0.28")
.appendPath("sfitness")
.appendPath("apps")
.appendPath("checkBooking.asp");
Url = builder.build().toString();
MyNotificationReceiver.getBook task = new MyNotificationReceiver.getBook();
task.execute(Url);
}
在uri构建器上,我还有一个AsynTask函数
private class getBook extends AsyncTask<String, Void, Void> {
private String responseString = null;
//private ProgressDialog dialog = new ProgressDialog(getContext());
protected void onPreExecute() {
}
protected Void doInBackground(String... urls) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(Url);
//From this place onwards, my program end and pop error
try {
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
responseString = str.toString();
} catch (ClientProtocolException e) {
responseString = "Error! Client Protocol Exception";
} catch (IOException e) {
responseString = "Please Login Check your Internet connection."; //No Internet Access!
}
return null;
}
protected void onPostExecute(Void unused) {
if (responseString != null) {
String sGetString = responseString.substring(0, responseString.indexOf("|"));
String sGet = responseString.toString();
MainActivity.gCountBook = Integer.parseInt(sGetString);
List classBook = new ArrayList<String>();
for (int i = 0; i < MainActivity.gCountBook; i++) {
sGet = sGet.substring(sGet.indexOf("|") + 1, sGet.length());
String data = sGet.substring(0, sGet.indexOf("|"));
}
}
}
}
在我的AsynTask函数上,在HttpGet之后进入try,我的应用程序弹出并说“不幸的是,你的应用已停止了#34;这是我从调试器得到的。没有错误,没有错误。每次我的应用程序运行,直到try语句自动弹出。有人知道解决方案吗?我不明白为什么。
我有类似的功能,在其他类中完成,该功能运行完美我不知道里面的问题是什么。我也在我的清单中添加了接收器。
谢谢,如果您需要我更新,请告诉我。谢谢!!