Я пытаюсь разработать пользовательскую панель запуска, которая будет содержать ярлык моего установленного приложения (или даже файлов 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<ResolveInfo> res = pm.queryIntentActivities( i,0);
for(int k=0; k<res.size(); 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, в котором будет выполняться ярлык. Я действительно не знаю, как привести созданный ярлык в эту активность)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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" >
<GridView
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" />