작성
·
648
·
수정됨
답변 4
0
0
개복치님 추가로
Manifest 쪽에도 notifications 권한이 된상태입니다. 뭐가문제일까요..? ㅠㅠ
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
0
개복치님!! 깃허브 사용하다가 도저히 안되서 아래와 같이 코드 복사하여 송부드립니다.
오류 확인 부탁드립니다. 맨 밑에 줄이 에러로 뜹니다.
오류 코드 : with(NotificationManagerCompat.from(this)){notify(123, builder.build())
package com.example.sogothing
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.bumptech.glide.Glide
import com.example.sogothing.auth.IntroActivity
import com.example.sogothing.auth.UserDataModel
import com.example.sogothing.setting.SettingActivity
import com.example.sogothing.slider.CardStackAdapter
import com.example.sogothing.utils.FirebaseAuthUtils
import com.example.sogothing.utils.FirebaseRef
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.ktx.storage
import com.yuyakaido.android.cardstackview.CardStackLayoutManager
import com.yuyakaido.android.cardstackview.CardStackListener
import com.yuyakaido.android.cardstackview.CardStackView
import com.yuyakaido.android.cardstackview.Direction
class MainActivity : AppCompatActivity() {
lateinit var cardStackAdapter: CardStackAdapter
lateinit var manager : CardStackLayoutManager
private val TAG = "MainActivity"
private val usersDataList = mutableListOf<UserDataModel>()
private var userCount = 0
private lateinit var currentUserGender : String
private val uid = FirebaseAuthUtils.getUid()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 나는 민수, 내가 좋아한 여자는 민지다
// 내가 민지를 좋아요 하면은, 민지의 좋아요 리스트중에서 내가 있는지만 확인하면 됨.
//
val setting = findViewById<ImageView>(R.id.settingIcon)
setting.setOnClickListener{
val intent = Intent(this, SettingActivity::class.java)
startActivity(intent)
}
val cardStackView = findViewById<CardStackView>(R.id.cardStackView)
manager = CardStackLayoutManager(baseContext,object : CardStackListener {
override fun onCardDragging(direction: Direction?, ratio: Float) {
}
override fun onCardSwiped(direction: Direction?) {
if(direction == Direction.Right) {
// Toast.makeText(this@MainActivity,"right", Toast.LENGTH_SHORT).show()
// Log.d(TAG,usersDataList[userCount].uid.toString())
userLikeOtherUser(uid,usersDataList[userCount].uid.toString())
}
if(direction == Direction.Left) {
// Toast.makeText(this@MainActivity,"left", Toast.LENGTH_SHORT).show()
}
userCount = userCount + 1
if(userCount == usersDataList.count()) {
getUserDataList(currentUserGender)
Toast.makeText(this@MainActivity,"유저 새롭게 받아옵니다", Toast.LENGTH_LONG).show()
}
}
override fun onCardRewound() {
}
override fun onCardCanceled() {
}
override fun onCardAppeared(view: View?, position: Int) {
}
override fun onCardDisappeared(view: View?, position: Int) {
}
})
cardStackAdapter = CardStackAdapter(baseContext,usersDataList)
cardStackView.layoutManager = manager
cardStackView.adapter = cardStackAdapter
// getUserDataList()
getMyUserData()
}
private fun getMyUserData(){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
Log.d(TAG,dataSnapshot.toString())
val data = dataSnapshot.getValue(UserDataModel::class.java)
Log.d(TAG,data?.gender.toString())
currentUserGender = data?.gender.toString()
getUserDataList(currentUserGender)
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userInfoRef.child(uid).addValueEventListener(postListener)
}
private fun getUserDataList(currentUserGender : String){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (dataModel in dataSnapshot.children){
val user = dataModel.getValue(UserDataModel::class.java)
if(user!!.gender.toString().equals(currentUserGender)){
} else {
}
usersDataList.add(user!!)
}
cardStackAdapter.notifyDataSetChanged()
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userInfoRef.addValueEventListener(postListener)
}
// 유저의 좋아요를 표시하는 부분
// 데이터에서 값을 저장해야 되는데, 어떤 값을 저장할까?
// 나의 uid, 내가 좋아요 한 사람의 uid 값
private fun userLikeOtherUser(myUid : String, otherUid : String){
FirebaseRef.userLikeRef.child(uid).child(otherUid).setValue("true")
getOtherUserLikeList(otherUid)
}
// 내가 좋아요한 사람이 누구를 좋아요 했는지 알 수 있음.
private fun getOtherUserLikeList(otherUid : String){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
// 여기 리스트안에서 나의 UID가 있는 지 확인만 해주면 됨.
// 내가 좋아요한 사람(응디)의 좋아요 리스트를 불러와서
// 여기서 내 UID가 있는 지 체크만 해주면 됨.
for (dataModel in dataSnapshot.children){
Log.e(TAG, dataModel.key.toString())
val likeUserKey = dataModel.key.toString()
if(likeUserKey.equals(uid)) {
Toast.makeText(this@MainActivity,"매칭완료",Toast.LENGTH_SHORT).show()
createNotificationChannel()
sendNotification()
}
}
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userLikeRef.child(otherUid).addValueEventListener(postListener)
}
// 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) {
val name = "name"
val descriptionText = "description"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("Test_Channel", name, importance).apply {
description = descriptionText
}
// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
private fun sendNotification(){
var builder = NotificationCompat.Builder(this, "Test_Channel")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("title")
.setContentText("content")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
with(NotificationManagerCompat.from(this)){
notify(123, builder.build())
}
}
}
0
안녕하세요. 정말 죄송한데. 깃허브 사용법 보면서도 잘모르겠어서요.
with(NotificationManagerCompat.from(this)){
notify(123, builder.build())
notfity(123, builder.build()) 여기서 빨간 줄그어지면서 에러가 나는거 같습니다.
package com.example.sogothing
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.bumptech.glide.Glide
import com.example.sogothing.auth.IntroActivity
import com.example.sogothing.auth.UserDataModel
import com.example.sogothing.setting.SettingActivity
import com.example.sogothing.slider.CardStackAdapter
import com.example.sogothing.utils.FirebaseAuthUtils
import com.example.sogothing.utils.FirebaseRef
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.ktx.Firebase
import com.google.firebase.storage.ktx.storage
import com.yuyakaido.android.cardstackview.CardStackLayoutManager
import com.yuyakaido.android.cardstackview.CardStackListener
import com.yuyakaido.android.cardstackview.CardStackView
import com.yuyakaido.android.cardstackview.Direction
class MainActivity : AppCompatActivity() {
lateinit var cardStackAdapter: CardStackAdapter
lateinit var manager : CardStackLayoutManager
private val TAG = "MainActivity"
private val usersDataList = mutableListOf<UserDataModel>()
private var userCount = 0
private lateinit var currentUserGender : String
private val uid = FirebaseAuthUtils.getUid()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// 나는 민수, 내가 좋아한 여자는 민지다
// 내가 민지를 좋아요 하면은, 민지의 좋아요 리스트중에서 내가 있는지만 확인하면 됨.
//
val setting = findViewById<ImageView>(R.id.settingIcon)
setting.setOnClickListener{
val intent = Intent(this, SettingActivity::class.java)
startActivity(intent)
}
val cardStackView = findViewById<CardStackView>(R.id.cardStackView)
manager = CardStackLayoutManager(baseContext,object : CardStackListener {
override fun onCardDragging(direction: Direction?, ratio: Float) {
}
override fun onCardSwiped(direction: Direction?) {
if(direction == Direction.Right) {
// Toast.makeText(this@MainActivity,"right", Toast.LENGTH_SHORT).show()
// Log.d(TAG,usersDataList[userCount].uid.toString())
userLikeOtherUser(uid,usersDataList[userCount].uid.toString())
}
if(direction == Direction.Left) {
// Toast.makeText(this@MainActivity,"left", Toast.LENGTH_SHORT).show()
}
userCount = userCount + 1
if(userCount == usersDataList.count()) {
getUserDataList(currentUserGender)
Toast.makeText(this@MainActivity,"유저 새롭게 받아옵니다", Toast.LENGTH_LONG).show()
}
}
override fun onCardRewound() {
}
override fun onCardCanceled() {
}
override fun onCardAppeared(view: View?, position: Int) {
}
override fun onCardDisappeared(view: View?, position: Int) {
}
})
cardStackAdapter = CardStackAdapter(baseContext,usersDataList)
cardStackView.layoutManager = manager
cardStackView.adapter = cardStackAdapter
// getUserDataList()
getMyUserData()
}
private fun getMyUserData(){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
Log.d(TAG,dataSnapshot.toString())
val data = dataSnapshot.getValue(UserDataModel::class.java)
Log.d(TAG,data?.gender.toString())
currentUserGender = data?.gender.toString()
getUserDataList(currentUserGender)
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userInfoRef.child(uid).addValueEventListener(postListener)
}
private fun getUserDataList(currentUserGender : String){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (dataModel in dataSnapshot.children){
val user = dataModel.getValue(UserDataModel::class.java)
if(user!!.gender.toString().equals(currentUserGender)){
} else {
}
usersDataList.add(user!!)
}
cardStackAdapter.notifyDataSetChanged()
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userInfoRef.addValueEventListener(postListener)
}
// 유저의 좋아요를 표시하는 부분
// 데이터에서 값을 저장해야 되는데, 어떤 값을 저장할까?
// 나의 uid, 내가 좋아요 한 사람의 uid 값
private fun userLikeOtherUser(myUid : String, otherUid : String){
FirebaseRef.userLikeRef.child(uid).child(otherUid).setValue("true")
getOtherUserLikeList(otherUid)
}
// 내가 좋아요한 사람이 누구를 좋아요 했는지 알 수 있음.
private fun getOtherUserLikeList(otherUid : String){
val postListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
// 여기 리스트안에서 나의 UID가 있는 지 확인만 해주면 됨.
// 내가 좋아요한 사람(응디)의 좋아요 리스트를 불러와서
// 여기서 내 UID가 있는 지 체크만 해주면 됨.
for (dataModel in dataSnapshot.children){
Log.e(TAG, dataModel.key.toString())
val likeUserKey = dataModel.key.toString()
if(likeUserKey.equals(uid)) {
Toast.makeText(this@MainActivity,"매칭완료",Toast.LENGTH_SHORT).show()
createNotificationChannel()
sendNotification()
}
}
}
override fun onCancelled(databaseError: DatabaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException())
}
}
FirebaseRef.userLikeRef.child(otherUid).addValueEventListener(postListener)
}
// 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) {
val name = "name"
val descriptionText = "description"
val importance = NotificationManager.IMPORTANCE_DEFAULT
val channel = NotificationChannel("Test_Channel", name, importance).apply {
description = descriptionText
}
// Register the channel with the system
val notificationManager: NotificationManager =
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.createNotificationChannel(channel)
}
}
private fun sendNotification(){
var builder = NotificationCompat.Builder(this, "Test_Channel")
.setSmallIcon(R.drawable.ic_launcher_background)
.setContentTitle("title")
.setContentText("content")
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
with(NotificationManagerCompat.from(this)){
notify(123, builder.build())
}
}
}
안녕하세요.
혹시 잘 안되시는게 있으신가요?
전체 코드를 깃허브/구글드라이브에 올리시고 어떤 부분에서 안되시는지 설명해주시면 살펴보겠습니다~