我是Kotlin的新手,也是使用intentService的一点点堆栈.Manifest向我显示一个错误,我的服务不包含默认构造函数,但在服务内部它看起来没问题且没有错误.
这是我的intentService:
class MyService : IntentService {
constructor(name:String?) : super(name) {
}
override fun onCreate() {
super.onCreate()
}
override fun onHandleIntent(intent: Intent?) {
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试了另一种变体:
class MyService(name: String?) : IntentService(name) {
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行此服务时,我仍然会收到错误:
java.lang.Class<com.test.test.MyService> has no zero argument constructor
Run Code Online (Sandbox Code Playgroud)
任何想法如何修复Kotlin中的默认构造函数?
谢谢!
有一个SelectableText小部件可以让您选择文本。但它缺少overflow参数,这是必需的......
有什么解决方法可以使其发挥作用吗?或者类似的解决方案?谢谢!
我正在尝试熟悉Firebase通知.它工作正常,但我没有在应用程序未打开时从通知控制台接收消息.
我知道文档说:
如果您的应用程序在前台或后台,您可以在onMessageReceived方法中接收消息,否则用户将收到托盘中的通知...单击它将打开主要活动与意图内的数据
但即使应用程序关闭,有没有办法从通知控制台捕获每条消息?
==== 答案 ====
在这里找到答案
无法从通知控制台发送数据消息.
但是还有其他方法可以向设备发送通知,它们将被捕获在onMessageReceived中!
您可以使用终端(Mac或Linux)或Postman等服务在此链接上发送Post请求:https://fcm.googleapis.com/fcm/send
与下一个身体:
{
"to": "/topics/your_topic_here",
"data": {
"text":"text",
"text1":"text1",
...
}
}
Run Code Online (Sandbox Code Playgroud)
你还需要添加2个标题:
要获取服务器密钥,可以在firebase控制台中找到它:您的项目 - >设置 - >项目设置 - >云消息 - >服务器密钥
android firebase firebase-cloud-messaging firebase-notifications
我有一个 4*4 的网格视图,但有时可能只有 15 个项目而不是 16 个项目,最后一行看起来不太好......
我想知道有没有办法将 gridView 行中的项目居中?或者可能有其他解决方案可以解决我的任务?
我正在尝试为 firebase 函数设置自定义域。自定义域已经验证并且工作正常。我的 firebase 函数在以下位置运行us-central1:
这是我的函数代码login:
const functions = require("firebase-functions");
const express = require(`express`);
const cors = require(`cors`);
const admin = require(`firebase-admin`);
admin.initializeApp();
const firestore = admin.firestore();
const appLogin = express();
appLogin.use(cors({origin:true}));
appLogin.post("/", async(req:Request, res:Response)=>{
functions.logger.log(`received`);
const body = req.body;
functions.logger.log(body);
const result = await firestore.collection(DbCollections.USER).add(body);
return res.status(201).send(JSON.stringify({"user_id":result.id}));
});
exports.login = functions.https.onRequest(appLogin);
Run Code Online (Sandbox Code Playgroud)
没什么超级花哨的...
因此,当我在邮递员中使用屏幕截图中的 url 时,它工作正常。但我想使用自定义域,如下所示:
https://mydomai.com/api/login
Run Code Online (Sandbox Code Playgroud)
这是我的firebase.json托管部分:
https://mydomai.com/api/login
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用login自定义域时 - 它返回给我,404但没有任何有价值的错误消息:

有任何想法吗?
我是单元测试的新手,我坚持测试以下方法:
fun freeze(view: View) {
view.isClickable = false
handler.postDelayed({
view.isClickable = true
}, CLICK_TIMEOUT)
}
Run Code Online (Sandbox Code Playgroud)
这是我已经拥有的:
@Test
fun freeze() {
var view = mock<View>()
viewUtil.freeze(view)
assertFalse(view.isClickable)
}
Run Code Online (Sandbox Code Playgroud)
但是现在我需要测试该视图在CLICK_TIMEOUT.
我该如何实施这种测试?