Skip to content
Snippets Groups Projects
Commit de0f87c3 authored by Zohaib Butt's avatar Zohaib Butt
Browse files

DONEgit add .!

parent 49fd07fe
No related branches found
No related tags found
No related merge requests found
......@@ -23,12 +23,6 @@
<activity android:name=".A3" />
<activity android:name=".A2"/>
<receiver android:name=".A1$taskDoneReceiver">
<intent-filter>
<action android:name="Task_Done_Listener" />
</intent-filter>
</receiver>
<receiver android:name=".AlarmReceiver">
<intent-filter>
<action android:name="ACTION_ALARM_RECEIVER" />
......@@ -36,7 +30,7 @@
</receiver>
<service android:name=".BackgroundThread"
android:exported="false"
android:exported="true"
android:enabled="true"/>
</application>
......
......@@ -100,10 +100,10 @@ public class A1 extends AppCompatActivity {
startActivityForResult(intent, GET_RESULT);
} else { // else url is specified and Rss feeds can be fetched
Intent i = new Intent(this, BackgroundThread.class);
i.putStringArrayListExtra(TAG_TITLE_LIST, titles);
/* i.putStringArrayListExtra(TAG_TITLE_LIST, titles);
i.putStringArrayListExtra(TAG_LINKS_LIST, links);
i.putStringArrayListExtra(TAG_DESC_LIST, description);
i.putExtra(FREQ_VAL, freq);
i.putExtra(FREQ_VAL, freq); */
startService(i);
Log.i("Service_running", "service is running!!");
}
......@@ -190,10 +190,10 @@ public class A1 extends AppCompatActivity {
}// else { // else start the service to fetch RSS
Intent i = new Intent(this, BackgroundThread.class);
i.putStringArrayListExtra(TAG_TITLE_LIST, titles);
/* i.putStringArrayListExtra(TAG_TITLE_LIST, titles);
i.putStringArrayListExtra(TAG_LINKS_LIST, links);
i.putStringArrayListExtra(TAG_DESC_LIST, description);
i.putExtra(FREQ_VAL, freq);
i.putExtra(FREQ_VAL, freq); */
startService(i);
Log.i("Service_running", "service is running!!");
// }
......
......@@ -4,6 +4,7 @@ package com.example.zohaibbutt.lab02;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
......@@ -19,22 +20,30 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import static com.example.zohaibbutt.lab02.A1.SETTING_VAL;
import static com.example.zohaibbutt.lab02.A1.TAG_DESC_LIST;
import static com.example.zohaibbutt.lab02.A1.TAG_LINKS_LIST;
import static com.example.zohaibbutt.lab02.A1.TAG_TITLE_LIST;
import static com.example.zohaibbutt.lab02.A1.requestURL;
import static com.example.zohaibbutt.lab02.A1.URL_VAL;
import static com.example.zohaibbutt.lab02.BackgroundThread.ACTION_ALARM_RECEIVER;
import static com.example.zohaibbutt.lab02.BackgroundThread.db;
import static com.example.zohaibbutt.lab02.BackgroundThread.dsc;
import static com.example.zohaibbutt.lab02.BackgroundThread.lnk;
import static com.example.zohaibbutt.lab02.BackgroundThread.ttl;
public class AlarmReceiver extends BroadcastReceiver {
public ArrayList<String> ttl = new ArrayList<>();
public ArrayList<String> lnk = new ArrayList<>();
public ArrayList<String> dsc = new ArrayList<>();
private SharedPreferences settings;
private String requestURL = null;
@Override
public void onReceive(Context arg0, Intent arg1) {
if (arg1 != null) {
if (ACTION_ALARM_RECEIVER.equals(arg1.getAction())) {
Log.i("Alarm_Receiver", "in OnReceive!!");
db = new DBHandler(arg0, null, null, 1);
this.settings = arg0.getSharedPreferences(SETTING_VAL, Context.MODE_PRIVATE);
requestURL = settings.getString(URL_VAL, "");
// empty array lists
if (ttl != null && lnk != null && dsc != null) {
......@@ -42,6 +51,8 @@ public class AlarmReceiver extends BroadcastReceiver {
ttl.clear();
lnk.clear();
dsc.clear();
} else {
Log.i("Lists_NULL", "lists are null");
}
// Set the alarm here.
......@@ -54,9 +65,6 @@ public class AlarmReceiver extends BroadcastReceiver {
Intent i = new Intent();
i.putExtra("TAG_VALUE", 20);
i.putStringArrayListExtra(TAG_TITLE_LIST, ttl);
i.putStringArrayListExtra(TAG_LINKS_LIST, lnk);
i.putStringArrayListExtra(TAG_DESC_LIST, dsc);
......@@ -114,6 +122,7 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override
protected final Exception doInBackground(ArrayList<String>... lists) {
try {
Log.i("URL_RESQUEST", ""+requestURL);
URL url = new URL(requestURL);
XmlPullParserFactory fact = XmlPullParserFactory.newInstance();
......@@ -177,6 +186,7 @@ public class AlarmReceiver extends BroadcastReceiver {
}
} catch (MalformedURLException e) {
exception = e;
e.printStackTrace();
Log.e("MALFORMED_URL_EXCEPTION", e.toString());
} catch (IOException e) {
exception = e;
......
......@@ -5,15 +5,19 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
import java.util.ArrayList;
import static com.example.zohaibbutt.lab02.A1.FREQ_VAL;
import static com.example.zohaibbutt.lab02.A1.LIMIT_VAL;
import static com.example.zohaibbutt.lab02.A1.SETTING_VAL;
import static com.example.zohaibbutt.lab02.A1.TAG_DESC_LIST;
import static com.example.zohaibbutt.lab02.A1.TAG_LINKS_LIST;
import static com.example.zohaibbutt.lab02.A1.TAG_TITLE_LIST;
import static com.example.zohaibbutt.lab02.A1.URL_VAL;
// Service that send broadcast to alarm receiver at the specified interval.
......@@ -26,16 +30,21 @@ public class BackgroundThread extends Service {
private AlarmManager alarmManager;
private PendingIntent alarmIntent;
public static final String ACTION_ALARM_RECEIVER = "ACTION_ALARM_RECEIVER";
private SharedPreferences settings;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// get all the data from intent
lnk = intent.getStringArrayListExtra(TAG_LINKS_LIST);
/* lnk = intent.getStringArrayListExtra(TAG_LINKS_LIST);
ttl = intent.getStringArrayListExtra(TAG_TITLE_LIST);
dsc = intent.getStringArrayListExtra(TAG_DESC_LIST);
frq = intent.getIntExtra(FREQ_VAL, 0);
frq = intent.getIntExtra(FREQ_VAL, 0);*/
// Shared Preferences
this.settings = getSharedPreferences(SETTING_VAL, Context.MODE_PRIVATE);
// Get the shared preferences
this.frq = settings.getInt(FREQ_VAL, 0);
db = new DBHandler(this, null, null, 1);
Log.i("Service_onStartCommand", "Service is onStartCommand!!");
......@@ -48,7 +57,7 @@ public class BackgroundThread extends Service {
this.alarmIntent = PendingIntent.getBroadcast(this, 0, i, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 500,
1000 * 60 * frq, alarmIntent);
Log.i("Alarm_set", "Alarm set!");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment