主頁 > 移動端開發 > 啪!啪!給 JobIntentService 打針, Hilt 號的大針,看你爽不爽?哎呦,Espresso 看不到結果,用 UiAutomator 測。

啪!啪!給 JobIntentService 打針, Hilt 號的大針,看你爽不爽?哎呦,Espresso 看不到結果,用 UiAutomator 測。

2021-05-04 09:23:55 移動端開發

0. 簡介 Service

Service 不一定用得很長久,那不就成了長傭了嗎?我們可以用 JobIntentService ——臨時傭人,它跟你的 App 同生共死,真好!但是,啟動容易,關閉就毫無頭緒了,因為 Service 在后臺跑,跟 UI 是不沾邊的,如果用 MVVM,我們可以塞 LiveData ,通過方程啟動,系統會彈出 “LiveData has not initialed”,如果用 Service 的建構式,系統會說不接受引數,饒頭啊,對不?

沒關系,我們可以使用插入式,我提議的是 Dagger-Hilt ,給系統打針,


📦 1. MVVM 包

🌮 Gradle —— 資料庫選擇:

  • View Binding:
buildFeatures {
    viewBinding true
}
  • Dagger Hilt ——請自學安裝,
  • ViewModel:
//region activity and fragment
// Activity and Fragment
def activity_version = "1.2.1"
implementation "androidx.activity:activity-ktx:$activity_version"
def fragment_version = "1.3.2"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
debugImplementation "androidx.fragment:fragment-testing:$fragment_version"
//endregion

這里隨便提提,其實你們可以抄我以前寫的,Gradle 太占地方了,所以省略一二,

🔰 MVVM —— 檔案排列

在這里插入圖片描述

🖐🏻 Helper —— 幫手

  • helper/LogHelper.kt
import android.util.Log

const val TAG = "MLOG"
fun lgd(s:String) = Log.d(TAG, s)
fun lgi(s:String) = Log.i(TAG, s)
fun lge(s:String) = Log.e(TAG, s)
fun lgv(s:String) = Log.v(TAG, s)
fun lgw(s:String) = Log.w(TAG, s)
  • helper/MessageHelper.kt
import android.content.Context
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import android.widget.Toast.LENGTH_SHORT

fun msg(context: Context, s: String, len: Int) =
    if (len > 0) Toast.makeText(context, s, LENGTH_LONG).show()
    else Toast.makeText(context, s, LENGTH_SHORT).show()

🖌? 2. UI Design 平面設計


et_message :輸入資料進Service,
tv_service :Service 的反應,


💼 3. JobIntentService

JobIntentService 是 IntentService 的改良版,

🐔 開始服務

這個服務是用方程啟動的——enqueueWork

fun enqueueWork(context: Context, work: Intent) {
    enqueueWork(context, MyIntentService::class.java, JOB_ID, work)
}

這個 enqueueWork 有 4 種引數:

  1. Context
  2. Service class
  3. Job ID
  4. Intent

?? 關閉服務

用 instance 關閉,

class MyIntentService: JobIntentService() {

    init {
        instance = this
    }
    
	companion object {
		private lateinit var instance: MyIntentService
		private val JOB_ID = 4343443

		fun enqueueWork(context: Context, work: Intent) {...}

		fun stopService() {
			lgd("MyIntentService: Service is stopping...")
			instance.stopSelf()
		}
	}
}

你瞧,自己關自己,


🚪 4. Permission

📍 AndroidManifest.xml

<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
    ...
    <activity android:name=".ui.MainActivity">
        ...
    </activity>
    <service android:name=".service.MyIntentService"
        android:permission="android.permission.BIND_JOB_SERVICE"
        android:exported="true" />
</application>

?? ui/MainActivity.kt

// check manifests for permissions
private val REQUIRED_PERMISSIONS = arrayOf(
    Manifest.permission.WAKE_LOCK
)

class MainActivity : AppCompatActivity() {

