An example project to show how the Auto Respond API can be used
Java
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
app
gradle/wrapper
.gitignore
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

AutoRespondAPITest

This project shows you how to use the Auto Respond API. See http://fifteen15studios.com/auto-respond-api/ for more details on the API and how to use it.

NOTE: This API will not work with the free version of Auto Respond.

In order to use this API, Auto Respond must first be installed. use AutoRespondAPI.isAutoRespondInstalled(Context) to determine if Auto Respond is installed on the device.

An API key is included for this application, but each key is also associated with a package name. Therefore, this API key will only work with this application.

Auto Respond can be downloaded from the Google Play Store here: https://play.google.com/store/apps/details?id=com.havens1515.autorespond

Setting up the API

Obtain an API key

First, you must obtain an API key. Submit a request for an API key to support@fifteen15studios.com . Be sure to include the following information in the email: App name, package name (usually something like com.example.app), developer name (the name of an individual or the company) and developer's email. If your key is misplaced, a copy of your key will only be sent to the email provided.

Jar File

Download AutoRespondAPI.jar and put it in your /libs folder.

build.gradle

To include the Auto Respond API jar file, make sure to include it in your build.gradle file.

dependencies {
    ...
    //necessary for AutoRespondAPI jar
    compile fileTree(dir: 'libs', include: ['*.jar'])
    ...
}

Android Manifest

Required Permissions

The API needs to connect to the internet to check the validity of your API key. To do this, you will need to declare the following permissions in your Android Manifest:

<!--to check for active connection-->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--To connect to check validity of API key-->
<uses-permission android:name="android.permission.INTERNET" />

Required Service

You will also need to declare the following service. This service allows the API to check for an active connection. If you do not declare this service, your application will crash.

<service
    android:name="com.fifteen15studios.autorespondapi.NetworkJobScheduler"
    android:exported="true"
    android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE">
    <intent-filter>
        <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
    </intent-filter>
</service>

Additional Permissions

The following permissions may be required, depending on what you do with the API:

<!-- Required if you want to change the Auto Respond message. Also implies READ_MESSAGE permission -->
<uses-permission android:name="com.fifteen15studios.autorespondapi.permission.CHANGE_MESSAGE"/>
<!-- Required if you want to change the state of Auto Respond -->
<uses-permission android:name="com.fifteen15studios.autorespondapi.permission.TOGGLE"/>

<!-- Only required if CHANGE_MESSAGE is not declared. Gives permission to read the Auto Respond message. -->
<uses-permission android:name="com.fifteen15studios.autorespondapi.permission.READ_MESSAGE"/>

CHANGE_MESSAGE and TOGGLE are declared as "dangerous" permissions. Therefore you will need to ask the user for these permissions on Android Marshmallow (SDK 23) and above.

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
    requestPermissions(new String[]{AutoRespondAPI.PERMISSION_CHANGE_MESSAGE, AutoRespondAPI.PERMISSION_TOGGLE}, 123);
}

The code above will request permission for both changing the Auto Respond message, and toggling Auto Respond. You can add more permissions to this statement or remove permissions that you won't be using.

READ_MESSAGE is declared as "normal", and therefore is granted simply by decalring it in your Android Manifest.

Create an API Object in your project

Once you have an API key, create an API object:

String apiKey = <insert your API Key here>;
AutoRespondAPI api = new AutoRespondAPI(getContext(), apiKey);

or, you can create your API object and set the API key later

AutoRespondAPI api = new AutoRespondAPI(getContext());
...
String apiKey = <insert your API Key here>;
api.setAPIKey(apiKey);

Querying Auto Respond

Determine if Auto Respond is installed

Before attempting to use any other API features, you should make sure that Auto Respond is installed. To do this, use AutoRespondAPI.isAutoRespondInstalled(). Notice that this is a static method. Therefore, you do not need an API object to call this method.

Determine if Auto Respond Supports Functionality

To prepare for future versions of the API, a method has been included to determine if the installed version of Auto Respond supports a given functionality. Notice that this is a static method. Therefore, you do not need an API object to call this method.

