【问题标题】:Is my broadcast receiver explicit or implicit?我的广播接收器是显式的还是隐式的?
【发布时间】:2018-06-23 06:06:53
【问题描述】:

在阅读了一些关于此的手册 (1,2) 之后,我仍然需要帮助。我将我的应用程序定位到 android O 并且在 android 7.0 上它工作正常,但在 8.1 上我似乎没有得到任何广播。那么,如果在清单中以 android O 为目标并在 7.0 上运行并使用隐式广播,它是否仍然可以工作? 你能帮我确定我的广播是显式的还是隐式的? 我正在使用Awareness API...

清单:

   <receiver android:name=".DetectionBroadcastReceiver" >
        <intent-filter>
            <action android:name="childincar.com.michlindevelopment.DETECTIONFENCE" />
        </intent-filter>
    </receiver>

检测广播接收器

public class DetectionBroadcastReceiver extends BroadcastReceiver {

    Context context;

    @Override
    public void onReceive(Context context, Intent intent) {


        Log.d("DTAG", "onReceive");
        this.context = context;

        if (!TextUtils.equals(Constans.FENCE_RECEIVER_ACTION, intent.getAction())) {
            return;
        }

        //Some Code
    }
}

常量

public class Constans {
    public static final String FENCE_RECEIVER_ACTION = BuildConfig.APPLICATION_ID + ".DETECTIONFENCE";
}

注册

 public static void registerFences(final Context context) {

        Intent intent = new Intent(Constans.FENCE_RECEIVER_ACTION);
        PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);


        Awareness.getFenceClient(context).updateFences(new FenceUpdateRequest.Builder()
                .addFence(Constans.DETECTION_FENCE_DRIVING, DetectedActivityFence.starting(DetectedActivity.IN_VEHICLE), mPendingIntent)
                .addFence(Constans.DETECTION_FENCE_WALKING, DetectedActivityFence.starting(DetectedActivity.WALKING), mPendingIntent)
                .build())
                .addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {

                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });
    }

【问题讨论】:

    标签: android android-broadcastreceiver


    【解决方案1】:

    任何不是“特定”于您的应用的广播都是隐式的。例如,“ACTION_MY_PACKAGE_REPLACED”的广播接收器是特定于您的应用程序的,应该是显式的,而“ACTION_PACKAGE_REPLACED”是隐式的,因为它会通知您所有包。

    您的广播接收器似乎是隐含的,因为它不仅仅是关于/为“您的”应用程序设计的。

    【讨论】:

    • 那我该怎么办呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2016-09-05
    相关资源
    最近更新 更多