use of android.app.AlarmManager in project Android-Error-Reporter by tomquist.
the class ExceptionReportService method sendReport.
private void sendReport(Intent intent) throws UnsupportedEncodingException, NameNotFoundException {
Log.v(TAG, "Got request to report error: " + intent.toString());
Uri server = getTargetUrl();
boolean isManualReport = intent.getBooleanExtra(EXTRA_MANUAL_REPORT, false);
boolean isReportOnFroyo = isReportOnFroyo();
boolean isFroyoOrAbove = isFroyoOrAbove();
if (isFroyoOrAbove && !isManualReport && !isReportOnFroyo) {
// We don't send automatic reports on froyo or above
Log.d(TAG, "Don't send automatic report on froyo");
return;
}
Set<String> fieldsToSend = getFieldsToSend();
String stacktrace = intent.getStringExtra(EXTRA_STACK_TRACE);
String exception = intent.getStringExtra(EXTRA_EXCEPTION_CLASS);
String message = intent.getStringExtra(EXTRA_MESSAGE);
long availableMemory = intent.getLongExtra(EXTRA_AVAILABLE_MEMORY, -1l);
long totalMemory = intent.getLongExtra(EXTRA_TOTAL_MEMORY, -1l);
String dateTime = intent.getStringExtra(EXTRA_EXCEPTION_TIME);
String threadName = intent.getStringExtra(EXTRA_THREAD_NAME);
String extraMessage = intent.getStringExtra(EXTRA_EXTRA_MESSAGE);
List<NameValuePair> params = new ArrayList<NameValuePair>();
addNameValuePair(params, fieldsToSend, "exStackTrace", stacktrace);
addNameValuePair(params, fieldsToSend, "exClass", exception);
addNameValuePair(params, fieldsToSend, "exDateTime", dateTime);
addNameValuePair(params, fieldsToSend, "exMessage", message);
addNameValuePair(params, fieldsToSend, "exThreadName", threadName);
if (extraMessage != null)
addNameValuePair(params, fieldsToSend, "extraMessage", extraMessage);
if (availableMemory >= 0)
addNameValuePair(params, fieldsToSend, "devAvailableMemory", availableMemory + "");
if (totalMemory >= 0)
addNameValuePair(params, fieldsToSend, "devTotalMemory", totalMemory + "");
PackageManager pm = getPackageManager();
try {
PackageInfo packageInfo = pm.getPackageInfo(getPackageName(), 0);
addNameValuePair(params, fieldsToSend, "appVersionCode", packageInfo.versionCode + "");
addNameValuePair(params, fieldsToSend, "appVersionName", packageInfo.versionName);
addNameValuePair(params, fieldsToSend, "appPackageName", packageInfo.packageName);
} catch (NameNotFoundException e) {
}
addNameValuePair(params, fieldsToSend, "devModel", android.os.Build.MODEL);
addNameValuePair(params, fieldsToSend, "devSdk", android.os.Build.VERSION.SDK);
addNameValuePair(params, fieldsToSend, "devReleaseVersion", android.os.Build.VERSION.RELEASE);
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(server.toString());
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
Log.d(TAG, "Created post request");
try {
httpClient.execute(post);
Log.v(TAG, "Reported error: " + intent.toString());
} catch (ClientProtocolException e) {
// Ignore this kind of error
Log.e(TAG, "Error while sending an error report", e);
} catch (SSLException e) {
Log.e(TAG, "Error while sending an error report", e);
} catch (IOException e) {
if (e instanceof SocketException && e.getMessage().contains("Permission denied")) {
Log.e(TAG, "You don't have internet permission", e);
} else {
int maximumRetryCount = getMaximumRetryCount();
int maximumExponent = getMaximumBackoffExponent();
// Retry at a later point in time
AlarmManager alarmMgr = (AlarmManager) getSystemService(ALARM_SERVICE);
int exponent = intent.getIntExtra(EXTRA_CURRENT_RETRY_COUNT, 0);
intent.putExtra(EXTRA_CURRENT_RETRY_COUNT, exponent + 1);
PendingIntent operation = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
if (exponent >= maximumRetryCount) {
// Discard error
Log.w(TAG, "Error report reached the maximum retry count and will be discarded.\nStacktrace:\n" + stacktrace);
return;
}
if (exponent > maximumExponent) {
exponent = maximumExponent;
}
// backoff in ms
long backoff = (1 << exponent) * 1000;
alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + backoff, operation);
}
}
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class TrimDataService method setNextTrim.
public void setNextTrim(Context context) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + AlarmManager.INTERVAL_DAY;
Log.v("alarm_date", "auto trim " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, TRIM_ID, new Intent(context, TrimDataService.class), 0);
am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class BootReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
AppSettings settings = AppSettings.getInstance(context);
if (settings.timelineRefresh != 0) {
// user only wants manual
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + settings.timelineRefresh;
Log.v("alarm_date", "timeline " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, HomeFragment.HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent);
}
if (settings.mentionsRefresh != 0) {
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + settings.mentionsRefresh;
Log.v("alarm_date", "mentions " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, MentionsFragment.MENTIONS_REFRESH_ID, new Intent(context, MentionsRefreshService.class), 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.mentionsRefresh, pendingIntent);
}
if (settings.dmRefresh != 0) {
// user only wants manual
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + settings.dmRefresh;
Log.v("alarm_date", "dircet message " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, DMFragment.DM_REFRESH_ID, new Intent(context, DirectMessageRefreshService.class), 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.dmRefresh, pendingIntent);
}
if (settings.activityRefresh != 0) {
// user only wants manual
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + settings.activityRefresh;
Log.v("alarm_date", "activity " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, ActivityFragment.ACTIVITY_REFRESH_ID, new Intent(context, ActivityRefreshService.class), 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.activityRefresh, pendingIntent);
}
if (settings.autoTrim) {
// user only wants manual
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long alarm = now + 1000 * 60;
Log.v("alarm_date", "auto trim " + new Date(alarm).toString());
PendingIntent pendingIntent = PendingIntent.getService(context, TRIM_ID, new Intent(context, TrimDataService.class), 0);
am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
}
if (settings.pushNotifications) {
context.startService(new Intent(context, CatchupPull.class));
}
ArrayList<ScheduledTweet> tweets = QueuedDataSource.getInstance(context).getScheduledTweets();
for (ScheduledTweet s : tweets) {
Intent serviceIntent = new Intent(context.getApplicationContext(), SendScheduledTweet.class);
Log.v("talon_scheduled_tweets", "in boot text: " + s.text);
serviceIntent.putExtra(ViewScheduledTweets.EXTRA_TEXT, s.text);
serviceIntent.putExtra("account", s.account);
serviceIntent.putExtra("alarm_id", s.alarmId);
PendingIntent pi = getDistinctPendingIntent(serviceIntent, s.alarmId);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, s.time, pi);
}
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class ConnectivityChangeReceiver method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
Log.v("talon_pull", "connectivity change: just starting receiver");
AppSettings settings = AppSettings.getInstance(context);
// we don't want to do anything here if talon pull isn't on
if (!settings.pushNotifications) {
Log.v("talon_pull", "connectivity change: stopping the receiver very early");
return;
}
if (Utils.hasInternetConnection(context)) {
Log.v("talon_pull", "connectivity change: network is available and talon pull is on");
// we want to turn off the live streaming/talon pull because it is just wasting battery not working/looking for connection
context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = Calendar.getInstance().getTimeInMillis();
// schedule it to begin in 1 min
long alarm = now + 60000;
PendingIntent pendingIntent = PendingIntent.getService(context, 236, new Intent(context, CatchupPull.class), 0);
// cancel the old one, then start the new one in 1 min
am.cancel(pendingIntent);
am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
} else {
Log.v("talon_pull", "connectivity change: network not available but talon pull is on");
// we want to turn off the live streaming/talon pull because it is just wasting battery not working/looking for connection
context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
}
}
use of android.app.AlarmManager in project Talon-for-Twitter by klinker24.
the class QueueTweets method onReceive.
@Override
public void onReceive(final Context context, final Intent intent) {
Log.v("talon_queued", "connectivity change: just starting receiver");
AppSettings settings = AppSettings.getInstance(context);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = Calendar.getInstance().getTimeInMillis();
// schedule it to begin in 20 seconds
long alarm = now + 10000;
PendingIntent pendingIntent = PendingIntent.getService(context, 253, new Intent(context, SendQueue.class), 0);
// cancel the old one, then start the new one in 1 min
am.cancel(pendingIntent);
if (Utils.hasInternetConnection(context) && QueuedDataSource.getInstance(context).getQueuedTweets(settings.currentAccount).length > 0) {
Log.v("talon_queued", "setting alarm for queue");
am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent);
}
}
Aggregations