-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
7a8eb03
commit 2265859
Showing
10 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/example/hw13_weatherapp/utils/MyFirebaseMessagingService.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,14 @@ | ||
|
||
import com.google.firebase.messaging.FirebaseMessagingService | ||
import com.google.firebase.messaging.RemoteMessage | ||
|
||
class MyFirebaseMessagingService : FirebaseMessagingService() { | ||
|
||
override fun onMessageReceived(message: RemoteMessage) { | ||
super.onMessageReceived(message) | ||
} | ||
|
||
override fun onNewToken(token: String) { | ||
super.onNewToken(token) | ||
} | ||
} |
71 changes: 69 additions & 2 deletions
71
app/src/main/java/com/example/hw13_weatherapp/view/MainActivity.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 |
---|---|---|
@@ -1,14 +1,81 @@ | ||
package com.example.hw13_weatherapp.view | ||
|
||
import android.Manifest | ||
import android.app.NotificationChannel | ||
import android.app.NotificationManager | ||
import android.app.PendingIntent | ||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import android.os.Build | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import androidx.core.app.ActivityCompat | ||
import androidx.core.app.NotificationCompat | ||
import androidx.core.app.NotificationManagerCompat | ||
import com.example.hw13_weatherapp.R | ||
import com.example.hw13_weatherapp.databinding.ActivityMainBinding | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityMainBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
val view = binding.root | ||
setContentView(view) | ||
|
||
|
||
|
||
createNotificationChannel() | ||
|
||
binding.buttonNotification.setOnClickListener { | ||
val notification = NotificationCompat.Builder(this, "NOTI_CHANNEL_ID") | ||
.setSmallIcon(R.drawable.baseline_message_24) | ||
.setContentTitle("UYGULAMAYI ACINIZ") | ||
.setContentText("Uygulamayi acmak icin tiklayiniz !!!") | ||
.setContentIntent(getPendingIntent()) | ||
.setPriority(NotificationCompat.COLOR_DEFAULT) | ||
.build() | ||
|
||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) | ||
!= PackageManager.PERMISSION_GRANTED | ||
) { | ||
return@setOnClickListener | ||
} | ||
|
||
NotificationManagerCompat.from(this).notify(1, notification) | ||
} | ||
} | ||
|
||
private fun createNotificationChannel() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | ||
|
||
val name = "Notification Title" | ||
val descricpitonText = "Notification Description" | ||
val importance = NotificationManager.IMPORTANCE_HIGH | ||
val channel = NotificationChannel("NOTI_CHANNEL_ID", name, importance).apply { | ||
description = descricpitonText | ||
} | ||
|
||
val notificationManager: NotificationManager = | ||
getSystemService(NOTIFICATION_SERVICE) as NotificationManager | ||
notificationManager.createNotificationChannel(channel) | ||
} | ||
} | ||
|
||
setContentView(R.layout.activity_main) | ||
private fun getPendingIntent(): PendingIntent { | ||
val intent = Intent( | ||
this, | ||
MainActivity::class.java | ||
) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
return PendingIntent.getActivity( | ||
this, | ||
0, | ||
intent, | ||
PendingIntent.FLAG_IMMUTABLE | ||
) | ||
} | ||
} | ||
} |
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 @@ | ||
<vector android:autoMirrored="true" android:height="24dp" | ||
android:tint="#EA0C0C" android:viewportHeight="24" | ||
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM18,14L6,14v-2h12v2zM18,11L6,11L6,9h12v2zM18,8L6,8L6,6h12v2z"/> | ||
</vector> |
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