什么作为启动器:启动器最喜欢的类名 [英] What to put as launcher:ClassName for launcher favorite

查看:23
本文介绍了什么作为启动器:启动器最喜欢的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的客户想要将我开发的应用程序放在他们最喜欢的启动器中,他们要求提供启动器的包名和类名.包名很简单,但 ClassName 不是,因为如果我查看清单,类名前面是这样的哈希:md599e473470f20dc18f556aff51bcfbcb1.LaunchScreen

那么,我必须为最喜欢的启动器使用什么类名,整个事情还是只使用类名 LaunchScreen?

谢谢

解决方案

(恭喜您进入他们的最爱,如果您提供 Play 链接;-)

如你所说,包名很简单,就是在manifest中定义为manifest元素的package属性:

启动器类名称是在Activity C# 类属性中标记的类,MainLauncher = true"

反过来,这会在清单中创建 activity 属性片段:

<意图过滤器><action android:name="android.intent.action.MAIN";/><category android:name="android.intent.category.LAUNCHER";/></意图过滤器></活动>

您的类名是完整的 android:name 属性,因为它不以句点开头.这是生成的唯一子类标识符,因此在我的示例中,这是完整的类名:

md5d2519388ea1895e3e3594794d2e0c4ce.MainActivity

虽然大多数人永远不会看到这个类 ID,但我强烈建议您覆盖这个生成类标识符并使​​用包含您的包名称的点类表示法.

通常,这是通过使用以句点开头的 android:name 提供名称来完成的(这是标准的 Android 类命名 101 ;-),但 Xamarin 目前没有strong> 支持以点开头的 Android 速记式类名,因此您需要使用完全限定的包名和类 ID 名称.

所以 Main Activity 属性变为:

[Activity(Label = "PlayScriptStarling2", Name = "com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay", MainLauncher = true, Icon = "@mipmap/icon")]

生成的清单变成:

<意图过滤器><action android:name="android.intent.action.MAIN";/><category android:name="android.intent.category.LAUNCHER";/></意图过滤器></活动>

我的启动器类名称变为:

com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay

Android 文档:

<块引用>

声明类名

许多元素对应于 Java 对象,包括应用程序本身的元素(元素)及其主要组件——活动()、服务()、广播接收器()和内容提供者().

如果您定义子类,就像您几乎总是为组件类(Activity、Service、BroadcastReceiver 和 ContentProvider)定义的那样,子类通过名称属性声明.该名称必须包括完整的包装名称.例如,一个 Service 子类可能声明如下:

<块引用>

但是,作为简写,如果字符串的第一个字符是句点,则该字符串将附加到应用程序的包名称(由元素的包属性指定).

下面的赋值和上面的一样:

<块引用>

当启动一个组件时,Android 会创建一个命名子类的实例.如果未指定子类,则会创建基类的实例.

参考:http://developer.android.com/guide/topics/manifest/manifest-intro.html

参考:https://developer.xamarin.com/guides/android/advanced_topics/working_with_androidmanifest.xml/#Intent_Actions_and_Features

My client wants to put the app I developed to be in their launcher favorite and they are asking for the package name and class name of the launcher. Package name is quite straightforward, but ClassName isn't since if I look into the manifest the class name is preceeded by a hash like this: md599e473470f20dc18f556aff51bcfbcb1.LaunchScreen

So what is the class name I have to use for launcher favorite, the whole thing or only the class name LaunchScreen?

Thanks

解决方案

(Congrats on getting into their favorites, should you provide a Play link ;-)

As you say, the package name is easy, it is the defined in the manifest as a package attribute of the manifest element:

<manifest .... package="com.sushihangover.playscriptstarling2" ...>

The launcher class name is the class that is tagged within the Activity C# class attribute, "MainLauncher = true"

In turn, this creates the activity attribute fragment within the manifest:

<activity android:icon="@mipmap/icon" android:label="PlayScriptStarling2" android:name="md5d2519388ea1895e3e3594794d2e0c4ce.MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

Your class name is the full android:name attribute since it does NOT begin with a period. This is a generated unique subclass identifier, thus in my example this is the full class name:

md5d2519388ea1895e3e3594794d2e0c4ce.MainActivity

While most people will never see this class ID, I highly recommend you override this generate class identifier and use the dot class notation that includes your package name.

Normally, this is done by providing a name using the android:name that BEGINS with a period (this is standard Android class naming 101 ;-) but Xamarin currently does not support Android shorthand-style class names beginning w/ a dot so you need to use the fully qualified package name with your class ID name.

So the Main Activity attribute becomes:

[Activity(Label = "PlayScriptStarling2", Name = "com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay", MainLauncher = true, Icon = "@mipmap/icon")]

And the generated manifest becomes:

<activity android:icon="@mipmap/icon" android:label="PlayScriptStarling2" android:name="com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

And my launcher class name becomes:

com.sushihangover.playscriptstarling2.MyBigBadGameEveryOneShouldPlay

Android Docs:

Declaring class names

Many elements correspond to Java objects, including elements for the application itself (the element) and its principal components — activities (), services (), broadcast receivers (), and content providers ().

If you define a subclass, as you almost always would for the component classes (Activity, Service, BroadcastReceiver, and ContentProvider), the subclass is declared through a name attribute. The name must include the full package designation. For example, an Service subclass might be declared as follows:

<manifest . . . >
    <application . . . >
        <service android:name="com.example.project.SecretService" . . . >
            . . .
        </service>
        . . .
    </application>
</manifest>

However, as a shorthand, if the first character of the string is a period, the string is appended to the application's package name (as specified by the element's package attribute).

The following assignment is the same as the one above:

<manifest package="com.example.project" . . . >
    <application . . . >
        <service android:name=".SecretService" . . . >
            . . .
        </service>
        . . .
    </application>
</manifest>

When starting a component, Android creates an instance of the named subclass. If a subclass isn't specified, it creates an instance of the base class.

Ref: http://developer.android.com/guide/topics/manifest/manifest-intro.html

Ref: https://developer.xamarin.com/guides/android/advanced_topics/working_with_androidmanifest.xml/#Intent_Actions_and_Features

这篇关于什么作为启动器:启动器最喜欢的类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