notification

This commit is contained in:
Page Asgardius 2022-09-30 18:34:52 -07:00
parent f0b96f3b25
commit 274d00a222
4 changed files with 51 additions and 23 deletions

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/4.7_WXGA_API_31.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-09-29T15:55:29.079423Z" />
</component>
</project>

View file

@ -1,9 +1,17 @@
package asgardius.page.r3forumtest;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ContentResolver;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@ -30,7 +38,8 @@ public class MainScreen extends AppCompatActivity {
SQLiteDatabase db;
MyDbHelper dbHelper;
TextView id ,email, nacionalidad, nacimiento;
Button logout;
Button logout, notification;
Uri crashsound;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -42,7 +51,9 @@ public class MainScreen extends AppCompatActivity {
nacionalidad = (TextView) findViewById(R.id.nacionalidad);
nacimiento = (TextView) findViewById(R.id.nacimiento);
logout = (Button)findViewById(R.id.logout);
notification = (Button)findViewById(R.id.notification);
dbHelper = new MyDbHelper(this);
crashsound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + this.getPackageName() + "/" + R.raw.crash);
id.setText(username);
Thread login = new Thread(new Runnable() {
@ -113,6 +124,31 @@ public class MainScreen extends AppCompatActivity {
}
});
login.start();
notification.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
//buttonaction
if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.O){
NotificationChannel channel= new NotificationChannel("Test","Test Notification",NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager =getSystemService(NotificationManager.class);
AudioAttributes audio = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
channel.setSound(crashsound, audio);
manager.createNotificationChannel(channel);
}
String message="Su nave ha chocado con un asteroide";
NotificationCompat.Builder builder = new NotificationCompat.Builder(MainScreen.this,"Test");
builder.setContentTitle("Prueba");
builder.setContentText(message);
builder.setSmallIcon(R.drawable.ic_launcher_foreground);
builder.setAutoCancel(true);
builder.setSound(crashsound);
NotificationManagerCompat managerCompat=NotificationManagerCompat.from(MainScreen.this);
managerCompat.notify(1,builder.build());
}
});
logout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {

View file

@ -13,19 +13,20 @@
android:id="@+id/linearLayoutSubmit"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_margin="20dp"
android:layout_margin="0dp"
android:orientation="horizontal"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="20dp">
<TextView
android:id="@+id/username"
<Button
android:id="@+id/notification"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:textAlignment="center"
android:backgroundTint="@color/black"
android:text="Notificar"
android:textColor="@color/white"
android:textSize="25sp" />
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/logout"
@ -39,6 +40,14 @@
</LinearLayout>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="25sp" />
<TextView
android:id="@+id/email"
android:layout_width="match_parent"

Binary file not shown.