我有一个可以执行各种功能的应用程序。我想为我的android手机主屏幕上最常用的功能创建一个快捷方式。
谁能告诉我(使用代码和代码实际如何工作)如何创建快捷方式?我见过很多行代码,但我无法理解。请解释一下。
我使用了以下code=>Main问题,即在主屏幕上创建快捷方式。但是,当我单击一个像这样的Toast显示消息时,日志中的“应用程序没有安装在您的手机上”.And中的错误消息是
1) WARN/ActivityManager(58):权限被拒绝: checkComponentPermission() reqUid=10046 2) WARN/ActivityManager(58):权限拒绝:从ProcessRecord{44f19b88 123:com.android.launcher/10025} (pid=123,uid=10025)发出的启动意图{ act=android.intent.action.VIEW flg=0x10000000 cmp=A.A/.s bnds=3,240 } (pid=123,uid=10025)需要空3)错误/启动器(123):Launcher没有启动意图{ act=android.intent.action.VIEW flg=0x10000000 cmp=a.a.a/.s bnds=3,240 }的权限。确保为相应的活动创建一个主意图过滤器,或者为该活动使用导出的属性。tag=ShortcutInfo(title=Sukumar) intent=Intent { act=android.intent.action.VIEW flg=0x10000000 cmp=a.a.a/.s bnds=3,240 } 4)错误/启动器(123):java.lang.SecurityException:权限拒绝:启动意图{ act=android.intent.action.VIEW flg=0x10000000 cmp=A.A/.s bnds=3,240 } from 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);
}
}`
发布于 2012-03-05 09:16:21
要在Android屏幕上创建应用程序快捷方式,我们只需要使用动作com.android.launcher.action.INSTALL_SHORTCUT
激发一个简单的意图。名称和图标的快捷方式,我们可以把与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);
https://stackoverflow.com/questions/9564040
复制相似问题