Example:

if (AutoRespondAPI.supportsFeature(getContext(), AutoRespondAPI.FEATURE_TOGGLE))
{
  api.toggleAutoRespond();
}

Accepted values

AutoRespondAPI.FEATURE_TOGGLE

AutoRespondAPI.FEATURE_CHANGE_MESSAGE

Get Current Auto Respond State

You can get the current state of Auto Repsond by using AutoRespondAPI.isAutoRespondActive(Context). Notice that this is a static method. Therefore, you do not need an API object to call this method.

Example:

boolean state = AutoRespondAPI.isAutoRespondActive(getContext());

Get Current Auto Respond Message

You can get the current Auto Respond message by using AutoRespondAPI.getAutoRespondMessage(Context). Notice that this is a static method. Therefore, you do not need an API object to call this method.

Requires permission CHANGE_MESSAGE or READ MESSAGE. See Additional Permissions above for details.

Example:

String message = AutoRespondAPI.getAutoRespondMessage(getContext());

Manipulating Auto Respond

Toggle Auto Respond

There are two ways to toggle Auto Respond. The first simply toggles auto respond. this can be done by calling api.toggleAutoRespond()

You can also set Auto Respond to a known state by passing a boolean value to the toggleAutoRespond like this: api.toggleAutoRespond(true) or api.toggleAutoRespond(false)

When Auto Respond is toggled, the Auto Respond app will automatically take care of things like displaying or clearing the notification. You do not need to worry about anything other than toggling it.

Requires TOGGLE permission. See Additional Permissions above for details.

Set Auto Respond Message

You can change the current Auto Respond message by calling api.setMessage(String). The string passed into the method will immediately become the new Auto Respond message.

When the message is changed, the Auto Respond app will take care of things like changing the text shown in the Auto Respond notification. You do not need to worry about anything other changing the message.

Requires CHANGE_MESSAGE permission. See Additional Permissions above for details.

Listening For Changes to Auto Respond

Auto Respond now sends a broadcast when it is toggled or the message is changed. To listen for these changes, you must declare a Broadcast Receiver to listen for those broadcasts.

Declare the receiver in your Android Manifest

<receiver
    android:name=".AutoRespondListener"
    android:exported="true">
    <intent-filter>
        <!-- Listen for toggle Events -->
        <action android:name="com.fifteen15studios.autorespondapi.STATE_CHANGED"/>
        <!-- Listen for message change events -->
        <action android:name="com.fifteen15studios.autorespondapi.MESSAGE_CHANGED"/>
    </intent-filter>
</receiver>

Only include the intent-filter that you need to listen for.

Create a BroadcastReceiver

Create a BroadcastReceiver in Java, and filter out each of the intents that are being received

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

import com.fifteen15studios.autorespondapi.AutoRespondAPI;

public class AutoRespondListener extends BroadcastReceiver {
    public AutoRespondListener() {
    }
    
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle extras = intent.getExtras();

        //If Auto Respond has been enabled or disabled
        if(intent.getAction().equals(AutoRespondAPI.ACTION_AUTO_RESPOND_STATE_CHANGED)) 
        {
            //get state after toggle
            boolean enabled = extras.getBoolean(AutoRespondAPI.EXTRA_STATE);

            //do something
        }
        //If Auto Respond message changed
        else if(intent.getAction().equals(AutoRespondAPI.ACTION_AUTO_RESPOND_MESSAGE_CHANGED))
        {
            //get new message
            String message = extras.getString(AutoRespondAPI.EXTRA_MESSAGE);
            
            //do something
        }
    }
}

Notice that the current state of Auto Respond is passed as an extra via AutoRespondAPI.EXTRA_STATE when it has been toggled, and the new message is passed as an extra via AutoRespondAPI.EXTRA_MESSAGE when the message has been changed.

Need Help?

Detailed explanations of the API functions can be found at http://fifteen15studios.com/auto-respond-api/

If you have any questions beyond this readme, send an email to support@fifteen15studios.com