gpt4 book ai didi

java - android注解@Receiver

转载 作者:太空宇宙 更新时间:2023-11-04 14:23:54 26 4
gpt4 key购买 nike

我正在尝试使用 android 注释库通过两种方式进行广播接收器,但 ide 无法识别此代码中的 @Receiver 或 @ReceiverAction

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import org.androidannotations.annotations.EReceiver;

/**
* Created by M.Hemdan on 11/12/2014.
*/
@EReceiver
public class MyBroadCast extends BroadcastReceiver {
@ReceiverAction(actions = android.content.Intent.VIEW, dataSchemes = "http")
protected void onHttp() {
// Will be called when an App wants to open a http website but not for https.
}

@ReceiverAction(actions = android.content.Intent.VIEW, dataSchemes = {"http", "https"})
protected void onHttps() {
// Will be called when an App wants to open a http or https website.
}
}

如果我尝试其他方式,那么就可以进行 Activity

  @Receiver(actions = android.content.Intent.VIEW, dataSchemes = "http")
protected void onHttp() {
// Will be called when an App wants to open a http website but not for https.
}

@Receiver(actions = android.content.Intent.VIEW, dataSchemes = {"http", "https"})
protected void onHttps() {
// Will be called when an App wants to open a http or https website.
}

这是我看来的错误 image

最佳答案

您需要导入您正在使用的注释类。

例如添加

import org.androidannotations.annotations.Receiver;
import org.androidannotations.annotations.ReceiverAction;

关于java - android注解@Receiver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26882267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com