android 创建快捷方式

 

shortactivity类

@Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        if (getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT))
        {
            Intent _int=new Intent();
            _int.putExtra(Intent.EXTRA_SHORTCUT_NAME, "myshortcut");
            _int.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this,R.drawable.ic_launcher));
            _int.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,MyshortcutActivity.class));
            setResult(RESULT_OK, _int);
            finish();
        }
    }

 

androidmainfest.xml  文件添加activity

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

 

 

posted on 2012-04-15 22:06  larryle  阅读(117)  评论(0)    收藏  举报