    // app permission
    private val reqMultiplePermissions = registerForActivityResult(
        ActivityResultContracts.RequestMultiplePermissions()
    ) { permissions ->
        permissions.entries.forEach {
            lgd("mainAct: Permission: ${it.key} = ${it.value}")
            if (!it.value) {
                // toast
                msg(this, "Permission: ${it.key} denied!", 1)
                finish()
            }
        }
    }

    // =============== Variables
    // view binding
    private lateinit var binding: ActivityMainBinding
    // view model
    val viewModel: MainViewModel by viewModels()

    // =============== END of Variables

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)

        // check app permissions
        reqMultiplePermissions.launch(REQUIRED_PERMISSIONS)
    }

    companion object {
        const val USER_INPUT = "USER_INPUT"
    }
}

?5. Observables & Hilt 觀察和打針

👁?🗨 觀察點

我需要提供兩個觀察點:

  1. isRunning:服務狀態,
  2. userInput:客戶輸入的內容,有兩種方式 IntentExtra 和 LiveData ,我將會測驗那種有保證,

🔆 app/ServiceApp.kt 提供 Hilt 應用

@HiltAndroidApp
class ServiceApp: Application()

🗡 di/LiveDataModule.kt

@Module
@InstallIn(SingletonComponent::class)
object LiveDataModule {

    @Provides
    @Singleton
    fun provideServiceStatus(): 
        MutableLiveData<Boolean> = MutableLiveData<Boolean>()

    @Provides
    @Singleton
    fun provideUserInput(): 
        MutableLiveData<String> = MutableLiveData<String>()
    
}

簡單吧,就伺候這倆,

?? ui/MainViewModel.kt

@HiltViewModel
class MainViewModel @Inject constructor(
    val isRunning: MutableLiveData<Boolean>,
    private val userInput: MutableLiveData<String>
): ViewModel() {

    init {
        isRunning.value = false
        userInput.value = ""
    }

    fun enableService() {
        isRunning.postValue(true)
    }

    fun updateUserInput(inputText: String) {
        userInput.postValue(inputText)
    }
}

主要功能是更新畫面,

🔧 service/MyIntentService.kt

@AndroidEntryPoint
class MyIntentService: JobIntentService() {

    @Inject
    lateinit var isRunning: MutableLiveData<Boolean>

    @Inject
    lateinit var userInput: MutableLiveData<String>

    init {
        instance = this
    }

    override fun onHandleWork(intent: Intent) {
        lgd("onHandleWork")
        try {
            lgd("MyIntentService: Service is running...")
            if (isRunning.value!!) {

                // check Intent Extra
                val extraInput = intent.getStringExtra(USER_INPUT)
                lgd("Intent Extra: $extraInput")
                
                var input = "Empty"
                if (userInput.value != "")
                    input = userInput.value.toString()

                lgd("receive text from LiveData: $input")

                for (i in 0..9) {
                    lgd("Input: $input - $i")
                    if (isRunning.value == false)
                        return
                    SystemClock.sleep(1000)
                }
                stopService()
            }
        } catch (e: InterruptedException) {
            Thread.currentThread().interrupt()
        }
    }
...

🔨 ui/MainActivity.kt

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
    ...

    override fun onCreate(savedInstanceState: Bundle?) {
        ...

        binding.btStart.setOnClickListener {
            viewModel.enableService()

            // update user input
            val inputText = binding.etMessage.text
            if (!inputText.isEmpty() || !inputText.isBlank())
                viewModel.updateUserInput(inputText.toString())
            lgd("input text: $inputText")

            val mIntent = Intent(this, MyIntentService::class.java)
            mIntent.putExtra(USER_INPUT, inputText)

            // start service
            MyIntentService.enqueueWork(this, mIntent)
        }

        binding.btStop.setOnClickListener {
            MyIntentService.stopService()

        }

        // observer
        viewModel.isRunning.observe(this, {
            if (it)
                binding.tvService.text = "Service is Start..."
            else
                binding.tvService.text = "Service is Stop!"
        })
    }

    companion object {...}
}

按鍵提供打開服務,關閉服務,
還有就是觀察服務狀態,


