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
public class PlayServicesUtils { | |
public static boolean checkGooglePlayServices(final Activity activity) { | |
final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); | |
switch (googlePlayServicesCheck) { | |
case ConnectionResult.SUCCESS: | |
return true; | |
case ConnectionResult.SERVICE_DISABLED: | |
case ConnectionResult.SERVICE_INVALID: | |
case ConnectionResult.SERVICE_MISSING: | |
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: |
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
public class RxBusExample { | |
RxBus bus = RxBus.getInstance(); | |
bus.post(); | |
} |
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
inline fun <reified T> createWebService(okHttpClient: OkHttpClient, url: String): T { | |
val retrofit = Retrofit.Builder() | |
.baseUrl(url) | |
.client(okHttpClient) | |
.addConverterFactory(ScalarsConverterFactory.create()) // <--- 避免產生雙引號在multipart-formdata的參數中 | |
.addConverterFactory(GsonConverterFactory.create()) // <-- ScalarsConverterFactory要放在GsonConverterFactory之前 | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build() | |
return retrofit.create(T::class.java) | |
} |
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
android { | |
compileSdkVersion 28 | |
... | |
/** | |
* 解決: | |
* Kotlin: Calls to static methods in Java interfaces are prohibited in JVM target 1.6. Recompile with '-jvm-target 1.8' | |
* 參考: | |
* https://stackoverflow.com/a/52561908/307442 |
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
fun exampleOfAudioFocus() { | |
// AUDIOFOCUS_GAIN : 嘗試取得非特定時間長度的Audio focus | |
// AUDIOFOCUS_GAIN_TRANSIENT, 取得一個短時間的focus,例如導航的提示音 | |
// AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, 取得一個短時間的focus,但是可以跟其他App播放的聲音一起播放,例如導航的提示音,蓋在背景音樂上 | |
// AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE, 預期取得一個獨佔的focus,佔有這個focus的期間,其他App應該安靜,例如語音筆記或是語音辨識 | |
// 要播放聲音前,先取得Audio focus | |
// Audio focus改變時,會透過Listener通知 | |
val gain = AudioManager.AUDIOFOCUS_GAIN | |
val request = AudioFocusRequest.Builder(gain) |
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
/** | |
* Wraps the parameters of onActivityResult | |
* | |
* @property resultCode the result code returned from the activity. | |
* @property data the optional intent returned from the activity. | |
* @since 0.0.3 | |
*/ | |
data class ActivityResult( | |
val requestCode: Int, | |
val resultCode: Int, |
OlderNewer