소개
게시글
질문&답변
매칭완료후->Notification 뜨지않는 오류 문제..
개복치님 추가로Manifest 쪽에도 notifications 권한이 된상태입니다. 뭐가문제일까요..? ㅠㅠ
- 0
- 4
- 645
질문&답변
매칭완료후->Notification 뜨지않는 오류 문제..
개복치님!! 깃허브 사용하다가 도저히 안되서 아래와 같이 코드 복사하여 송부드립니다.오류 확인 부탁드립니다. 맨 밑에 줄이 에러로 뜹니다.오류 코드 : with(NotificationManagerCompat.from(this)){notify(123, builder.build()) package com.example.sogothingimport android.app.NotificationChannelimport android.app.NotificationManagerimport android.content.Contextimport android.content.Intentimport android.os.Buildimport androidx.appcompat.app.AppCompatActivityimport android.os.Bundleimport android.util.Logimport android.view.Viewimport android.widget.ImageViewimport android.widget.Toastimport androidx.core.app.NotificationCompatimport androidx.core.app.NotificationManagerCompatimport com.bumptech.glide.Glideimport com.example.sogothing.auth.IntroActivityimport com.example.sogothing.auth.UserDataModelimport com.example.sogothing.setting.SettingActivityimport com.example.sogothing.slider.CardStackAdapterimport com.example.sogothing.utils.FirebaseAuthUtilsimport com.example.sogothing.utils.FirebaseRefimport com.google.firebase.auth.ktx.authimport com.google.firebase.database.DataSnapshotimport com.google.firebase.database.DatabaseErrorimport com.google.firebase.database.ValueEventListenerimport com.google.firebase.ktx.Firebaseimport com.google.firebase.storage.ktx.storageimport com.yuyakaido.android.cardstackview.CardStackLayoutManagerimport com.yuyakaido.android.cardstackview.CardStackListenerimport com.yuyakaido.android.cardstackview.CardStackViewimport com.yuyakaido.android.cardstackview.Directionclass MainActivity : AppCompatActivity() {lateinit var cardStackAdapter: CardStackAdapterlateinit var manager : CardStackLayoutManagerprivate val TAG = "MainActivity"private val usersDataList = mutableListOf()private var userCount = 0private lateinit var currentUserGender : Stringprivate val uid = FirebaseAuthUtils.getUid()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// 나는 민수, 내가 좋아한 여자는 민지다// 내가 민지를 좋아요 하면은, 민지의 좋아요 리스트중에서 내가 있는지만 확인하면 됨.//val setting = findViewById(R.id.settingIcon)setting.setOnClickListener{val intent = Intent(this, SettingActivity::class.java)startActivity(intent)}val cardStackView = findViewById(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 + 1if(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 = managercardStackView.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 messageLog.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 messageLog.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 messageLog.w(TAG, "loadPost:onCancelled", databaseError.toException())}}FirebaseRef.userLikeRef.child(otherUid).addValueEventListener(postListener)}// Notificationprivate fun createNotificationChannel() {// Create the NotificationChannel, but only on API 26+ because// the NotificationChannel class is new and not in the support libraryif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {val name = "name"val descriptionText = "description"val importance = NotificationManager.IMPORTANCE_DEFAULTval channel = NotificationChannel("Test_Channel", name, importance).apply {description = descriptionText}// Register the channel with the systemval notificationManager: NotificationManager =getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManagernotificationManager.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
- 4
- 645