Skip to content

Commit f3a2e31

Browse files
committed
get pushes working again from exact steps in readme
1 parent e3e8800 commit f3a2e31

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

example/src/main/java/org/xmtp/android/example/MainActivity.kt

+21
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package org.xmtp.android.example
22

3+
import android.Manifest
34
import android.accounts.AccountManager
45
import android.content.ClipData
56
import android.content.ClipboardManager
67
import android.content.Context
78
import android.content.Intent
9+
import android.content.pm.PackageManager
810
import android.os.Bundle
911
import android.view.Menu
1012
import android.view.MenuItem
1113
import android.view.View
1214
import android.widget.Toast
1315
import androidx.activity.viewModels
1416
import androidx.appcompat.app.AppCompatActivity
17+
import androidx.core.app.ActivityCompat
18+
import androidx.core.content.ContextCompat
1519
import androidx.lifecycle.Lifecycle
1620
import androidx.lifecycle.lifecycleScope
1721
import androidx.lifecycle.repeatOnLifecycle
@@ -28,6 +32,7 @@ import org.xmtp.android.example.pushnotifications.PushNotificationTokenManager
2832
import org.xmtp.android.example.utils.KeyUtil
2933
import org.xmtp.android.library.Conversation
3034

35+
3136
class MainActivity : AppCompatActivity(),
3237
ConversationsClickListener {
3338

@@ -37,10 +42,12 @@ class MainActivity : AppCompatActivity(),
3742
private lateinit var adapter: ConversationsAdapter
3843
private var bottomSheet: NewConversationBottomSheet? = null
3944
private var groupBottomSheet: NewGroupBottomSheet? = null
45+
private val REQUEST_CODE_POST_NOTIFICATIONS = 101
4046

4147
override fun onCreate(savedInstanceState: Bundle?) {
4248
super.onCreate(savedInstanceState)
4349
accountManager = AccountManager.get(this)
50+
checkAndRequestPermissions()
4451
PushNotificationTokenManager.init(this, "10.0.2.2:8080")
4552
viewModel.setupPush()
4653

@@ -208,4 +215,18 @@ class MainActivity : AppCompatActivity(),
208215
NewGroupBottomSheet.TAG
209216
)
210217
}
218+
219+
private fun checkAndRequestPermissions() {
220+
if (ContextCompat.checkSelfPermission(
221+
this,
222+
Manifest.permission.POST_NOTIFICATIONS
223+
) != PackageManager.PERMISSION_GRANTED
224+
) {
225+
ActivityCompat.requestPermissions(
226+
this,
227+
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
228+
REQUEST_CODE_POST_NOTIFICATIONS
229+
)
230+
}
231+
}
211232
}

example/src/main/java/org/xmtp/android/example/pushnotifications/PushNotificationsService.kt

+1-7
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,7 @@ class PushNotificationsService : FirebaseMessagingService() {
9898
Manifest.permission.POST_NOTIFICATIONS
9999
) != PackageManager.PERMISSION_GRANTED
100100
) {
101-
// TODO: Consider calling
102-
// ActivityCompat#requestPermissions
103-
// here to request the missing permissions, and then overriding
104-
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
105-
// int[] grantResults)
106-
// to handle the case where the user grants the permission. See the documentation
107-
// for ActivityCompat#requestPermissions for more details.
101+
Log.e(TAG, "No push notification permissions granted")
108102
return
109103
}
110104
notify(topic.hashCode(), builder.build())

0 commit comments

Comments
 (0)