This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.Reader; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpGet; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.json.JSONObject; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getMaxID() { | |
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); | |
return sp.getString("MaxID", ""); | |
} | |
private void setMaxID(String maxID) { | |
if (maxID != null) { | |
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); | |
SharedPreferences.Editor editor = sp.edit(); | |
editor.putString("MaxID", maxID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Boolean newTweet() { | |
Boolean result = false; | |
String oldMaxID = getMaxID(); | |
String newMaxID = oldMaxID; | |
HttpClient httpClient; | |
HttpGet getMethod; | |
HttpResponse response; | |
InputStream responseStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected JSONObject doWork() { | |
if (newTweet()) | |
Log.d(TAG, "New Tweet - I'll need to send a notification"); | |
else | |
Log.d(TAG, "No new Tweets, back to sleep I go"); | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void showNotification( String contentTitle, String contentText ) { | |
int icon = R.drawable.ic_stat_notification; | |
long when = System.currentTimeMillis(); | |
Notification notification = new Notification(icon, contentTitle, when); | |
notification.flags |= Notification.FLAG_AUTO_CANCEL; | |
Intent notificationIntent = new Intent(this, TwitterExampleActivity.class); | |
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected JSONObject doWork() { | |
if (newTweet()) { | |
Log.d(TAG, "New Tweet - I'll need to send a notification"); | |
showNotification("New Tweet","Click to open"); | |
} else | |
Log.d(TAG, "No new Tweets, back to sleep I go"); | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.red_folder.sample; | |
import org.json.JSONObject; | |
import com.red_folder.phonegap.plugin.backgroundservice.BackgroundService; | |
public class TwitterService extends BackgroundService { | |
@Override | |
protected JSONObject doWork() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final String TAG = TwitterService.class.getSimpleName(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected JSONObject doWork() { | |
// TODO Auto-generated method stub | |
Log.d(TAG, "This is doWork()"); | |
return null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<service android:name="com.red_folder.sample.TwitterService"> | |
<intent-filter> | |
<action android:name="com.red_folder.sample.TwitterService"/> | |
</intent-filter> | |
</service> |
OlderNewer