在HomeScreen中创建快捷方式

问题描述:

我有一个可以执行各种功能的应用程序。我想在我的android手机主屏幕中为最常用的功能创建快捷方式。在HomeScreen中创建快捷方式

任何人都可以请告诉我(带代码和代码实际工作)如何创建快捷方式?我看过很多代码,但我无法理解。请解释我。

我已经使用了下面的代码=>主要问题是在主屏幕上创建了快捷方式。但是,当我点击它像的一个吐司显示消息“未安装此应用在手机上”。而在日志中的错误消息是

1)WARN/ActivityManager(58):权限 否认:checkComponentPermission ()reqUid = 10046 2)WARN/ActivityManager(58):权限拒绝:启动Intent {act = android.intent.action.VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]} ProcessRecord {44f19b88 123:com.android.launcher/10025}(pid = 123,uid = 10025)需要null 3)错误/启动器(123):启动器没有启动权限Intent {act = android.intent.action .VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]}。确保为相应的活动创建主要意图过滤器,或使用此活动的导出属性。 tag = ShortcutInfo(title = Sukumar)intent = Intent {act = android.intent.action.VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]} 4)ERROR/Launcher(123):java .lang.SecurityException:Permission Denial:启动Intent {act = android.intent.action.VIEW flg = 0x10000000 cmp = aaa/.s bnds = [3,240] [77,319]} ProcessRecord {44f19b88 123:com.android.launcher/10025}(PID = 123,UID = 10025)需要空


`package a.a.a; 

import android.app.Activity; 
    import android.content.Intent; 
    import android.os.Bundle; 

public class ShortActivity extends Activity { 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Intent i=new Intent(this,s.class); 
    Intent j=new Intent(); 
    j.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i); 
    j.putExtra(Intent.EXTRA_SHORTCUT_NAME,"Sukumar"); 
    j.putExtra(Intent.EXTRA_SHORTCUT_ICON,R.drawable.icon); 
    j.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
    this.sendBroadcast(j); 


} 


}` 

要创建Android主屏幕上的应用程序快捷方式,我们只需要火一个简单的意图与行动com.android.launcher.action.INSTALL_SHORTCUT。快捷方式的名称和图标,我们可以把Intent的exrta参数。
检查下面的方法:

Intent intent = new Intent(); 
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentActivity); 
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, textShortcut); 
Parcelable iconResource = (Parcelable) bitmap; 
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconResource); 
intent.putExtra("duplicate", duplicateNeed); // (duplicateNeed=false) 
// will not allow the 
// duplicate same name 
// shortcuts. 
intent.setAction(INSTALL_SHORTCUT_ACTION); 
getApplicationContext().sendBroadcast(intent);