Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sending broadcast function for integration with other apps #176

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

reesque
Copy link

@reesque reesque commented May 6, 2024

I wanted to have Airpod integration in my own custom launcher and this seems to be a nice way to do so. I appreciate the community's effort in reverse engineering this 👍

Edit: Updated README to reflect this change.

Usage:

Intent parameters

public static final String ACTION_STATUS = "com.dosse.airpods.status";
public static final String EXTRA_IS_ALL_DISCONNECTED = "isAllDisconnected";
public static final String EXTRA_MODEL = "model";
public static final String EXTRA_IS_SINGLE = "isSingle";
public static final String EXTRA_LEFT_POD_STATUS = "leftPodStatus";
public static final String EXTRA_RIGHT_POD_STATUS = "rightPodStatus";
public static final String EXTRA_POD_CASE_STATUS = "caseStatus";
public static final String EXTRA_LEFT_POD_IN_EAR = "leftPodInEar";
public static final String EXTRA_RIGHT_POD_IN_EAR = "rightPodInEar";
public static final String EXTRA_SINGLE_POD_STATUS = "singlePodStatus";
public static final String EXTRA_LEFT_POD_CHARGING = "isLeftPodCharging";
public static final String EXTRA_RIGHT_POD_CHARGING = "isRightPodCharging";
public static final String EXTRA_POD_CASE_CHARGING = "isCaseCharging";
public static final String EXTRA_SINGLE_POD_CHARGING = "isSinglePodCharging";

AndroidManifest.xml

<receiver android:name=".AirpodReceiver"
    android:exported="true"
    android:permission="com.dosse.airpods.permission.ACCESS_AIRPOD_INFORMATION">
    <intent-filter>
        <action android:name="com.dosse.airpods.status"/>
    </intent-filter>
</receiver>

Check and request permission

if (checkSelfPermission(context, "com.dosse.airpods.permission.ACCESS_AIRPOD_INFORMATION") == PackageManager.PERMISSION_DENIED) {
    context.requestPermissions(new String[]{"com.dosse.airpods.permission.ACCESS_AIRPOD_INFORMATION"}, 201);
}

Receiver

public class AirpodReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(ACTION_STATUS)) {
           // Do something with "intent.getExtras()" here
        }
    }
}

Register Receiver

IntentFilter airpodFilter = new IntentFilter(ACTION_STATUS);
AirpodReceiver airpodReceiver = new AirpodReceiver();
registerReceiver(airpodReceiver, airpodFilter);

@seasonyuu
Copy link

Maybe work with permission would be better. https://developer.android.com/develop/background-work/background-tasks/broadcasts#restrict-broadcasts-permissions

@reesque
Copy link
Author

reesque commented May 23, 2024

Added a custom permission, since Bluetooth LE permission, Location permission, etc... have already been handled by OpenPods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants