android实现快捷方式

来源:互联网 发布:爱淘宝每日3次抽红包 编辑:程序博客网 时间:2024/04/29 22:54



使用android手机的都知道,当长按着桌面的时候,会弹出“添加到主屏幕”的选项,在“快捷方式”里面有很多的应用,其中有的可以添加快捷方式,有的就不可以。


其实最关键的方法就是:


在AndroidMainfest,xml文件中的主ACTIVITY添加:

    <intent-filter >
                    <action android:name="android.intent.action.CREATE_SHORTCUT"/>
      </intent-filter>


在添加权限:

 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 



集成下来就是如下所示:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ljz.shortcut.demo1"
    android:versionCode="1"
    android:versionName="1.0" >


    <uses-sdk android:minSdkVersion="8" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> 
    


    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".ShortCutDemo1Activity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
                <intent-filter >
                    <action android:name="android.intent.action.CREATE_SHORTCUT"/>
                </intent-filter>
                
        </activity>
    </application>


</manifest>



原创粉丝点击