Android创建和删除桌面快捷方式
/**
* 为程序创建桌面快捷方式
*/
private
void
addShortcut(){
Intent
shortcut = new
Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcut.putExtra("duplicate",
false);
//不允许重复创建
//指定当前的Activity为快捷方式启动的对象:
如
//com.everest.video.VideoPlayer
//注意:
ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
ComponentName
comp = new
ComponentName(this.getPackageName(),
"."+this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new
Intent(Intent.ACTION_MAIN).setComponent(comp));
//快捷方式的图标
ShortcutIconResource
iconRes = Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
iconRes);
sendBroadcast(shortcut);
}
/**
*
删除程序的快捷方式
*/
private
void
delShortcut(){
Intent
shortcut = new
Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
//快捷方式的名称
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
//指定当前的Activity为快捷方式启动的对象:
如
//com.everest.video.VideoPlayer
//注意:
ComponentName的第二个参数必须是完整的类名(包名+类名),否则无法删除快捷方式
String
appClass = this.getPackageName()
+ "."
+this.getLocalClassName();
ComponentName
comp = new
ComponentName(this.getPackageName(),
appClass);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
new
Intent(Intent.ACTION_MAIN).setComponent(comp));
sendBroadcast(shortcut);
}
全屏显示
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
横竖屏显示
private
void
changedScreen(){
int
request = this.getRequestedOrientation();
if(request
== -1){
Toast.makeText(TaskRunActivity.this,
"None
1",
Toast.LENGTH_SHORT).show();
}else{
if(getRequestedOrientation()
== ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}else
if(getRequestedOrientation()
== ActivityInfo.SCREEN_ORIENTATION_PORTRAIT){
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
}
获取手机分辩率
DisplayMetrics
dm = new
DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
int
width =
dm.widthPixels;
int
height = dm.heightPixels;
分享到:
相关推荐
mars老师的Android代码全集,里面包括mars前三季的Android源代码!
80多个经典android 案例,包括一个eclipse搭建android环境。经典有用、适合初学、巩固和回忆。
Android开发源代码合集 Android开发源代码合集 Android开发源代码合集Android开发源代码合集
Android小游戏安卓游戏源码45款合集: 21点游戏源码.rar Angle v1.0.ZIP Barrage_OpenGLES.rar Billiard_2D.zip catcake-0.9.5-android.tar.gz Chess.rar Crackedcarrot.rar CrazyFootBall.zip EggGame.rar Elose-wr....
android 开发源码合集
Android3D游戏源代码合集,都是写好的程序哦! TAG:Android 3D 游戏 应用开发 源代码 Cindigo整理发布,谨此致谢!
mars 老师 android 源代码 mars 老师 android 源代码 mars 老师 android 源代码
android游戏开发实例几十个源代码,注释非常详细,无论你是android开发高手还是刚刚接触android开发的菜鸟,对你在android开发方面的提高绝对有很大的帮助!
Android经典源码全集常用android小程序源码80个合集,可以做为你学习设计参考,每一个都是一个完整的小项目,里面都有源码,初学者学着用! 具体如下: GestureRecogniseSample GetPostSample ...
2)Android游戏捕鱼达人代码 是一个比较好的学习android编程的参考例子,谢了。 使用AndEngine引擎开发的,可以学习下。 3)android 经典代码例子 4)7个比较具有代表性的Android应用程序源代码!!! 有天气,有播放器...
android 经典代码例子android开发( 安卓)经典软件源代码合集(27个): animation audio broadcast Bundle db download draw expandableList http iconFile imageView Intent listView menu mouseovertest ...
android上百列开源源码,总共分为3个合集,这个是第三个合集,来源于网络,近半年的搜集,谢谢大家的支持。。
mars android 第一季 第26集 代码
绝对经典!配合Android 游戏开发实战宝典课件PPT,由于之前上传文件大小限制15M,所以合集除了胜利大逃亡外推箱子、疯狂足球、太空保卫战、象棋、小球快跑、回到战国源代码 现免费补充胜利大逃亡源代码
Android安卓应用项目源码Android开发学习经典源代码合集(88个): android 安卓经典源代码(25个) 一个支持暂停下载断点续传的源码 一个登陆和注册界面 一个短信应用源码 一个简单注册界面 一个简单登录的DEMO 一款...
Android应用源码-Android安卓设计实例源代码15个合集,可供学习及设计参考。
Android 恶意代码:SpringerBriefs in Computer Science 第二章 pdf
Android经典源码全集[简单易懂],共88套代码,完整有效,已全部测试! Android经典源码列表: GestureRecogniseSample GetPostSample GridAndImageSwitcherSample HandlerSample ImageButton Intent_...
Android手机程序代码合集-有重力感应-地图-ucweb界面媒体播放等程序