无法从命令行在 Android 13 中启动活动。

huangapple go评论95阅读模式
英文:

Can not start activity from command line in Android 13

问题

无法通过以下命令从终端打开活动:

adb shell am start -n com.mypackage/com.mypackage.MyActivity -d --es myvariable1 myvalue1 --es myvariable2 myvalue2 -d

在Android 13上返回:

> Starting: Intent { act=android.intent.action.MAIN
> cat=[android.intent.category.LAUNCHER] dat= pkg=username
> cmp=com.mypackage/.MyActivity } Error type 3 Error:
> Activity class {com.mypackage/com.mypackage.MyActivity} does not
> exist.

在Android 12及更低版本上有效。

在链接https://developer.android.com/about/versions/13/behavior-changes-all#intents中找不到有关此问题的任何信息。

当我按照链接中提到的Intent过滤器匹配时

adb shell am start -a android.intent.action.VIEW -d myscheme://myhost/myprefix -n com.mypackage/com.mypackage.MyActivity

可以打开,但我需要在没有myscheme://myhost/myprefix和View intent的情况下打开活动。

你有什么想法?

英文:

I cannot open activity from the terminal via the command below,

adb shell am start -n com.mypackage/com.mypackage.MyActivity -d --es myvariable1 myvalue1 --es myvariable2 myvalue2 -d

On Android 13 it returns:

> Starting: Intent { act=android.intent.action.MAIN
> cat=[android.intent.category.LAUNCHER] dat= pkg=username
> cmp=com.mypackage/.MyActivity } Error type 3 Error:
> Activity class {com.mypackage/com.mypackage.MyActivity} does not
> exist.

It works on Android 12 and lower.

Couldn't find any information about that except https://developer.android.com/about/versions/13/behavior-changes-all#intents

When I match the Intent filter as mentioned in the link

adb shell am start -a android.intent.action.VIEW -d myscheme://myhost/myprefix -n com.mypackage/com.mypackage.MyActivity

opens but I need to open activty with my parameters without myscheme://myhost/myprefix and View intent

Do you have any idea?

答案1

得分: 1

你可能需要添加一个单独的意图过滤器来启动:
https://automationchronicles.com/error-when-opening-chrome-on-android-13-via-adb/

例如:

<activity
        android:name=".mypackage.MyActivity"
        android:exported="true"
        android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
      </intent-filter>

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="myhost"
            android:scheme="myscheme" />

      </intent-filter>
英文:

You probably need to add a separate intent filter to launch:
https://automationchronicles.com/error-when-opening-chrome-on-android-13-via-adb/

e.g.

<activity
        android:name=".mypackage.MyActivity"
        android:exported="true"
        android:windowSoftInputMode="adjustResize">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
      </intent-filter>

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="myhost"
            android:scheme="myscheme" />

      </intent-filter>

</details>



huangapple
  • 本文由 发表于 2023年3月9日 20:52:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定