android.intent.action.MY_PACKAGE_REPLACED をBorodcastReceiver で反応させるテスト

Debug でなく Run ボタンでいけてたような気がするが
セキュリティの絡みか、今では反応がない。

なので、

コマンドラインで adb から。


❯ adb shell am broadcast -a android.intent.action.MY_PACKAGE_REPLACED
Broadcasting: Intent { act=android.intent.action.MY_PACKAGE_REPLACED flg=0x400000 }

Exception occurred while executing 'broadcast':
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.MY_PACKAGE_REPLACED from pid=6153, uid=2000

ダメですか。

またセキュリティですか。

 

🤔 解決法

一度、ビルドして、 apk をインストールしたらいけた。

Go to Build -> Build APK, and note the location that the .apk is stored.

Then, run in terminal:

adb install -r debugapp.apk

This will trigger the MY_PACKAGE_REPLACED intent, since newer Android SDKs only allow the system to broadcast it.

👉 Android: Broadcast ACTION_MY_PACKAGE_REPLACED never received - Stack Overflow

-r」いるんかね ? いらなくね ?

 

🤔 まとめ

今後以下でやろう。


❯ ./gradlew assembleDebug  
                         
> Configure project :app
BUILD SUCCESSFUL in 59s
42 actionable tasks: 21 executed, 21 up-to-date

❯ find . -name "*.apk" | fzf | xargs adb install

Performing Streamed Install
Success

❯ adb shell am start -a android.intent.action.MAIN -n YOUR_PACKAGE/.TARGET_ACTIVITY 

Starting: Intent { act=android.intent.action.MAIN cmp=YOUR_PACKAGE/.TARGET_ACTIVITY }

当然、バージョン番号は上げておかなければなりません。

👉 junegunn/fzf: :cherry_blossom: A command-line fuzzy finder


Jetpack Compose 「Modifierは子1つ目だけに適用する」の考え方

実際のコード例で考えてみる。


Column {
  Text(
    text = "Hello",
    modifier = Modifier.padding(16.dp)
  )
  Text(
    text = "World",
    modifier = Modifier.padding(16.dp)
  )
}


val modifier = Modifier.padding(16.dp)

Column {
  Text(text = "Hello", modifier = modifier)
  Text(text = "World", modifier = modifier)
}


Column(
  modifier = Modifier.padding(16.dp)
) {
  Text(text = "Hello")
  Text(text = "World")
}


@Composable
fun ParentLayout() {
  Column(
    modifier = Modifier.verticalScroll(rememberScrollState())
  ) {
    for (i in 1..10) {
      ListItem(
        text = "Item $i",
        modifier = Modifier.padding(8.dp)
      )
    }
  }
}

@Composable
fun ListItem(modifier: Modifier, text: String) {
  Text(
    text = text,
    modifier = modifier.background(Color.LightGray)
  )
}

共有することの意味は「統一性」だろうけども、

見通しが悪くなるので「1つ目まで」としているのだろう。

「まずは個別につけてから共通部分をホイストしていく。」

「親から渡すときは子まで影響。孫は個別に。」

そんな考え方の順番が簡単で自然だと思います。


Android Architecture Samples でみる JetpackCompose UI コンポーネントのネスト



表示されてるコンテンツまでにいくつかのコンポーネントを経由している。

👉 architecture-samples/app/src/main/java/com/example/android/architecture/blueprints/todoapp/TodoNavGraph.kt at 130f5dbebd0c7b5ba195cc08f25802ed9f0237e5 · android/architecture-samples

中心は、NavGraph として利用されている NavHost

ModalDrawer ごと切り替えてる。


Activity
  + NavHost
    + ModalDrawer
      + 【Screen】
        + Scaffold
          + SwipeRefresh
            + 【Content】    
    + ModalDrawer
      + 【Screen】
        + Scaffold
          + SwipeRefresh
            + 【Content】
    + ModalDrawer
      + 【Screen】
        + Scaffold
          + SwipeRefresh
            + 【Content】

きっと、使いやすい理にかなった入れ子関係なのだろう。


Activity
   ↓
NavHost
   ↓ 1:*
ModalDrawer
   ↓
【Screen】
   ↓
Scaffold
   ↓
SwipeRefresh
   ↓
【Content】

参考にしたいですね。

👉 android/architecture-samples: A collection of samples to discuss and showcase different architectural tools and patterns for Android apps.


ポリシーステータス「アプリは Android 14(API レベル 34) 以降を対象とする必要があります。」が消えない

かなり遅れて、今さらなのですが。

このポリシーステータスのメッセージ。


アプリは Android 14(API レベル 34) 以降を対象とする必要があります。

アプリ自体は、

SDKのターゲットバージョン35にして

公開完了してるにこのメッセージが消えない。

なんでかな。

 

🧑🏻‍💻 すぐには消えない?

Check that all tracks are updated (even paused tracks). If they are then give it a few days for the message to disappear.

すべてのトラックが更新されていることを確認してください(一時停止したトラックも)。もしそうなら、メッセージが消えるまで数日待ってください。

👉 How can I clear this message because now my target API is 34 - Google Play Developer Community

It turned out that I need to wait for 24 hours for the message to disappear. I don't know why it's not instant even though the target api is clearly within the policy requirements. Maybe they check these manually. Anyway it's solved.

メッセージが消えるまで24時間待つ必要があることが判明しました。ターゲットAPIが明らかにポリシー要件の範囲内であるにもかかわらず、なぜそれが即時ではないのかわかりません。おそらく彼らはこれらを手動でチェックします。とにかく解決しました。

👉 i still get this warning (App must target Android 14 (API level 34) or higher) even though iupdated - Google Play Developer Community

 

🧑🏻‍💻 結果

大体6時間後に確認すると消えてました!


Android のアーキテクチャで何が Google に「強く推奨」されているか図で理解する

👉 Recommendations for Android architecture  |  Android Developers

分かりやすいドキュメントなのでさらに分かりやすくなるように図にしてみます。

 

🤔 Layered Architecture


UI Layer
  |
Coroutine
  |
DataL Layer
  |
Repository

👉 Layered architecture - Recommendations for Android architecture  |  Android Developers

 

🤔 UI Layer


UI Layer
  UDF
  AAC ViewModel
  Lifecycle
  User Event

👉 UI layer - Recommendations for Android architecture  |  Android Developers

 

🤔 ViewModel


ViewModel
  Depencencies
  Coroutine Flow
  State Holder

👉 ViewModel - Recommendations for Android architecture  |  Android Developers

 

🤔 Lifecycle


Lifecycle
  LifecycleObserver

👉 Lifecycle - Recommendations for Android architecture  |  Android Developers


 

🤔 Handle dependencies


Constructor Injection
Container

👉 Handle dependencies - Recommendations for Android architecture  |  Android Developers

 

🤔 Test


ViewModel
Data Entity (Repository + DataSource)
FakeData
StateFlow

👉 Test - Recommendations for Android architecture  |  Android Developers

 

🤔 まとめ

しれっと、公式リファレンスも分かりやすく更新されていて驚きました。

👉 【Android】アーキテクチャーとして Google が推奨していること #Kotlin - Qiita