Skip to content

Instantly share code, notes, and snippets.

View furkanaskin's full-sized avatar

faskN furkanaskin

View GitHub Profile
adb shell am start -a android.intent.action.VIEW -d slice-{contentURI}
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
<?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"
dependencies {
//
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
//
}
dependencies {
//..
..
//..
}
kotlin {
experimental {
coroutines "enable"
}
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."
}
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'
//
}
<uses-permission android:name="android.permission.INTERNET" />
interface RetrofitService{
@GET("photos")
fun getPhotos(): Deferred<Response<List<Photos>>>
@GET("posts")
fun getPost() : Deferred<Response<List<Posts>>>
}
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)