Professional Documents
Culture Documents
Experiment No 7
Experiment No 7
Source Code:
<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Notifications">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
package com.example.notifications;
import android.app.Notification;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notificationManager = NotificationManagerCompat.from(this);
editTextTitle = findViewById(R.id.edit_text_title);
editTextMessage = findViewById(R.id.edit_text_message);
}
notificationManager.notify(1, notification);
}
notificationManager.notify(2, notification);
}
}
package com.example.notifications;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
@Override
public void onCreate() {
super.onCreate();
createNotificationChannels();
}
NotificationManager manager =
getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel1);
manager.createNotificationChannel(channel2);
}
}
}
<EditText
android:id="@+id/edit_text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title" />
<EditText
android:id="@+id/edit_text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendOnChannel1"
android:text="Send on Channel 1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendOnChannel2"
android:text="Send on Channel 2" />
</LinearLayout>
Output: