android 自定义启动器快捷方式,在Android中的自定义启动器中创建应用程序...

我正在尝试开发一个自定义启动器,它将包含我安装的应用程序的快捷方式(甚至是apk文件).我可以在应用程序外部创建一个快捷方式,我需要做的是在我的启动器活动中创建它.我怎样才能做到这一点?

AdminActivity.java(此活动包含一个能够从设备创建已安装应用程序快捷方式的方法)

private boolean installUninstall_ShortCut(Context context, String appName, boolean isTrue) {

boolean flag =false ;

int app_id=-1;

PackageManager pm = context.getPackageManager();

Intent i = new Intent(Intent.ACTION_MAIN);

i.addCategory(Intent.CATEGORY_LAUNCHER);

List res = pm.queryIntentActivities( i,0);

for(int k=0; k

if(res.get(k).activityInfo.loadLabel(pm).toString().equals(appName)){

flag = true;

app_id = k;

break;

}

}

if(flag) {

ActivityInfo ai = res.get(app_id).activityInfo;

Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);

shortcutIntent.setClassName(ai.packageName, ai.name);

shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Intent intent = new Intent();

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

intent.putExtra("duplicate", false);

if(isTrue) {

intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher));

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

} else {

intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");

}

context.sendBroadcast(intent);

} else

System.out.println("applicaton not found");

return true;

}

activity_launcher.xml(这是Launcher Activity的布局,快捷方式将在其中.我真的不知道如何在此活动中创建创建的快捷方式)

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/plain_without_logo"

tools:context=".S_2nd_MainActivity" >

android:id="@+id/grid_app"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:columnWidth="80dp"

android:gravity="center"

android:horizontalSpacing="15dp"

android:numColumns="auto_fit"

android:padding="10dp"

android:stretchMode="columnWidth"

android:verticalSpacing="15dp" />

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值