Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lol768
committed
Feb 4, 2019
1 parent
86cc8c3
commit 582d568
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
Using KICL on Android | ||
===================== | ||
|
||
KICL can be used within an Android application. This requires some configuration, because KICL uses features only available in Java 8: | ||
|
||
### Add the library dependency | ||
|
||
In `app/build.gradle`: | ||
|
||
```groovy | ||
dependencies { | ||
// ... | ||
implementation group: 'org.kitteh.irc', name: 'client-lib', version: '5.1.0' | ||
} | ||
``` | ||
|
||
### Ensure minSdkVersion >= 24 | ||
|
||
In `app/build.gradle`: | ||
|
||
```groovy | ||
android { | ||
// ... | ||
defaultConfig { | ||
applicationId "com.example.kiclandoridtest" | ||
minSdkVersion 24 | ||
// ... | ||
} | ||
} | ||
### Ensure source and target compatibility are set for Java 8 | ||
In `app/build.gradle`: | ||
```groovy | ||
android { | ||
// ... | ||
compileOptions { | ||
sourceCompatibility = '1.8' | ||
targetCompatibility = '1.8' | ||
} | ||
} | ||
``` | ||
|
||
### Filter out duplicate META-INF files | ||
|
||
In `app/build.gradle`: | ||
|
||
```groovy | ||
android { | ||
// ... | ||
packagingOptions { | ||
exclude 'META-INF/INDEX.LIST' | ||
exclude 'META-INF/io.netty.versions.properties' | ||
} | ||
} | ||
``` | ||
|
||
### Add internet permission | ||
|
||
In `AndroidManifest.xml`: | ||
|
||
```xml | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.kiclandoridtest"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
<!-- ... --> | ||
</manifest> | ||
``` | ||
|
||
### Write some code | ||
|
||
Simple asynchronous task to connect to an IRC network and send a message: | ||
|
||
```java | ||
package com.example.kiclandoridtest; | ||
|
||
import android.os.AsyncTask; | ||
|
||
import org.kitteh.irc.client.library.Client; | ||
|
||
public class ConnectIrcTask extends AsyncTask<Void, Void, Void> { | ||
@Override | ||
protected Void doInBackground(Void... voids) { | ||
Client client = Client.builder().nick("KittehAndroid").server().host("irc.esper.net").then().buildAndConnect(); | ||
|
||
client.addChannel("#kittehandroid"); | ||
client.sendMessage("#kittehandroid", "Hello World!"); | ||
return null; | ||
} | ||
} | ||
``` | ||
|
||
|
||
And run it somewhere in an activity listener: | ||
|
||
```java | ||
FloatingActionButton fab = findViewById(R.id.fab); | ||
fab.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
Snackbar.make(view, "Connecting to IRC", Snackbar.LENGTH_LONG) | ||
.setAction("Action", null).show(); | ||
new ConnectIrcTask().execute(); | ||
} | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters