- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用以下代码向设备发送推送通知。
var nTitle = "New message from " + $rootScope.clients_firstName;
var to = "DeviceToken is here";
var notification = {
'title': nTitle,
//'body': 'Click here to more details...',
'icon': 'firebase-logo.png',
'click_action': 'openapp'
};
var key = 'your key';
fetch('https://fcm.googleapis.com/fcm/send', {
'method': 'POST',
'headers': {
'Authorization': 'key=' + key,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
'notification': data,
'to': to
})
}).then(function(response) {
//console.log("res ", response);
}).catch(function(error) {
console.error("err ", error);
});
推送通知在设备上成功发送。
但是当我点击通知时,特定页面应该是打开的。
例如 'click_action' : 'openapp/somepage'
然后当我点击推送通知时应该打开“somepage”。
AndroidManifest.xml
<activity android:name="MainActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="openapp" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
我的项目结构
--platforms
--plugins
--www
--app
--about
--about.html
--about.ctrl.js
--product
--product.html
--product.ctrl.js
--css
--js
--lib
index.html
如果我点击通知并想打开产品或关于页面,那么我需要做什么?
这里有什么问题?请告诉我正确的解决方案。
最佳答案
要让您的应用在后台时可以点击通知,您需要 click_action
通知负载中的属性。
请检查这个section Firebase 文档。
此外,当您定义 click_action
属性,您还需要相应的 <action>
<intent-filter>
中的属性您希望启动的 Activity 。
这video非常详细地解释了它。
但是请注意,您不能设置 click__action
如果您要从 Firebase 控制台发送通知,请使用该属性。只有从您自己的管理服务器或使用 Firebase Cloud Functions 发送通知时,您才能这样做。
最后,在启动的 Activity 中,您可以设置额外的 Data
使用数据属性(也显示在我上面链接的同一文档中)。当您通过单击通知启动您的应用程序时,您可以使用 getIntent()
获取通知数据。 .查看this answer有关如何执行此操作的更多详细信息。
问题更新后编辑:-
而不是把 <intent-filter>
在 MainActivity
, 将过滤器放在 <activity>
中单击通知时要打开的 Activity 的标记。一个例子如下:-
<activity android:name="ProductDetailsActivity" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="openapp" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
现在您指定的 Activity 已打开,您可以从 data
中获取信息使用 getIntent()
通知的一部分.
例如,如果您的通知负载具有以下结构,
payload = {
notification: {
title: `You ordered a new product`,
click_action : 'HANDLE_NOTIFICATION',
},
data : {
product_id : 'ABC98292',
type : `Clothes`,
product_name : 'Cotton spring shirt'
}
};
然后你可以得到product_id
来自使用 getIntent().getStringsExtra("product_id")
的通知等等。
这样,您将打开所需的 Activity ,并可以使用从您的通知中获得的相关详细信息填充它,而无需使用任何其他框架。
关于android - 使用 firebase api 打开特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44797486/
我已经设置了 Azure API 管理服务,并在自定义域上配置了它。在 Azure 门户中 API 管理服务的配置部分下,我设置了以下内容: 因为这是一个客户端系统,我必须屏蔽细节,但以下是基础知识:
我是一名习惯 React Native 的新程序员。我最近开始学习 Fetch API 及其工作原理。我的问题是,我找不到人们使用 API key 在他们的获取语句中访问信息的示例(我很难清楚地表达有
这里有很多关于 API 是什么的东西,但是我找不到我需要的关于插件 API 和类库 API 之间的区别。反正我不明白。 在 Documenting APIs 一书中,我读到:插件 API 和类库 AP
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在尝试找出设计以下场景的最佳方法。 假设我已经有了一个 REST API 实现,它将从不同的供应商那里获取书籍并将它们返回给我自己的客户端。 每个供应商都提供单独的 API 来向其消费者提供图书。
请有人向我解释如何使用 api key 以及它有什么用处。 我对此进行了很多搜索,但得到了不同且相互矛盾的答案。有人说 API key 是保密的,它从不作为通信的一部分发送,而其他人则将它发送给客户端
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 4年前关闭。 Improve this
谁能告诉我为什么 WSo2 API 管理器不进行身份验证?我已经设置了两个 WSo2 API Manager 1.8.0 实例并创建了一个 api。它作为原型(prototype) api 工作正常。
我在学习 DSL 的过程中遇到了 Fluent API。 我在流利的 API 上搜索了很多……我可以得出的基本结论是,流利的 API 使用方法链来使代码流利。 但我无法理解——在面向对象的语言中,我们
基本上,我感兴趣的是在多个区域设置 WSO2 API 管理器;例如亚洲、美国和欧洲。一些 API 将部署在每个区域的数据中心内,而其他 API 将仅部署在特定区域内。 理想情况下,我想要的是一个单一的
我正在构建自己的 API,供以下用户使用: 1) 安卓应用 2) 桌面应用 我的网址之一是:http://api.chatapp.info/order_api/files/getbeers.php我的
我需要向所有用户显示我的站点的分析,但使用 OAuth 它显示为登录用户配置的站点的分析。如何使用嵌入 API 实现仪表板但仅显示我的网站分析? 我能想到的最好的可能性是使用 API key 而不是客
我正在研究大公司如何管理其公共(public) API。我想到的是拥有成熟 API 的公司,例如 Google、Facebook、Twitter 和 Amazon。 这些公司向公众公开了许多不同的 A
在定义客户可访问的 API 时,以下是首选的行业惯例: a) 定义一组显式 API 方法,每个方法都有非常狭窄和特定的目的,例如: SetUserName SetUserAge Se
这在本地 deserver 和部署时都会发生。我成功地能够通过留言簿教程使用 API 资源管理器,但现在我已经创建了自己的项目并尝试访问我编写的第一个 API,它从未出现过。搜索栏旁边的黄色“正在加载
我正在尝试使用 http://ip-api.com/ api通过我的ip地址获取经度和纬度。当我访问 http://ip-api.com/json从我的浏览器或使用 curl,它以 json 格式返回
这里的典型示例是 Twitter 的 API。我从概念上理解 REST API 的工作原理,本质上它只是针对您的特定请求向他们的服务器查询,然后您会在其中收到响应(JSON、XML 等),很棒。 但是
我能想到的最好的标题,但要澄清的是,情况是这样的: 我正在开发一种类似短 url 的服务,该服务允许用户使用他们的 Twitter 帐户“登录”并发布内容。现在这项服务可以包含在 Tweetdeck
我正在设计用于管理评论和讨论线程的 API 方案。我想有一个点 /discussions/:discussionId 当您GET 时,它会返回一组评论和一些元数据。评论也许可以单独访问 /discus
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭去年。 Improve this quest
我是一名优秀的程序员,十分优秀!