Skip to content

Commit

Permalink
Merge pull request #138 from morgenroth/Whisper-activate-presence-gen…
Browse files Browse the repository at this point in the history
…erator

Whisper: Activate presence generator on boot or if the app has been replaced
  • Loading branch information
morgenroth committed Jan 4, 2015
2 parents 6b4616a + 8e98a9c commit fe47287
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions android/Whisper/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<uses-permission android:name="de.tubs.ibr.dtn.permission.DTN_COMMUNICATION"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -52,6 +53,12 @@
<action android:name="de.tubs.ibr.dtn.intent.STATUS_REPORT" />
<category android:name="de.tubs.ibr.dtn.chat" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver android:enabled="true" android:name=".service.NotificationReceiver" android:exported="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class EventReceiver extends BroadcastReceiver {

Expand All @@ -47,5 +49,24 @@ else if (action.equals(de.tubs.ibr.dtn.Intent.STATUS_REPORT))
i.putExtra("bundleid", intent.getParcelableExtra("bundleid"));
context.startService(i);
}
else if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction()) ||
Intent.ACTION_MY_PACKAGE_REPLACED.equals(intent.getAction()))
{
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String desired = prefs.getString("presencetag", "unavailable");

if (desired.equals("unavailable")) {
// deactivate presence generator
PresenceGenerator.deactivate(context);
} else {
// activate presence generator
PresenceGenerator.activate(context);

// send initial presence
Intent presenceIntent = new Intent(context, ChatService.class);
presenceIntent.setAction(ChatService.ACTION_PRESENCE_ALARM);
context.startService(presenceIntent);
}
}
}
}

0 comments on commit fe47287

Please sign in to comment.