在FirebaseMessaging 中发送(com.google.firebase.messaging.RemoteMessage);无法应用于(android.os.Message)
我正在处理推送通知我从firebase控制台推送了通知它可以工作 现在我想通过编码来推送通知,所以我尝试了在FirebaseMessaging 中发送(com.google.firebase.messaging.RemoteMessage);无法应用于(android.os.Message),android,firebase-cloud-messaging,Android,Firebase Cloud Messaging,我正在处理推送通知我从firebase控制台推送了通知它可以工作 现在我想通过编码来推送通知,所以我尝试了 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; im
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]
}
}
此处的消息是com.google.firebase.messaging.RemoteMessage类型对象,但该对象未在此类中定义
Message message = Message.builder()
在消息alt+enter时,按此键可显示通知样式和android.os.message
但是我发现com.google.firebase.messaging.RemoteMessage要在这里实现,我使用import com.google.firebase.messaging.RemoteMessage;但是没有起作用
提前感谢使用RemoteMessage.Builder类构建要通过send发送的消息实例(RemoteMessage)尝试清理项目并再次同步渐变但它发送字符串类型远程消息不是字符串类型此代码是在firbase文档中编写的不知道为什么它不工作检查此