Quick Links: Downloads, Wiki, Support, Translations, Contributing, Research Paper, Project Website
Developer's App Requirements:
slinger-dev.appspot.com
Modify your AndroidManifest.xml
to include required permissions.
...
<uses-permission android:name="android.permission.INTERNET" />
...
Modify your AndroidManifest.xml
to include required activities.
...
<!-- we must include all activities declared by library manifests as well: -->
<activity
android:name="edu.cmu.cylab.starslinger.exchange.ExchangeActivity"
android:label="@string/lib_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="edu.cmu.cylab.starslinger.exchange.GroupingActivity"
android:label="@string/lib_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="edu.cmu.cylab.starslinger.exchange.VerifyActivity"
android:label="@string/lib_name"
android:screenOrientation="portrait" >
</activity>
...
Modify your Activity
that starts the exchange to import Bundle
string extras for convenience and to avoid potential refactoring of names in future versions of the library.
...
import edu.cmu.cylab.starslinger.exchange.ExchangeActivity;
import edu.cmu.cylab.starslinger.exchange.ExchangeConfig;
public class MainActivity extends Activity {
private static final int RESULT_EXCHANGE = 1;
...
Call the ExchangeActivity
with required extras USER_DATA
and HOST_NAME
. The UX will ask for the number of users, grouping number, and 3-word phrase.
private void beginExchange(String hostName, byte[] mySecret) {
Intent intent = new Intent(getActivity(), ExchangeActivity.class);
intent.putExtra(ExchangeConfig.extra.USER_DATA, mySecret);
intent.putExtra(ExchangeConfig.extra.HOST_NAME, hostName);
startActivityForResult(intent, RESULT_EXCHANGE);
}
Optionally, you may pass in the number of users using the NUM_USERS
extra. The UX will ask for the grouping number and 3-word phrase only.
private void beginExchange(String hostName, byte[] mySecret, int numUsersIn) {
Intent intent = new Intent(getActivity(), ExchangeActivity.class);
intent.putExtra(ExchangeConfig.extra.USER_DATA, mySecret);
intent.putExtra(ExchangeConfig.extra.HOST_NAME, hostName);
intent.putExtra(ExchangeConfig.extra.NUM_USERS, numUsersIn);
startActivityForResult(intent, RESULT_EXCHANGE);
}
Handle the ExchangeActivity
results.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case RESULT_EXCHANGE:
switch (resultCode) {
case ExchangeActivity.RESULT_EXCHANGE_OK:
// use newly exchanged data from 'theirSecrets'
ArrayList<byte[]> theirSecrets = endExchange(data);
// ...
break;
case ExchangeActivity.RESULT_EXCHANGE_CANCELED:
// handle canceled result
// ...
break;
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private static ArrayList<byte[]> endExchange(Intent data) {
ArrayList<byte[]> theirSecrets = new ArrayList<byte[]>();
Bundle extras = data.getExtras();
if (extras != null) {
byte[] d = null;
int i = 0;
do {
d = extras.getByteArray(ExchangeConfig.extra.MEMBER_DATA + i);
if (d != null) {
theirSecrets.add(d);
i++;
}
} while (d != null);
}
return theirSecrets;
}
The MIT License (MIT)
Copyright (c) 2010-2015 Carnegie Mellon University
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.