在阅读有关此的一些手册(12)之后,我仍然需要帮助。我将我的应用程序定位为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) {

                    }
                });
    }

最佳答案

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

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

关于android - 我的广播接收器是显式的还是隐式的?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50998444/

10-10 00:58