🏃🏻 6. 運行結果

startStop
狀態良好,看看 Logcat:

--------- beginning of system
2021-04-24 14:39:27.113 6199-7154 D/MLOG: onHandleWork
2021-04-24 14:39:27.113 6199-7154 D/MLOG: MyIntentService: Service is running...
2021-04-24 14:39:27.123 6199-7154 D/MLOG: Intent Extra: null
2021-04-24 14:39:27.123 6199-7154 D/MLOG: receive text from LiveData: Empty
2021-04-24 14:39:27.123 6199-7154 D/MLOG: Input: Empty - 0
2021-04-24 14:39:28.164 6199-7154 D/MLOG: Input: Empty - 1
2021-04-24 14:39:29.205 6199-7154 D/MLOG: Input: Empty - 2
2021-04-24 14:39:30.246 6199-7154 D/MLOG: Input: Empty - 3
2021-04-24 14:39:31.273 6199-7154 D/MLOG: Input: Empty - 4
2021-04-24 14:39:32.318 6199-7154 D/MLOG: Input: Empty - 5
2021-04-24 14:39:33.360 6199-7154 D/MLOG: Input: Empty - 6
2021-04-24 14:39:34.375 6199-7154 D/MLOG: Input: Empty - 7
2021-04-24 14:39:35.380 6199-7154 D/MLOG: Input: Empty - 8
2021-04-24 14:39:36.384 6199-7154 D/MLOG: Input: Empty - 9
2021-04-24 14:39:37.387 6199-7154 D/MLOG: MyIntentService: Service is stopping...

加入 Welcome, 看看 Service 是否收到,
welcome
Logcat:

2021-04-24 14:44:55.110 6199-6199 D/MLOG: input text: Welcome
2021-04-24 14:44:55.126 6199-7154 D/MLOG: onHandleWork
2021-04-24 14:44:55.126 6199-7154 D/MLOG: MyIntentService: Service is running...
2021-04-24 14:44:55.127 6199-7154 D/MLOG: Intent Extra: null
2021-04-24 14:44:55.127 6199-7154 D/MLOG: receive text from LiveData: Welcome
2021-04-24 14:44:55.127 6199-7154 D/MLOG: Input: Welcome - 0
2021-04-24 14:44:56.168 6199-7154 D/MLOG: Input: Welcome - 1
2021-04-24 14:44:57.211 6199-7154 D/MLOG: Input: Welcome - 2
2021-04-24 14:44:58.251 6199-7154 D/MLOG: Input: Welcome - 3
2021-04-24 14:44:59.293 6199-7154 D/MLOG: Input: Welcome - 4
2021-04-24 14:45:00.334 6199-7154 D/MLOG: Input: Welcome - 5
2021-04-24 14:45:01.377 6199-7154 D/MLOG: Input: Welcome - 6
2021-04-24 14:45:02.418 6199-7154 D/MLOG: Input: Welcome - 7
2021-04-24 14:45:03.460 6199-7154 D/MLOG: Input: Welcome - 8
2021-04-24 14:45:04.501 6199-7154 D/MLOG: Input: Welcome - 9
2021-04-24 14:45:05.542 6199-7154 D/MLOG: MyIntentService: Service is stopping...

IntentExtra 接收失敗,
LiveData 成功,


? 7. Espresso 測驗

? 加測驗

右鍵點擊 “class MyIntentService”, 然后 Alt+Insert ,
test
選 Junit4:
junit4
androidTest 檔案夾:
androidTest

🔭 service/MyIntentServiceTest.kt

@ExperimentalCoroutinesApi
@LargeTest
@HiltAndroidTest
class MyIntentServiceTest {

    @get:Rule(order = 1)
    var hiltRule = HiltAndroidRule(this)

    @get:Rule(order = 2)
    var activityRule = ActivityScenarioRule(MainActivity::class.java)


    @Before
    fun setup() {
        hiltRule.inject()
    }

🍬 helper/Constants.kt —— 常數

const val START = "Service is Start..."
const val STOP = "Service is Stop!"

? Stop Test Case —— 停止測驗

@Test
fun test_stop_service_espresso() {
    lgd("=====>  Stop Service Test")

    // start activity
    val scenario = activityRule.getScenario()

    onView(withId(R.id.bt_start)).perform(click())
    lgd("=====>  Start Button Clicked")

    onView(withId(R.id.bt_stop)).perform(click())
    lgd("=====>  Stop Button Clicked")

    val serviceMsg = onView(withId(R.id.tv_service))
    serviceMsg.check(ViewAssertions.matches(
        ViewMatchers.withText(STOP)))
}

ok
好像很正常,讓我們看看 Logcat :

2021-04-27 07:57:31.223 20493-20703 D/MLOG: MyIntentService: Service is running...
2021-04-27 07:57:31.230 20493-20703 D/MLOG: Intent Extra: null
2021-04-27 07:57:31.230 20493-20703 D/MLOG: receive text from LiveData: Empty
2021-04-27 07:57:31.230 20493-20703 D/MLOG: Input: Empty - 0
2021-04-27 07:57:32.278 20493-20703 D/MLOG: Input: Empty - 1
2021-04-27 07:57:33.313 20493-20703 D/MLOG: Input: Empty - 2
2021-04-27 07:57:34.345 20493-20703 D/MLOG: Input: Empty - 3
2021-04-27 07:57:35.356 20493-20703 D/MLOG: Input: Empty - 4
2021-04-27 07:57:36.393 20493-20703 D/MLOG: Input: Empty - 5
2021-04-27 07:57:37.434 20493-20703 D/MLOG: Input: Empty - 6
2021-04-27 07:57:38.473 20493-20703 D/MLOG: Input: Empty - 7
2021-04-27 07:57:39.475 20493-20703 D/MLOG: Input: Empty - 8
2021-04-27 07:57:40.521 20493-20703 D/MLOG: Input: Empty - 9
2021-04-27 07:57:41.558 20493-20703 D/MLOG: MyIntentService: Service is stopping...
2021-04-27 07:57:41.792 20493-20533 D/MLOG: =====>  Start Button Clicked
2021-04-27 07:57:41.850 20493-20493 D/MLOG: MainAct: stop button clicked!
2021-04-27 07:57:41.850 20493-20493 D/MLOG: MyIntentService: Service is stopping...
2021-04-27 07:57:42.089 20493-20533 D/MLOG: =====>  Stop Button Clicked

糟透了,Espresso 在 Service 停止后才出來干活,因此,我們需要另一種工具來測驗 —— UiAutomator ,


🚍 8. UiAutomator

📌 gradle.module

//UiAutomator
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

Sync,

📢 MyIntentJobServiceTest

@get:Rule(order = 1)
var hiltRule = HiltAndroidRule(this)

這個保留,

private var mDevice: UiDevice? = null

啟動:

@Before
fun setup() {
    hiltRule.inject()

    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(getInstrumentation())
    mDevice!!.pressMenu()
    val launcherPackage = mDevice!!.launcherPackageName
    Truth.assertThat(launcherPackage).isNotNull()

    mDevice!!.wait(
        Until.hasObject(By.pkg(launcherPackage).depth(0)),
        LAUNCH_TIMEOUT
    )

    // launch app
    val context = ApplicationProvider.getApplicationContext<Context>()
    val intent = context.packageManager.getLaunchIntentForPackage(
        APPLICATION_ID)?.apply {
        // Clear out any previous instances
        addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
    }
    context.startActivity(intent)

    // Wait for the app to appear
    mDevice!!.wait(
        Until.hasObject(By.pkg(APPLICATION_ID).depth(0)),
        LAUNCH_TIMEOUT
    )
}
companion object {
    const val LAUNCH_TIMEOUT = 5000L
}

加 Test :

@Test
fun test_stop_service_uiautomator() {
}

🔍 用 ID 找物體

UiAutomator 找東西跟安卓是一樣的:

val $var$ = mDevice!!.findObject(
    res("${APPLICATION_ID}:id/$obj$"))

這是 Live Template 捷徑,

讓我們加兩個按鍵:

// buttons
val startBt = mDevice!!.findObject(
    res("${APPLICATION_ID}:id/bt_start"))
val stopBt = mDevice!!.findObject(
    res("${APPLICATION_ID}:id/bt_stop"))

同樣程序再試試:啟動服務 → 停止服務 → 檢查

lgd("start bt: ${startBt.resourceName}")
startBt.click()

Thread.sleep(1000L)

lgd("stop bt: ${stopBt.resourceName}")
stopBt.click()

// service message
val serviceMsg = mDevice!!.findObject(
    res("${APPLICATION_ID}:id/tv_service"))
val statusStr = serviceMsg.text
Truth.assertThat(statusStr).isEqualTo(STOP)

🚴跑啊:
test2
這次,你應該看到測驗沒有用到 10 秒,幾乎立刻就停止了,所以這是成功的測驗,


🚁 9. UiAutomator — UserInput 輸入測驗

👁?🗨 LogOutput.kt —— Log 輸出

我們可以截取一部分 Log 來檢查成果,

/**
 *  Editor: Homan Huang
 *  Date: 04/27/2021
 */
/**
 *  Get Logcat output by getOutput("logcat *:S TAG -d")
 */
fun getOutput(command: String): String? {
    val proc = Runtime.getRuntime().exec(command)

    try {
        val stdInput = BufferedReader(
            InputStreamReader(
                proc.inputStream
            )
        )
        val output = StringBuilder()
        var line: String? = ""
        //var counter = 0
        while (stdInput.readLine().also { line = it } != null) {
            //counter += 1
            //lgd("line #$counter = $line")
            output.append(line+"\n")
        }
        stdInput.close()
        return output.toString()
    } catch (e: IOException) {
        e.printStackTrace()
    }
    return null
}

/**
 *  clear logcat buffer
 */
fun clearLog() {
    Runtime.getRuntime().exec("logcat -c")
}

📳 輸入測驗

/**
 *  Test: Input the message;
 *        start the service;
 *        and check logcat
 */
@Test
fun message_input_service_uiautomator() {
    // buttons
    val msgInput = mDevice!!.findObject(
        res("${APPLICATION_ID}:id/et_message"))
    val startBt = mDevice!!.findObject(
        res("${APPLICATION_ID}:id/bt_start"))
    val stopBt = mDevice!!.findObject(
        res("${APPLICATION_ID}:id/bt_stop"))

    // clear Logcat buffer
    clearLog()

    // input
    val toServiceStr = "This is a test."
    msgInput.text = toServiceStr
    Thread.sleep(1000)

    lgd("start bt: ${startBt.resourceName}")
    startBt.click()

    Thread.sleep(1000)

    lgd("stop bt: ${stopBt.resourceName}")
    stopBt.click()

    val param = "logcat *:S MLOG -d"
    lgd("param: $param")
    val mLog = getOutput(param)

    Thread.sleep(500)

    lgd("mlog: $mLog")

    Truth.assertThat(mLog?.contains("Input: $toServiceStr"))
        .isTrue()
}

跑啊!截取 Logcat:

mlog: --------- beginning of main
    04-27 14:06:29.582 31368 31368 D MLOG    : mainAct: Permission: android.permission.WAKE_LOCK = true
    04-27 14:06:31.459 31368 31400 D MLOG    : start bt: com.homan.huang.servicedemo:id/bt_start
    04-27 14:06:31.504 31368 31368 D MLOG    : MainAct: start button clicked!
    04-27 14:06:31.504 31368 31368 D MLOG    : input text: This is a test.
    04-27 14:06:31.527 31368 31419 D MLOG    : onHandleWork
    04-27 14:06:31.527 31368 31419 D MLOG    : MyIntentService: Service is running...
    04-27 14:06:31.528 31368 31419 D MLOG    : Intent Extra: null
    04-27 14:06:31.528 31368 31419 D MLOG    : receive text from LiveData: This is a test.
    04-27 14:06:31.528 31368 31419 D MLOG    : Input: This is a test. - 0
    04-27 14:06:32.495 31368 31400 D MLOG    : stop bt: com.homan.huang.servicedemo:id/bt_stop
    04-27 14:06:32.519 31368 31400 D MLOG    : param: logcat *:S MLOG -d
    04-27 14:06:32.525 31368 31368 D MLOG    : MainAct: stop button clicked!
    04-27 14:06:32.525 31368 31368 D MLOG    : MyIntentService: Service is stopping...

測驗通過!


🍞 10. 英文版

幫幫忙,拍拍手!
英文連接: 💉Inject LiveData into JobIntentService and How to🔫 Test It

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/282642.html

標籤:其他

上一篇:EasyClick 原生UI連載三十一

下一篇:自定義PopupWindow實作下拉選擇框并進行選擇資料傳遞

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 【從零開始擼一個App】Dagger2

