ftl->freemarker process -> java
。 Android Studio自定义模板 写页面竟然可以如此轻松 - Hongyang
总结:
package ${packageName};
import android.app.admin.DeviceAdminReceiver;
public class ${className} extends DeviceAdminReceiver {
public ${className}() {
}
//代码
}
android:exported="${isExported?string}"
android:enabled="${isEnabled?string}"
android:label="组件名字"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
android:name="android.app.device_admin"
android:resource="@xml/device_admin_receiver" />
${relativePackage}<#else>${packageName}#if>" />
format="5"
revision="3"
name="DeviceAdminReceiver"
description="Creates a new DeviceAdminReceiver component and adds it to your Android manifest.">
id="className"
name="Class Name"
type="string"
constraints="class|unique|nonempty"
default="MyDeviceAdminReceiver"
help="The name of the DeviceAdminReceiver component class to create"/>
id="isExported"
name="Exported"
type="boolean"
default="true"
help="Whether or not the broadcast receiver can receive messages from sources outside its application" />
id="isEnabled"
name="Enabled"
type="boolean"
default="true"
help="Whether or not the broadcast receiver can be instantiated by the system" />
id="packageName"
name="Package name"
type="string"
constraints="package"
default="com.mycompany.myapp"/>
to="${escapeXmlAttribute(manifestOut)}/AndroidManifest.xml" />
to="${escapeXmlAttribute(resOut)}/xml/device_admin_receiver.xml" />
to="${escapeXmlAttribute(srcOut)}/${className}.java" />
OK,仔细检查下代码,不然使用模板出错了很麻烦的,我的就需要重启android-studio。现在在项目里创建个DeviceAdminReceiver: