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

问题描述 投票:5回答:2

我正在创建一个应用程序,我要求在主屏幕上创建一个文件夹。用户可以删除一些应用程序图标。可能吗?如果是,那么任何人都可以告诉我如何创建文件夹...

我试试这个

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;
        }
}

表现

    <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>
android homescreen
2个回答
6
投票

可能吗?

并不是的。

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

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


0
投票

您可以在主屏幕上为应用程序快捷方式创建一个实时文件夹,这里有一些有用的链接可以帮助您:

1.android-developers

2.AudioBooksLiveFolder

3.betterandroid

或者您可以使用Intent转到主屏幕,然后您可以创建一个文件夹。您可以使用以下代码进入主屏幕:

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
© www.soinside.com 2019 - 2024. All rights reserved.