    Dagger2是一個IOC框架,一般用于Android平臺,第一次接觸的朋友,一定會被搞得暈頭轉向。它延續了Java平臺Spring框架代碼碎片化,注解滿天飛的傳統。嘗試將各處代碼片段串聯起來,理清思緒,真不是件容易的事。更不用說還有各版本細微的差別。 與Spring不同的是,Spring是通過反射 ......

    uj5u.com 2020-09-10 06:57:59 more
  • Flutter Weekly Issue 66

    新聞 Flutter 季度調研結果分享 教程 Flutter+FaaS一體化任務編排的思考與設計 詳解Dart中如何通過注解生成代碼 GitHub 用對了嗎?Flutter 團隊分享如何管理大型開源專案 插件 flutter-bubble-tab-indicator A Flutter librar ......

    uj5u.com 2020-09-10 06:58:52 more
  • Proguard 常用規則

    介紹 Proguard 入口,如何查看輸出,如何使用 keep 設定入口以及使用實體,如何配置壓縮,混淆,校驗等規則。

    ......

    uj5u.com 2020-09-10 06:59:00 more
  • Android 開發技術周報 Issue#292

    新聞 Android即將獲得類AirDrop功能:可向附近設備快速分享檔案 谷歌為安卓檔案管理應用引入可安全隱藏資料的Safe Folder功能 Android TV新主界面將顯示電影、電視節目和應用推薦內容 泄露的Android檔案暗示了傳說中的谷歌Pixel 5a與折疊屏新機 谷歌發布Andro ......

