开机默认此app作为launcher首次加载 ,就是设置这个apk为开机向导,并没有设置这个成默认launcher,若此应用是launcher应用那么按返回之后会提示让你选择哪一laucher前提是此应用内置并没有作为launcher应用,就可以用下面的方法。
开机自启,开机自动启动某个指定应用!!!!
方法一:(推荐)但是这个比较慢,开机已经进入系统了但是还有过好一会才会收到广播,它需要完成系统更新之后才接受到
vendor/mediatek/proprietary/packages/apps/SystemUI/ src/com/android/systemui/SystemUIApplication.java
在接受到开机广播的地方,执行跳转,这里是广播接受跳转,可以直接显式启动
IntentFilter bootCompletedFilter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
bootCompletedFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
registerReceiver(new BroadcastReceiver() {
下面增加执行操作
一:可以直接显式启动
Intent cIntent=new Intent();
cIntent.setClassName("lte.trunk.tapp","lte.trunk.tapp.settings.AASSettingActivity");
cIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
android.util.Log.d("yantao", "cIntent="+cIntent);
context.startActivity(cIntent);
二:用PackageManager().getLaunchIntentForPackage方法,可以不用传类名,适合不晓得具体那个activity先出来,只需要有一个包名就可以
Intent cIntent=new Intent();
cIntent = context.getPackageManager().getLaunchIntentForPackage("lte.trunk.tapp");
android.util.Log.d("yantao", "cIntent="+cIntent);
if(cIntent != null){
cIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(cIntent);
} else {
android.util.Log.d("yantao", "getLaunchIntentForPackage failed");
}
O版本!o以上不起作用
frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
在Home Activity 在上面的ActivityManagerService开启之后,会调用finishBooting()函数
在这个finishBooting中最后加入如下,这样可以开机指定应用直接进入这个应用,哪怕它是个launcher应用。就这一次首次加载,前面的判断可以不加
if (Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 1) {
+ Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
+ Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
+ }
+ Intent cIntent=new Intent();
+ cIntent = mContext.getPackageManager().getLaunchIntentForPackage("com.mcptt");
+ if(cIntent != null){
+ mContext.startActivity(cIntent);
+ } else {
+ android.util.Log.i("yantao", "getLaunchIntentForPackage failed" );+ }
+ //*/
上面就是设置这个apk为开机向导,ActivityManagerService中,由于开机向导只在系统第一次启动之前启动,所以开机向导关闭的时候需要将自己设置为不在启动。源码里finishBooting里面有句mAnrManager.writeEvent(AnrManager.EVENT_BOOT_COMPLETED);就是设置不再启动了。然后同时需要告诉系统开机向导已经完成了,需要写入如下属性到系统中(需要系统权限)
Settings.Global.putInt(getActivity().getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 1);
Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.USER_SETUP_COMPLETE, 1);
然后在frameworks/base/services/core/java/com/android/server/policy/PhoneWindowManager.java里面修改别人写的按下电源键后锁死在launcher3了,判断如下,在case KeyEvent.KEYCODE_POWER: {这个case下 ,
else{
- if(getCurrentActivityName(mContext).equals("com.android.launcher3.Launcher")) {
- if (down) {
- interceptPowerKeyDown(event, interactive);
- } else {
- interceptPowerKeyUp(event, interactive, canceled);
- }
- }else{
- if (down) {
- Intent intent=new Intent();
- intent.setClassName("com.android.launcher3","com.android.launcher3.Launcher");
- mContext.startActivity(intent);
- }
- }
他这个意思是如果当前在launcher3,那么这个电源键正常使用,如果不在,那么就强制开启launcher3
我们只需要把这个回退到源码本来就可。就是电源键正常使用
if (down) {
interceptPowerKeyDown(event, interactive);
} else {
interceptPowerKeyUp(event, interactive, canceled);
}
}
break;
}
上面是针对本身不是launcher的应用,如果本身就是launcher应用,那么就把它设置成默认launcher就可以
在frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
在这个方法里startHomeActivityLocked,源码的最后加入
加入这个更改默认launcher的方法
final PackageManager mPm = mContext.getPackageManager();
Intent homeIntent=new Intent();
homeIntent.addCategory(Intent.CATEGORY_HOME);
homeIntent.setAction(Intent.ACTION_MAIN);
homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
ResolveInfo info = mPm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
ComponentName DefaultLauncher=new ComponentName("afrizona.maxalerts.rotas","afrizona.maxalerts.rotas.MainActivity");
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
ComponentName[]mHomeComponentSet = new ComponentName[homeActivities.size()];
for (int i = 0; i < homeActivities.size(); i++) {
final ResolveInfo candidate = homeActivities.get(i);
Log.d(TAG,"homeActivitie: candidate = "+candidate);
final ActivityInfo activityInfo= candidate.activityInfo;
ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);
mHomeComponentSet[i] = activityName;
}
IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
mHomeFilter.addCategory(Intent.CATEGORY_HOME);
mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
List<ComponentName>Activities=new ArrayList();
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher);
完了别忘了把PhoneWindowManager里面别人强制电源键回launcher3的删了,如果有的话
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我有一些Ruby代码,如下所示:Something.createdo|x|x.foo=barend我想编写一个测试,它使用double代替block参数x,这样我就可以调用:x_double.should_receive(:foo).with("whatever").这可能吗? 最佳答案 specify'something'dox=doublex.should_receive(:foo=).with("whatever")Something.should_receive(:create).and_yield(x)#callthere
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or