-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start android service and call its methods (#98)
- Loading branch information
1 parent
813f6e7
commit a39cd68
Showing
7 changed files
with
129 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 49 additions & 1 deletion
50
android/app/src/main/kotlin/org/rocstreaming/rocdroid/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,63 @@ | ||
package org.rocstreaming.rocdroid | ||
|
||
import AndroidConnector | ||
import android.content.ComponentName | ||
import android.content.Intent | ||
import android.content.ServiceConnection | ||
import android.media.AudioManager | ||
import android.os.Bundle | ||
import android.os.IBinder | ||
import android.util.Log | ||
import io.flutter.embedding.android.FlutterActivity | ||
import io.flutter.embedding.engine.FlutterEngine | ||
import io.flutter.embedding.engine.plugins.FlutterPlugin | ||
import org.rocstreaming.connector.AndroidConnectorImpl | ||
import org.rocstreaming.service.SenderReceiverService | ||
|
||
private const val LOG_TAG = "[rocdroid.MainActivity]" | ||
|
||
class MainActivity: FlutterActivity() { | ||
private lateinit var senderReceiverService: SenderReceiverService | ||
|
||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) { | ||
super.configureFlutterEngine(flutterEngine) | ||
|
||
AndroidConnector.setUp(flutterEngine.dartExecutor.binaryMessenger, | ||
AndroidConnectorImpl()) | ||
} | ||
|
||
private val senderReceiverServiceConnection = object : ServiceConnection { | ||
override fun onServiceConnected(componentName: ComponentName, binder: IBinder) { | ||
senderReceiverService = (binder as SenderReceiverService.LocalBinder).getService() | ||
|
||
Log.d(LOG_TAG, "On service connected") | ||
|
||
AndroidConnectorImpl.senderReceiverService = senderReceiverService | ||
} | ||
|
||
override fun onServiceDisconnected(componentName: ComponentName) { | ||
|
||
Log.d(LOG_TAG, "On service disconnected") | ||
|
||
senderReceiverService.removeListeners() | ||
} | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
Log.d(LOG_TAG, "Create Main Activity") | ||
|
||
val serviceIntent = Intent(this, SenderReceiverService::class.java) | ||
bindService(serviceIntent, senderReceiverServiceConnection, BIND_AUTO_CREATE) | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
volumeControlStream = AudioManager.STREAM_MUSIC | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
unbindService(senderReceiverServiceConnection) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters