Samplers is a framework to build mobile citizen science applications.
-
Create a new empty Android Studio project (without any activity)
- The Minimun SDK Version must be API17: Android 4.2 (Jelly Bean)
-
Import the framework library into your Android Studio project
- Download the latest samplersFramework.aar from here
- Import the library into the project: File -> New -> New Module -> Import .JAR/.AAR Package
-
Add the google repository
- On your project build.gradle
allprojects { repositories { jcenter() google() } }
- On your project build.gradle
-
Add the necessary dependencies
- On your application build.gradle
dependencies { // here the standards dependencies created by Android Studio // ... // if not added automatically, add this dependency // you should use the latest version e.j. 25.+ compile 'com.android.support:design:24.2.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' // if you will use maps and location services, add this dependencies (you should use the latest version) compile ('com.google.android.gms:play-services-location:12.0.1') compile ('com.google.android.gms:play-services-maps:12.0.1') // if you will use authentication with Google, add this dependencies (you should use the latest version) compile ('com.google.android.gms:play-services-auth:12.0.1') // the framework dependency compile project(":samplersFramework") }
- On your application build.gradle
Instantiation can be done manually or using gradle class generator.
- Create a Main Activity
-
You can create a class inherited from SamplersMainActivity. You will need to:
- Implement the getWorkflow() method and return the Workflow to pass to the TakeSampleActivity
- Override the onCreate() method and set the NetworkConfiguration:
NetworkConfiguration.setURL("http://192.168.1.10/samplers/upload.php"); NetworkConfiguration.setPARAM_NAME_SAMPLE("sample"); // Optional if you will use authentication NetworkConfiguration.setPARAM_NAME_USER_ID("user_id"); NetworkConfiguration.setPARAM_NAME_AUTHENTICATION_TYPE("authentication_type");
-
You can create your own Main Activity and start the TakeSampleActivity like this:
Workflow workflow = new Workflow(); // ... populate the workflow as desired Intent intent = new Intent(this, TakeSampleActivity.class); intent.putExtra(TakeSampleActivity.EXTRA_WORKFLOW, workflow); startActivity(intent);
-
-
Create a JSON file named SamplersConfig.json
- Format and options available are in the wiki
- To check for sintax problems you can use this JSON validador
- You can use this example SamplersConfig.json file (don't forget to change the app_path and package_name on project section with the application path and package name of your application, the networkConfiguration to successfully send samples, and your Google Maps API KEY if you want to use Location and Maps services)
-
Copy your created JSON file SamplersConfig.json to the root directory of your Android Studio project
-
Download the latest samplers.gradle and samplersclassgenerator.jar files from realeases and and copy them to the root directory of your Android Studio project
-
Link samplers.gradle with your application build.gradle (it will create MyMainSamplersActivity in your project)
- On your application build.gradle add this line at the end
apply from: '../samplers.gradle'
- Save and Sync when asked
- On your application build.gradle add this line at the end
-
Delete (or customize) the auto-generated style.xml file in the res/values directory
-
Run your application
-
Enjoy!