Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

faskN furkanaskin

🚀
View GitHub Profile
View AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.faskn.sliceexample">
<application
//..
<provider
android:name=".MySliceProvider"
View MySliceProvider.kt
override fun onBindSlice(sliceUri: Uri): Slice? {
return when {
sliceUri.path == "/hello" -> createBasicRowSlice(sliceUri) // path hello'ya eşit olursa basit bir slice oluştur.
else->null
}
}
private fun createBasicRowSlice(sliceUri: Uri): Slice {
return ListBuilder(context, sliceUri, ListBuilder.INFINITY)
.addRow { // satır ekle
View cmd.exe
adb shell am start -a android.intent.action.VIEW -d slice-{contentURI}
View build.gradle(app)
dependencies {
//
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
//
}
View build.gradle(app)
dependencies {
//..
..
//..
}
kotlin {
experimental {
coroutines "enable"
}
View ThreadBlockingActivity.kt
class ThreadBlockingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_thread_blocking)
GlobalScope.launch(Dispatchers.Main){
Toast.makeText(applicationContext,"10 Saniyelik geri sayım başladı.",Toast.LENGTH_SHORT).show()
delay(10000)
tv_thread.text = "10 Saniye sonra değişti."
}
View build.gradle(app)
dependencies {
//
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
//
}
View AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
View RetrofitService.kt
interface RetrofitService{
@GET("photos")
fun getPhotos(): Deferred<Response<List<Photos>>>
@GET("posts")
fun getPost() : Deferred<Response<List<Posts>>>
}
View RetrofitFactory.kt
object RetrofitFactory {
const val BASE_URL = "https://jsonplaceholder.typicode.com/"
fun makeRetrofitService(): RetrofitService {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build().create(RetrofitService::class.java)