我是颤振新手并尝试实现推送通知。我使用 ONE SIGNAL 进行推送通知
在这里,我初始化了一个信号并获取了playerId,并将其发送到服务器。
void oneSignalInit() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
OneSignal.shared.init('one signal id');
OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);
status = await OneSignal.shared.getPermissionSubscriptionState();
var playerId = status.subscriptionStatus.userId;
print(playerId);
preferences.setString(Constants.PLAYER_ID, playerId);
}
Run Code Online (Sandbox Code Playgroud)
在这里,我收到来自一个信号的通知并从中获取所需的数据。
notificationHandler() {
OneSignal.shared.setNotificationReceivedHandler((OSNotification notification) {
// will be called whenever a notification is received
var data = notification.payload.additionalData;
print(data['body']['tripID'].toString());
showNotification(message);
});
Run Code Online (Sandbox Code Playgroud)
现在,我正在提出我的自定义通知,使用 flutter_local_notification 依赖项
showNotification(var msg) async {
print("show notification is working");
AndroidNotificationDetails androidPlatformChannelSpecifics =
new AndroidNotificationDetails(
msg, msg, msg);
IOSNotificationDetails iOSPlatformChannelSpecifics =
new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics = new …Run Code Online (Sandbox Code Playgroud) 在android中实现了dataBinding,但在编译时抛出错误
XML 代码
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/sw360dp_260dp"
android:layout_marginTop="@dimen/sw360dp_45dp"
android:background="@drawable/apply_jobs_background_xhdpi" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/toolbar"
android:layout_marginStart="@dimen/sw360dp_40dp"
android:layout_marginTop="@dimen/sw360dp_20dp"
android:orientation="vertical">
<TextView
android:id="@+id/applyJobsCompanyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/amarnath_regular"
android:hint="Company Name"
android:textColor="@color/white"
android:textSize="@dimen/sw360dp_18sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的错误
数据绑定错误****msg:“视图”节点文件没有类属性:C:\Users\Aayush\AndroidStuidoProjects\SkillDostiJobs\app\src\main\res\layout\activity_apply_jobs.xml