读书人

Shortcut 快捷方式 运用 - 2

发布时间: 2012-09-20 09:36:50 作者: rapoo

Shortcut 快捷方式 使用 - 2

Shortcut

?

[功能]

1. Shortcut 创建 有2种方法:

* "Shortcut 快捷方式 使用" 里面提到的 通过发送包含Shortcut 信息的 Broadcast

*? 本次讨论的 在桌面长按空白区域 在功能选项里面选择"Shortcut" 然后选择目标程序即可 如下图:

Shortcut 快捷方式 运用 - 2

?

?

[代码]

1. 创建一个class:public class Shortcut1Usage extends Activity

public class Shortcut1Usage extends Activity {        @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        Intent addShortcut;                if (getIntent().getAction()                .equals(Intent.ACTION_CREATE_SHORTCUT)) {                        addShortcut = new Intent();            addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,                     "119");                        Parcelable icon = Intent.ShortcutIconResource.fromContext(                    this,R.drawable.icon);            addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,                     icon);                        Intent callFirePolice =                 new Intent(Intent.ACTION_CALL,Uri.parse("tel://119"));            addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,                    callFirePolice);                        setResult(RESULT_OK,addShortcut);        } else {            setResult(RESULT_CANCELED);        }        finish();    }}

?

?

?

2. 修改 AndroidManifest.xml,增加 Shortcut1Usage 的 Activity

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

?

?

?

这样就可以了

?

程序中有需要 自己看哪种方法合适 就用哪一个 现附上代码 供需要的朋友看看

读书人网 >移动开发

热点推荐