经过昨天一天的猛虎操作,终于工厂的需求进入尾声,总结下新学到的知识
如果想让两个apk 预置在launcher 需要修改launcher 的配置文件
配置如下 packages/apps/Launcher3/res/xml/default_workspace_4x4.xml
<favorites xmlns:launcher="http://schemas.android.com/apk/res-auto/com.android.launcher3">
<!-- Hotseat -->
<include launcher:workspace="@xml/dw_phone_hotseat" />
<favorite
launcher:packageName="" //包名
launcher:className="Activity" //带包名的activity
launcher:screen="0" //第几屏
launcher:x="0" //x位置
launcher:y="3" /> //y的位置
<favorite
launcher:packageName=""
launcher:className="Activity"
launcher:screen="0"
launcher:x="1"
launcher:y="3" />
</favorites>
这样点击就能进入app的activity 但是我还没有找到单编 launcher3的方法,所以直接增量编译
这两个工厂测试的app 可以通过dial secret code 进入 其实就是发送一个广播
AndroidManifest.xml 需要配置 广播接收者
<receiver
android:name=".BroadcastReceiver">
<intent-filter>
<action
android:name="android.provider.Telephony.SECRET_CODE" />
<data
android:scheme="android_secret_code"
android:host="64542552" />
</intent-filter>
</receiver>
上面配置的其实就是网址 格式,可以通过getIntent 获取相关信息
<activity
android:name=".LauncherActivity"
android:label="@string/cit_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Holo.Light">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.DEFAULT" />
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
启动的activity 一定要有 action :android.intent.category.LAUNCHER 这个决定点击应用进入的activity 界面
activity 启动模式有四种 standard 、single top、single instance、SingleTask
如果想集中管理activity 就要在application中 进行操作
public class TestApplication extends Application {
private List<Activity> mList = new ArrayList<>();
private static CitApplication instance;
public CitApplication(){}//注意这里的构造函数一定是public 不能private
public static synchronized TestApplication getInstance(){
if (null == instance){
instance = new TestApplication();
}
return instance;
}
public void addActivity(Activity activity){ //添加activity 实例
mList.add(activity);
}
public void removeActivity(){ //销毁activity 实例
for(Activity activity:mList){
if (activity != null){
activity.finish();
}
}
}
}
7