    uj5u.com 2020-09-10 07:00:37 more
  • AutoFitTextureView Error inflating class

    報錯: Binary XML file line #0: Binary XML file line #0: Error inflating class xxx.AutoFitTextureView 解決: <com.example.testy2.AutoFitTextureView android: ......

    uj5u.com 2020-09-10 07:00:41 more
  • 根據Uri,Cursor沒有獲取到對應的屬性

    Android: 背景:呼叫攝像頭,拍攝視頻,指定保存的地址,但是回傳的Cursor檔案,只有名稱和大小的屬性,沒有其他諸如時長,連ID屬性都沒有 使用 cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATIO ......

    uj5u.com 2020-09-10 07:00:44 more
  • Android連載29-持久化技術

    一、持久化技術 我們平時所使用的APP產生的資料,在記憶體中都是瞬時的,會隨著斷電、關機等丟失資料,因此android系統采用了持久化技術,用于存盤這些“瞬時”資料 持久化技術包括:檔案存盤、SharedPreference存盤以及資料庫存盤,還有更復雜的SD卡記憶體儲。 二、檔案存盤 最基本存盤方式, ......

    uj5u.com 2020-09-10 07:00:47 more
  • Android Camera2Video整合到自己專案里

    背景: Android專案里呼叫攝像頭拍攝視頻,原本使用的 MediaStore.ACTION_VIDEO_CAPTURE, 后來因專案需要,改成了camera2 1.Camera2Video 官方demo有點問題,下載后,不能直接整合到專案 問題1.多次拍攝視頻崩潰 問題2.雙擊record按鈕, ......

