Shortcut 快捷方式 使用 - 2(转)

Shortcut

 

[功能]

1. Shortcut 创建 有2种方法:

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

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

 

 

[代码]

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

Java代码
  1. public   class  Shortcut1Usage  extends  Activity {  
  2.       
  3.     @Override   
  4.     public   void  onCreate(Bundle savedInstanceState) {  
  5.         super .onCreate(savedInstanceState);  
  6.         Intent addShortcut;  
  7.           
  8.         if  (getIntent().getAction()  
  9.                 .equals(Intent.ACTION_CREATE_SHORTCUT)) {  
  10.               
  11.             addShortcut = new  Intent();  
  12.             addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,   
  13.                     "119" );  
  14.               
  15.             Parcelable icon = Intent.ShortcutIconResource.fromContext(  
  16.                     this ,R.drawable.icon);  
  17.             addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,   
  18.                     icon);  
  19.               
  20.             Intent callFirePolice =   
  21.                 new  Intent(Intent.ACTION_CALL,Uri.parse( "tel://119" ));  
  22.             addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,  
  23.                     callFirePolice);  
  24.               
  25.             setResult(RESULT_OK,addShortcut);  
  26.         } else  {  
  27.             setResult(RESULT_CANCELED);  
  28.         }  
  29.         finish();  
  30.     }  
  31. }  
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

Java代码
  1. <activity android:name= ".Shortcut1Usage" >  
  2.             <intent-filter>  
  3.                 <action android:name="android.intent.action.CREATE_SHORTCUT"  />  
  4.             </intent-filter>  
  5.         </activity>  
<activity android:name=".Shortcut1Usage">
            <intent-filter>
                <action android:name="android.intent.action.CREATE_SHORTCUT" />
            </intent-filter>
        </activity>

 

 

 

这样就可以了

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值