This repository has been archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added app icon/name, begun push notification implementation
- Loading branch information
Showing
32 changed files
with
220 additions
and
59 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
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
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 |
---|---|---|
@@ -1,22 +1,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.opia.android"> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.VIBRATE" /> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<!-- Theme.AppCompat.Light.NoActionBar --> | ||
<!-- TODO disable usesCleartextTraffic --> | ||
<application | ||
android:allowBackup="false" | ||
android:supportsRtl="true" | ||
android:usesCleartextTraffic="true" | ||
android:theme="@style/Theme.Material3.Light.NoActionBar"> | ||
<activity android:name=".MainActivity" android:exported="true"> | ||
android:allowBackup="false" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme" | ||
android:usesCleartextTraffic="true"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
<action android:name="android.intent.action.MAIN" /> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<receiver | ||
android:name=".UnifiedPushReceiver" | ||
android:enabled="true" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="org.unifiedpush.android.connector.MESSAGE" /> | ||
<action android:name="org.unifiedpush.android.connector.UNREGISTERED" /> | ||
<action android:name="org.unifiedpush.android.connector.NEW_ENDPOINT" /> | ||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_FAILED" /> | ||
<action android:name="org.unifiedpush.android.connector.REGISTRATION_REFUSED" /> | ||
</intent-filter> | ||
</receiver> | ||
</application> | ||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,51 @@ | ||
package app.opia.android | ||
|
||
import android.app.Notification | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.content.Context | ||
import android.os.Build | ||
import java.util.concurrent.ThreadLocalRandom | ||
|
||
class Notifier(var context: Context) { | ||
private var gNM: NotificationManager? = null | ||
private var channelId = "Opia-Android" // TODO per account | ||
|
||
init { | ||
channelId = context.packageName | ||
createNotificationChannel() | ||
gNM = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
} | ||
|
||
fun sendNotification(title: String, text: String, priority: Int) { | ||
val notificationBuilder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
Notification.Builder(context, channelId) | ||
} else { | ||
Notification.Builder(context) | ||
} | ||
|
||
val notification = notificationBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(text) | ||
.setWhen(System.currentTimeMillis()).setContentTitle(title).setContentText(text) | ||
.setPriority(priority).build() | ||
|
||
gNM!!.notify(ThreadLocalRandom.current().nextInt(), notification) | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
// Create the NotificationChannel, but only on API 26+ because | ||
// the NotificationChannel class is new and not in the support library | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && channelId.isNotEmpty()) { | ||
val name = context.packageName | ||
val descriptionText = "Opia" | ||
val importance = NotificationManager.IMPORTANCE_DEFAULT | ||
val channel = NotificationChannel(channelId, name, importance).apply { | ||
description = descriptionText | ||
} | ||
|
||
// Register the channel with the system | ||
val notificationManager: NotificationManager = | ||
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager | ||
notificationManager.createNotificationChannel(channel) | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
android/src/main/java/app/opia/android/UnifiedPushReceiver.kt
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,58 @@ | ||
package app.opia.android | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.util.Log | ||
import android.widget.Toast | ||
import org.unifiedpush.android.connector.EXTRA_BYTES_MESSAGE | ||
import org.unifiedpush.android.connector.MessagingReceiver | ||
import org.unifiedpush.android.connector.UnifiedPush | ||
import java.net.URLDecoder | ||
|
||
const val TAG = "OpiaApp" | ||
const val DEBUG = true | ||
|
||
class UnifiedPushReceiver : MessagingReceiver() { | ||
// instance: accountId/subscription? | ||
override fun onMessage(context: Context, message: ByteArray, instance: String) { | ||
Log.d(TAG, "UPReceiver [$instance] > message: $message") | ||
val dict = URLDecoder.decode(String(message), "UTF-8").split("&") | ||
val params = dict.associate { | ||
try { | ||
it.split("=")[0] to it.split("=")[1] | ||
} catch (e: Exception) { | ||
"" to "" | ||
} | ||
} | ||
val text = params["message"] ?: "New notification" | ||
val priority = params["priority"]?.toInt() ?: 8 | ||
val title = params["title"] ?: context.getString(R.string.app_name) | ||
Notifier(context).sendNotification(title, text, priority) | ||
} | ||
|
||
override fun onNewEndpoint(context: Context, endpoint: String, instance: String) { | ||
Log.d(TAG, "UPReceiver [$instance] > new endpoint: $endpoint - syncing...") | ||
} | ||
|
||
override fun onRegistrationFailed(context: Context, instance: String) { | ||
Log.e(TAG, "UPReceiver [$instance] > registration failed") | ||
Toast.makeText(context, "Registration Failed", Toast.LENGTH_SHORT).show() | ||
UnifiedPush.forceRemoveDistributor(context) | ||
} | ||
|
||
override fun onUnregistered(context: Context, instance: String) { | ||
Log.w(TAG, "UPReceiver [$instance] > unregistered") | ||
val appName = context.getString(R.string.app_name) | ||
Toast.makeText(context, "$appName is unregistered", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
Log.d(TAG, "UPReceiver > event received") | ||
if (DEBUG) { | ||
Log.d(TAG, | ||
"raw bytes: " + intent.getByteArrayExtra(EXTRA_BYTES_MESSAGE) | ||
?.joinToString("") { byte -> "%02x".format(byte) }) | ||
} | ||
super.onReceive(context, intent) | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@color/ic_launcher_background"/> | ||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> | ||
</adaptive-icon> |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<background android:drawable="@color/ic_launcher_background"/> | ||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/> | ||
</adaptive-icon> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#010E44</color> | ||
<color name="colorPrimaryDark">#20212C</color> | ||
<color name="colorAccent">#5BB6CB</color> | ||
</resources> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="ic_launcher_background">#82A3A9</color> | ||
</resources> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="app_name" translatable="false">Opia</string> | ||
</resources> |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<!-- Theme.AppCompat.Light.NoActionBar --> | ||
<style name="AppTheme" parent="Theme.Material3.Light.NoActionBar"> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
</resources> |
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
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
Oops, something went wrong.