android - 以编程方式在主屏幕上创建文件夹?

标签 android homescreen

我正在创建一个应用程序,我需要在其中在主屏幕上创建一个文件夹。并且用户可以将一些应用程序图标拖放到它上面。可能吗?如果是,那么谁能告诉我如何创建文件夹...

我试试这个

public class LiveFolderActivity extends Activity {

    public static final Uri CONTENT_URI = Uri.parse("content://shelves/live_folders/books");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live_folder);

          final Intent intent = getIntent();
            final String action = intent.getAction();

            if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
                setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI,"Books", R.drawable.ic_launcher));
            } else {
                setResult(RESULT_CANCELED);
            }

            finish();

    }

      private static Intent createLiveFolder(Context context, Uri uri, String name, int icon) {
            final Intent intent = new Intent();

            intent.setData(uri);
            intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME, name);
            intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON,
                    Intent.ShortcutIconResource.fromContext(context, icon));
            intent.putExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, LiveFolders.DISPLAY_MODE_LIST);

            return intent;
        }
}

list

    <activity
        android:name="com.example.testcreatefolder.LiveFolderActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.CREATE_LIVE_FOLDER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
   </activity>

最佳答案

Is it possible?

不是真的。

首先,并非所有主屏幕都提供文件夹。设备上有数十种甚至数百种主屏幕实现,更不用说通过 Play 商店和其他地方提供的第三方实现了。

其次,并非所有提供文件夹的主屏幕都提供任何类型的 API 以允许第三方应用程序创建此类文件夹。

关于android - 以编程方式在主屏幕上创建文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116399/

相关文章:

android - 如何取消处于运行状态的AsyncTask。

android - 在 Android 中打开启动应用程序之前如何避免加载主屏幕?

android - Android 主屏幕小部件中的 ImageButton

ios - 长时间不活动后,iPhone 会被发送到主屏幕吗?

java - 如何在 Android 中以编程方式启动主屏幕

android - 如何测试 native 应用程序安装横幅是否有效

javascript - 社交共享插件在 Ionic Cordova 中不起作用

php - 在 firebase 上为参数创建自定义数据以调用推送通知

java - 如何请求root权限

android - 无需拖放即可从主屏幕删除小部件