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.