本文介绍了我的广播接收器是显式的还是隐式的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读了一些手册之后( API ...

after reading some manuals (1,2) about this I still need help. I am targeting my app to android O and on android 7.0 it work fine but on 8.1 I don`t seem to get any broadcast. So, if targeting android O in manifest and running on 7.0 and using implicit broadcast should it still work?Can you please help me determine if my broadcast is explicit or implicit?I am using Awareness API...

清单:

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

DetectionBroadcastReceiver

DetectionBroadcastReceiver

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
    }
}

Constans

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) {

                    }
                });
    }


推荐答案

不是应用是隐式的。例如, ACTION_MY_PACKAGE_REPLACED的广播接收器是特定于您的应用的,应该是显式的,而 ACTION_PACKAGE_REPLACED是隐式的,因为它会通知您所有软件包。

Any broadcast that is not 'specific' to your app is implicit. For example the broadcast receiver for 'ACTION_MY_PACKAGE_REPLACED' is specific to your app and should be explicit and the 'ACTION_PACKAGE_REPLACED' is implicit because it informs you about all packages.

您的广播接收器似乎是隐式的,因为它不仅是针对您的应用程序而设计的。

Your broadcast receiver seems implicit since it is not just about/designed-for 'your' application.

这篇关于我的广播接收器是显式的还是隐式的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 21:34