Shortcut
[功能]
1. Shortcut 創建 有2種方法:
* "Shortcut 快捷方式 使用" 裏面提到的 通過發送包含Shortcut 信息的 Broadcast
* 本次討論的 在桌面長按空白區域 在功能選項裏面選擇"Shortcut" 然後選擇目標程序即可 如下圖:
[代碼]
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();
- }
- }
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>
<activity android:name=".Shortcut1Usage">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
</intent-filter>
</activity>
這樣就可以了
程序中有需要 自己看哪種方法合適 就用哪一個 現附上代碼 供需要的朋友看看