-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostsRetrieveService.java
More file actions
78 lines (66 loc) · 2.55 KB
/
Copy pathpostsRetrieveService.java
File metadata and controls
78 lines (66 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.example.brand.yambrand;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import java.util.List;
import winterwell.jtwitter.Twitter;
public class postsRetrieveService extends Service {
PostsDBManager db = new PostsDBManager(this);
private static final String TAG = "StatusActivity";
private boolean FLAG = true;
Twitter twitter;
public postsRetrieveService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
// The service is being created
Log.d(TAG, "Service Created");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// The service is starting, due to a call to startService()
//twitter.getFriendsTimeline();
Log.d(TAG, "Service Started");
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String strUserName = SP.getString("username", "NA");
String strPassword= SP.getString("password", "NA");
String strApiUrl= SP.getString("apiurl", "NA");
twitter = new Twitter(strUserName, strPassword);
twitter.setAPIRootUrl(strApiUrl);
Thread thread=new Thread(new retrieveThread());
thread.start();
return 0;
//twitter.getFriendsTimeline();
//return mStartMode;
}
@Override
public void onDestroy() {
Log.d(TAG, "Service Stopped");
FLAG=false;
}
class retrieveThread extends Thread {
@Override
public void run()
{ // Moves the current Thread into the background
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
while (FLAG==true)
{
List<Twitter.Status> statuses = twitter.getFriendsTimeline();
for (Twitter.Status status : statuses) {
//System.out.println(status.getId() + ":" + status.getCreatedAt() + ":" + status.getText() + ":" + status.getUser().getScreenName());
db.insertPosts(status);
}
try{sleep(3000);
}catch(InterruptedException ex){}
}
}
}
}