package com.sevenlearn.notification_tutorial2;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
NotificationChannel notificationChannel= new NotificationChannel("myApp","defaultChannel",NotificationManager.IMPORTANCE_HIGH);
notificationChannel.setDescription("test");
if (notificationManager!=null)
notificationManager.createNotificationChannel(notificationChannel);
}
}
-----------
package com.sevenlearn.notification_tutorial2;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.viewpager.widget.ViewPager;
import android.app.Notification;
import android.app.NotificationManager;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private View v;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button2:
// Toast.makeText(this, "test", Toast.LENGTH_SHORT).show();
Notification notification= new NotificationCompat.Builder(this,"myapp")
.setSmallIcon(android.R.drawable.stat_notify_chat)
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setContentTitle("My Notification")
.setContentText("this is my first notification ")
.build();
NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1001,notification);
break;
}
}
}
----------
کد هارو به اینصورت نوشتم طبق ویدیو آموزشی ولی نوتیفیکشن نمایش داده نشد - توست هم گذاشتم که ببینم باتن عمل میکنه توست کار کرد