    uj5u.com 2020-09-10 07:00:50 more
  • Android 開發技術周報 Issue#293

    新聞 谷歌為Android TV開發者提供多種新功能 Android 11將自動填表功能整合到鍵盤輸入建議中 谷歌宣布Android Auto即將支持更多的導航和數字停車應用 谷歌Pixel 5只有XL版本 搭載驍龍765G且將比Pixel 4更便宜 [圖]Wear OS將迎來重磅更新:應用啟動時間 ......

    uj5u.com 2020-09-10 07:01:38 more
  • 海豚星空掃碼投屏 Android 接收端 SDK 集成 六步驟

    掃碼投屏,開放網路,獨占設備,不需要額外下載軟體,微信掃碼,發現設備。支持標準DLNA協議,支持倍速播放。視頻,音頻,圖片投屏。好點意思。還支持自定義基于 DLNA 擴展的操作動作。好像要收費,沒體驗。 這里簡單記錄一下集成程序。 一 跟目錄的build.gradle添加私有mevan倉庫 mave ......

    uj5u.com 2020-09-10 07:01:43 more
最新发布
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:40:31 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:40:11 more
  • 歡迎頁輪播影片

    如圖,引導開始,球從上落下,同時淡入文字,然后文字開始輪播,最后一頁時停止,點擊進入首頁。 在來看看效果圖。 重力球先不講,主要歡迎輪播簡單實作 首先新建一個類 TextTranslationXGuideView,用于影片展示 文本是類似的,最后會有個圖片箭頭影片,布局很簡單,就是一個 TextVi ......

    uj5u.com 2023-04-20 08:39:36 more
  • 【FAQ】關于華為推送服務因營銷訊息頻次管控導致服務通訊類訊息

    一. 問題描述 使用華為推送服務下發IM訊息時,下發訊息請求成功且code碼為80000000,但是手機總是收不到訊息; 在華為推送自助分析(Beta)平臺查看發現,訊息發送觸發了頻控。 二. 問題原因及背景 2023年1月05日起,華為推送服務對咨詢營銷類訊息做了單個設備每日推送數量上限管理,具體 ......

    uj5u.com 2023-04-20 08:39:13 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:16:23 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:16:15 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:15:46 more
  • iOS從UI記憶體地址到讀取成員變數(oc/swift)

    開發除錯時,我們發現bug時常首先是從UI顯示發現例外,下一步才會去定位UI相關連的資料的。XCode有給我們提供一系列debug工具,但是很多人可能還沒有形成一套穩定的除錯流程,因此本文嘗試解決這個問題,順便提出一個暴論:UI顯示例外問題只需要兩個步驟就能完成定位作業的80%: 定位例外 UI 組 ......

    uj5u.com 2023-04-19 09:14:53 more
  • FIDE重磅更新!性能飛躍!體驗有禮!

    FIDE 開發者工具重構升級啦!實作500%性能提升,誠邀體驗! 一直以來不少開發者朋友在社區反饋,在使用 FIDE 工具的程序中,時常會遇到諸如加載不及時、代碼預覽/渲染性能不如意的情況,十分影響開發體驗。 作為技術團隊,我們深知一件趁手的開發工具對開發者的重要性,因此,在2023年開年,FinC ......

    uj5u.com 2023-04-19 09:14:08 more
  • 游戲內嵌社區服務開放,助力開發者提升玩家互動與留存

    華為 HMS Core 游戲內嵌社區服務提供快速訪問華為游戲中心論壇能力,支持玩家直接在游戲內瀏覽帖子和交流互動,助力開發者擴展內容生產和觸達的場景。 一、為什么要游戲內嵌社區? 二、游戲內嵌社區的典型使用場景 1、游戲內打開論壇 您可以在游戲內繪制論壇入口,為玩家提供沉浸式發帖、瀏覽、點贊、回帖、 ......

    uj5u.com 2023-04-19 09:08:34 more