Skip to content

Reference Service Implementation - #31

Closed
akapelrud wants to merge 1 commit into
kshoji:masterfrom
akapelrud:master
Closed

Reference Service Implementation#31
akapelrud wants to merge 1 commit into
kshoji:masterfrom
akapelrud:master

Conversation

@akapelrud

Copy link
Copy Markdown
Contributor

This is a service implementation that I have used in my own projects. It has been lying around for awhile, so It might need some updates to conform to your latest API changes (especially the OnMidiDeviceAttachedListener part). It does work with the latest version though. I find a service much better to work with when having several MIDI-enabled activities or fragments.

The manifest should include a line within <Application>:

<service android:name="jp.kshoji.driver.midi.service.SingleMidiService" android:exported="false" />

The service can be bound from activities (or fragments) by implementing a ServiceConnection. Something like:

private SingleMidiService mMIDIService = null;
private ServiceConnection mConnection = new ServiceConnection(){
    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        mMIDIService = ((SingleMidiService.LocalBinder)service).getService();
        mMIDIService.getMidiOutputDevice();
    }

    @Override
    public void onServiceDisconnected(ComponentName name) {
        mMIDIService = null;
    }
};

and later started via a startService call or bound by calling:

Intent intent = new Intent(context, SingleMidiService.class);
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE|Context.BIND_IMPORTANT);

Hope this is useful!

@kshoji

kshoji commented Mar 3, 2015

Copy link
Copy Markdown
Owner

Thanks for your nice code and documentation.
I've added the code to the feature branch

My another issue's change caused the confliction. I'll fix it soon..

Regards,
Kaoru

@akapelrud

Copy link
Copy Markdown
Contributor Author

Great!
Your library helped me tremendously with the MIDI aspect of things, so I'm
just glad to contribute.

Regards
André
Trondheim, Norway

On Tue, Mar 3, 2015 at 10:05 AM, Kaoru Shoji notifications@github.com
wrote:

Thanks for your nice code and documentation.
I've added the code to the feature branch
https://github.com/kshoji/USB-MIDI-Driver/tree/feature/pull_request_31

My another issue's change caused the confliction. I'll fix it soon..

Regards,
Kaoru


Reply to this email directly or view it on GitHub
#31 (comment).

@kshoji

kshoji commented Mar 6, 2015

Copy link
Copy Markdown
Owner

The code confliction has been fixed, and merged to develop branch.
I've added another Service for multiple devices with referring to your code..

Thank you again for your contribution.

@kshoji kshoji closed this Mar 6, 2015
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