Feed on
Posts
Comments

Configuration

Create a new Android project

Create a new Android project (we called it TestSmsViewer) through the classical Android wizard, creating an activity called SmsViewer as the main project Activity.



Adding JaCa-Android library using Android library project dependency

All the JaCa-Andorid sources are contained inside the JaCa-Android-Library folder. This folder is an Android library project ready to be imported in your Eclipse workspace. Import the JaCa-Android-Library project in your workspace (File -> Import -> Existing project into workspace). At this point go to the TestSmsViewer project properties, then choose Android and add a new library project reference that points at the JaCa-Android-Library project previuosly imported. We are now ready to use JaCa-Android classes in our project.



Adding JaCa-Android library not using library project dependency

In the TestSmsViewer project properties add to the build path the jaca-android.jar that you can find inside the JaCa-Android-Library/lib folder.



Add required libraries

Add jason.jar, cartago-jaca-android.jar, c4jason.jar and jaca_android.jar libraries in your project. You can find this libraries inside the JaCa-Android-Library/lib folder.



Create the mas2j

The mas2j is the JaCa-Android configuration file used for initialise the application (for more details see here). For the TestSmsViewer example we create a file example.mas2j (place it inside the jaca.android.example package) with the following content:

MAS test {

    infrastructure: Centralised

    environment: c4jason.CartagoEnvironment

    agents: agent agentArchClass c4jason.CAgentArch;

    aslSourcePath: "jaca/android/example";
}


More generally the mas2j configuration file of a JaCa-Android application is the following:

MAS [project_name] {
	infrastructure: Centralised
	environment: c4jason.CartagoEnvironment [CartagoEnvironmentParameters]
	agents:
		[agent_name1] agentArchClass c4jason.CAgentArch;
		[agent_name2] agentArchClass c4jason.CAgentArch;
		....
	aslSourcePath: "[asl package path]";
}

The mas2j file defines the underlying infrastructure that has been chosen for that project (Centralised), the class that implements the environment (c4jason.CartagoEnvironment [CartagoEnvironmentParameters] for a complete overview of the possible parameter take a look here), and the agents (agentArchClass c4jason.CAgentArch) that belong to the application.

Finishing the configuration

Add a string resource in res/values/string.xml pointing at the mas2j just created.

<?xml version="1.0" encoding="utf-8"?>
<resources>
	....
	<string name="mas2j">/jaca/android/example/example.mas2j</string>
	....
</resources>


Update the application manifest with as follow:

  • Define an Android service pointing to the JaCa-Android class jaca.android.JaCaService. This class is the implementation of an Android Service used for handling the execution of our MAS. You will always need to add this service in your JaCa-Android applications.
  • Add the android:launchMode=”singleTask” to the SmsViewer activity in the manifest for avoiding the creation of multiply Activity of the same type, we need just one SmsViewer GUI.
  • Add receive SMS permission needed for receive SMS.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="jaca.android.example"
      android:versionCode="1"
      android:versionName="1.0">

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <service android:name="jaca.android.JaCaService" android:exported="false" />
        <activity android:name=".SMSViewer"
                  android:label="@string/app_name"
                  android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
</manifest>

Comments are closed.

-->