Skip to content

Commit

Permalink
Launch service on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
vladholubiev committed Feb 14, 2015
1 parent 2dcb710 commit b7ce48f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<uses-sdk tools:overrideLibrary="com.balysv.materialripple, com.dd.circular.progress.button"/>

Expand All @@ -24,6 +25,11 @@
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name=".BootCompletedIntentReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ua.samosfator.moduleok;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import ua.samosfator.moduleok.notification.ScoreCheckerService;

public class BootCompletedIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (!App.isServiceRunning(ScoreCheckerService.class) && Auth.isLoggedIn()) {
context.startService(new Intent(context, ScoreCheckerService.class));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static void sendTotalScoreOnStart() {
try {
sendTotalScore();

Toast.makeText(App.getContext(), "Faculty total score: " + rating.getTotalScore() + "↑", Toast.LENGTH_SHORT).show();
// Toast.makeText(App.getContext(), "Faculty total score: " + rating.getTotalScore() + "↑", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();

Toast.makeText(App.getContext(), "Failed to send total score", Toast.LENGTH_SHORT).show();
// Toast.makeText(App.getContext(), "Failed to send total score", Toast.LENGTH_SHORT).show();
}
Log.d(TOTAL_SCORE_KEY, "first launch - send total score");
}
Expand Down Expand Up @@ -58,12 +58,12 @@ public static void sendTotalScoreOnRefresh() {
sendTotalScore();
Preferences.save("lastSendFailed", "false");

Toast.makeText(App.getContext(), "Faculty total score: " + scoreDifference + " ↑", Toast.LENGTH_SHORT).show();
// Toast.makeText(App.getContext(), "Faculty total score: " + scoreDifference + " ↑", Toast.LENGTH_SHORT).show();
Log.d(TOTAL_SCORE_KEY, "send - total scores differ: " + previousScore + " / " + rating.getTotalScore());
} catch (IOException e) {
Preferences.save("lastSendFailed", "true");

Toast.makeText(App.getContext(), "Failed to send total score", Toast.LENGTH_SHORT).show();
// Toast.makeText(App.getContext(), "Failed to send total score", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else {
Expand Down

0 comments on commit b7ce48f

Please sign in to comment.