Android Create Shortcut for some special mobile phone.
来源:互联网 发布:俊知集团 分红 编辑:程序博客网 时间:2024/05/07 06:45
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">在手机中运行App时,很奇怪的问题,有的手机运行App后桌面有快捷图标,有的手机没有快捷图标,</span>
经过在网上找了的资料,自己实践了一下,测试也没有问题,现在把步骤与代码贴出来给大家盾一下。
刚接触Android开发,好多代码都是Copy过来的,每行代码只能通过字面意思理解。
AndroidManifest.xml文件中添加以下权限设置,还有设置activity的intent-filter节点.
这个应该是必须要添加的,后面两个我也带上怕出什么问题。
"com.android.launcher.permission.INSTALL_SHORTCUT"
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/> <uses-permission android:name="android.permission.BROADCAST_PACKAGE_REPLACED" /> <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18" /> <application android:allowBackup="true" android:icon="@drawable/appicon" android:label="@string/app_name" android:theme="@style/AppBaseTheme" > <activity android:name=".SplashActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity" android:label="@string/app_name" android:logo="@drawable/appicon"> </activity>在我的启动SplashActivity中实现以下代码:
/**For shortcut**/private Context mContext=SplashActivity.this;private SharedPreferences appPreferences;private boolean isAppInstalled=false;private final long SPLASH_LENGTH=1000;private Handler handler=new Handler();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_NO_TITLE);/*//hide android status bar.this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//hide title bar-title bar of current activitythis.requestWindowFeature(Window.FEATURE_NO_TITLE);*/setContentView(R.layout.activity_splash);/******For Shortcut*******/appPreferences=PreferenceManager.getDefaultSharedPreferences(mContext);isAppInstalled=appPreferences.getBoolean("isAppInstalled", false);if(isAppInstalled==false){addShortcutIcon();}SharedPreferences.Editor editor=appPreferences.edit();editor.putBoolean("isAppInstalled", true);editor.commit();/*************/new Thread(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubtry {Thread.sleep(SPLASH_LENGTH);} catch (Exception e) {// TODO: handle exception}runOnUiThread(new Runnable() {@Overridepublic void run() {startActivity(new Intent(SplashActivity.this,MainActivity.class));finish();}});}}).start();/*handler.postDelayed(new Runnable() {@Overridepublic void run() {// TODO Auto-generated method stubIntent intent=new Intent(SplashActivity.this,MainActivity.class);startActivity(intent);finish();}}, SPLASH_LENGTH);*/}
添加桌面快捷图标方法:
private void addShortcutIcon() {Intent shortcutIntent=new Intent(getApplicationContext(),SplashActivity.class);shortcutIntent.setAction(Intent.ACTION_MAIN);Intent addIntent=new Intent();addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(),R.drawable.appicon));addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");//finally broadcast the new intentgetApplicationContext().sendBroadcast(addIntent);}
0 0
- Android Create Shortcut for some special mobile phone.
- Android Create Shortcut
- Shortcut for some CSS properties: padding, background
- create shortcut in gnome3 and some settings-- lockscreen & arp_attack
- linux for qq (create a shortcut )
- Create Shortcut for windows 10 Universal Apps
- Create a shortcut for a program at user Desktop
- Some method for Android
- SOME SPECIAL PERMISSIONS
- Android-Shortcut
- shortcut key of Android Studio for Mac OS X
- shortcut keys for linux
- Android - Listener for incoming phone
- Create Android Toolchain for ARMv4T
- some special cases of "extern" in C
- 使用jQuery Mobile和Phone Gap开发Android应用程序
- 使用jQuery Mobile和Phone Gap开发Android应用程序
- 使用jQuery Mobile和Phone Gap开发Android应用程序
- windows cmd 中无法使用ping、ipconfig等命令
- sizeof(struct)的结果分析及其原因
- request与response的作用
- Kettle4 Repository 操作示例 (登陆资源库,获取模型,运行)
- shell case的用法及shell如何运行
- Android Create Shortcut for some special mobile phone.
- elasticsearch MultiSearch实例
- Springmvc构造RESTful详细讲解
- 第一周 课后实践:阅读程序(2)
- 枚举类型—平面点的对称点
- 1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100的值
- Linux下烧写工具DNW和USB驱动安装
- android docs本地帮助文档打开特别慢的解决方法
- Linux shell的标准输入、输出和错误