https://github.com/onehilltech/android-gatekeeper
Gatekeeper support library for Android
https://github.com/onehilltech/android-gatekeeper
Last synced: about 1 year ago
JSON representation
Gatekeeper support library for Android
- Host: GitHub
- URL: https://github.com/onehilltech/android-gatekeeper
- Owner: onehilltech
- License: other
- Created: 2015-10-07T02:35:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T06:12:23.000Z (almost 9 years ago)
- Last Synced: 2025-04-15T07:19:27.775Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 1.2 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
android-gatekeeper
==================
[](https://jitpack.io/#onehilltech/android-gatekeeper)
[](https://travis-ci.org/onehilltech/android-gatekeeper)
Gatekeeper support library for Android.
## Installation
#### Gradle
```
buildscript {
repositories {
maven { url "https://jitpack.io" }
}
}
dependencies {
compile com.github.onehilltech:android-gatekeeper:x.y.z
}
```
## Getting Started
### Configuring meta-data in AndroidManifest.xml
Use the `gatekeeper-cli` to add a new client that represents the mobile application to
the database. Then, define the following values in `strings.xml`:
```xml
URL for Gatekeeper
CLIENT ID
CLIENT SECRET
```
The strings then need to be referenced as meta-data in `AndroidManifest.xml`.
```xml
```
### Initialize Gatekeeper in the application
Update your `Application` class to call `Gatekeeper.init (context)`. You must also
initialize [DBFlow](https://github.com/Raizlabs/DBFlow).
```javascript
public class TheApplication extends Application
{
@Override
public void onCreate ()
{
super.onCreate ();
FlowManager.init (
new FlowConfig.Builder (this)
.openDatabasesOnInit (true)
.build ());
// Initialize Gatekeeper
Gatekeeper.initialize (this);
}
}
```
### Login / New account activity
Export the default activities for login and creating a new account, if applicable, to
`AndroidManifest.xml`.
```xml
```
### Protecting activities
Last, we need to protect the activities that require login. Create a
`SingleUserSessionClient` in each activity, and make sure the user is
logged in before continuing on the `Activity.onStart()` method. This
will ensure that regardless of how the user enter the application, they
must be logged in.
```java
public class MyActivity extends AppCompatActivity
implements SingleUserSessionClient.Listener
{
private SingleUserSessionClient session_;
@Override
protected void onCreate (@Nullable Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
this.setContentView (R.layout.activity_main);
this.session_ = new SingleUserSessionClient.Builder (this).build ();
this.session_.setListener (this);
}
@Override
protected void onStart ()
{
super.onStart ();
// Make sure the user it logged in.
this.session_.checkLoggedIn (this, SingleUserLoginActivity.class);
// If you do not want create a SingleUserSessionClient object,
// then use:
//
// SingleUserSessionClient.ensureLoggedIn (this, SingleUserLoginActivity.class);
}
@Override
public void onLogin (SingleUserSessionClient client)
{
// Handle the user logging in
}
@Override
public void onLogout (SingleUserSessionClient client)
{
// Handle the user logging out
}
}
```
## Custom Activities