使用 adb 启动 activity
Start activity with adb
我有一个最简单的测试应用程序,它是用 xamarin 开发的,部署到一个 USB 连接的机器人上。为了有朝一日的工作意图 url,我正在尝试用 adb shell am 调用我的主 activity。这是我的 MainActivity 的前几行...
namespace DematAEAT_Android
{
[Activity(Label = "DematAEAT_Android", MainLauncher = true, Icon = "@drawable/icon")]
[IntentFilter(new[] { "AcquireSignedImage" },
Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault })]
public class MainActivity : Activity
{
int count = 1;
这里有两个 shell 命令。首先,包管理器成功理解包名并报告 apk 路径。第二,activity 管理器无法解析 class MainActivity。无论有没有名称空间,它都会失败。
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell pm path "fr.company.DematAEAT_Android"
package:/data/app/fr.company.DematAEAT_Android-1/base.apk
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell am start -n "fr.company.DematAEAT_Android/.DematAEAT_Android.MainActivity"
Starting: Intent { cmp=fr.company.DematAEAT_Android/.DematAEAT_Android.MainActivity }
Error type 3
Error: Activity class {fr.company.DematAEAT_Android/fr.company.DematAEAT_Android.DematAEAT_Android.MainActivity} does not exist.
编辑...
然而,我可以愉快地使用 monkey 启动。以下命令工作正常。这好像我在 adb shell am call 中命名我的 activity class 的方式有问题,但我无法发现它。
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb shell monkey -p fr.company.DematAEAT_Android 1
Events injected: 1
## Network stats: elapsed time=170ms (0ms mobile, 0ms wifi, 170ms not connected)
谁能告诉我怎么称呼这个activity?
谁知道呢?我需要在我的 manifest.xml 中四处寻找,发现 xamarin 在我的 activity 名称前附加了一个哈希作为名称空间。所以有效的 adb 调用看起来像这样...
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell am start -n fr.company.DematAEAT_Android/md5abda05033ab0415fc7a776c5d9734c74.BrowsableActivity
Starting: Intent { cmp=fr.company.DematAEAT_Android/md5abda05033ab0415fc7a776c5d9734c74.BrowsableActivity }
故事还在继续。对于任何试图通过 adb shell am 启动 xamarin activity,或试图以意图或意图 url 启动 xamarin activity 的人来说,这可能是一个问题.
这是 Xamarin Android 5.0
中的重大更改
Android Callable Wrapper Naming
The name mangling scheme for Android Callable Wrappers is changing. Previously, the Android Callable Wrapper package name was constructed by lowercasing the namespace name, which would result in packaging failures if more than one assembly contained a type with the same fully-qualified name.
With the 5.0 release, the default package names for Android Callable Wrappers will be based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error.
您可以通过在 [Activity]
属性中指定名称来覆盖您的 Activity:
[Activity(Name = "fr.company.demeat_android.MainActivity")]
public class MainActivity : Activity {
/* ... */
}
我有一个最简单的测试应用程序,它是用 xamarin 开发的,部署到一个 USB 连接的机器人上。为了有朝一日的工作意图 url,我正在尝试用 adb shell am 调用我的主 activity。这是我的 MainActivity 的前几行...
namespace DematAEAT_Android
{
[Activity(Label = "DematAEAT_Android", MainLauncher = true, Icon = "@drawable/icon")]
[IntentFilter(new[] { "AcquireSignedImage" },
Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault })]
public class MainActivity : Activity
{
int count = 1;
这里有两个 shell 命令。首先,包管理器成功理解包名并报告 apk 路径。第二,activity 管理器无法解析 class MainActivity。无论有没有名称空间,它都会失败。
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell pm path "fr.company.DematAEAT_Android"
package:/data/app/fr.company.DematAEAT_Android-1/base.apk
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell am start -n "fr.company.DematAEAT_Android/.DematAEAT_Android.MainActivity"
Starting: Intent { cmp=fr.company.DematAEAT_Android/.DematAEAT_Android.MainActivity }
Error type 3
Error: Activity class {fr.company.DematAEAT_Android/fr.company.DematAEAT_Android.DematAEAT_Android.MainActivity} does not exist.
编辑... 然而,我可以愉快地使用 monkey 启动。以下命令工作正常。这好像我在 adb shell am call 中命名我的 activity class 的方式有问题,但我无法发现它。
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb shell monkey -p fr.company.DematAEAT_Android 1
Events injected: 1
## Network stats: elapsed time=170ms (0ms mobile, 0ms wifi, 170ms not connected)
谁能告诉我怎么称呼这个activity?
谁知道呢?我需要在我的 manifest.xml 中四处寻找,发现 xamarin 在我的 activity 名称前附加了一个哈希作为名称空间。所以有效的 adb 调用看起来像这样...
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb -d shell am start -n fr.company.DematAEAT_Android/md5abda05033ab0415fc7a776c5d9734c74.BrowsableActivity
Starting: Intent { cmp=fr.company.DematAEAT_Android/md5abda05033ab0415fc7a776c5d9734c74.BrowsableActivity }
故事还在继续
这是 Xamarin Android 5.0
中的重大更改Android Callable Wrapper Naming
The name mangling scheme for Android Callable Wrappers is changing. Previously, the Android Callable Wrapper package name was constructed by lowercasing the namespace name, which would result in packaging failures if more than one assembly contained a type with the same fully-qualified name.
With the 5.0 release, the default package names for Android Callable Wrappers will be based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error.
您可以通过在 [Activity]
属性中指定名称来覆盖您的 Activity:
[Activity(Name = "fr.company.demeat_android.MainActivity")]
public class MainActivity : Activity {
/* ... */
}