i'm working on push notification here i pushed notification from firebase console it works now i want to push notification through coding so i tried
import android.content.Context;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.messaging.FirebaseMessaging;
public class LockScreen extends AppCompatActivity {
Button btn;
EditText t1;
TextView status;
Password_Database password_database;
String v1, v2;
Context cn;
String str = "";
public LockScreen() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lock_screen);
cn = this;
password_database = new Password_Database(cn);
btn = (Button) findViewById(R.id.unlock_btn);
t1 = (EditText) findViewById(R.id.unlock_pass);
status = (TextView) findViewById(R.id.App_name);
// v1 and v2 get data from background services
Bundle extras = getIntent().getExtras();
if (extras != null) {
v1 = extras.getString("name");
v2 = extras.getString("pack");
//The key argument here must match that used in the other activity
}
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (v1.equals(t1.getText().toString())) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage(v2);
launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(launchIntent);
sendToTopic();
finish();
Toast.makeText(LockScreen.this, "Password Correct", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(LockScreen.this, "wrong password", Toast.LENGTH_LONG).show();
t1.setText("");
}
}
});
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onBackPressed() {
v2 = "";
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
LockScreen.this.finish();
}
public void sendToTopic() {
// [START send_to_topic]
// The topic name can be optionally prefixed with "/topics/".
String topic = "notification";
// See documentation on defining a message payload.
Message message = Message.builder()
.putData("score", "850")
.putData("time", "2:45")
.setTopic(topic)
.build();
// Send a message to the devices subscribed to the provided topic.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);
// [END send_to_topic]
}
}
here message is com.google.firebase.messaging.RemoteMessage type object but this is not defining in this class
Message message = Message.builder()
on message alt+enter pressed it show Notification Style and android.os.Message But i neend com.google.firebase.messaging.RemoteMessage to be implemented here i used import com.google.firebase.messaging.RemoteMessage; but didn't worked thanks in advance