2014-03-01 28 views
5

我正在創建一個應用程序,我要求在主屏幕上創建一個文件夾。用戶可以放下一些應用程序圖標。可能嗎?如果是,那麼任何一個可以請告訴我如何創建文件夾...編程在主屏幕上創建文件夾?

我嘗試這個

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> 

回答

6

這可能嗎?

不是。

首先,並非所有主屏幕都提供文件夾。有幾十個,也許有幾百個主屏幕實現在設備上發佈,更不用說通過Play商店和其他地方提供的第三方實現了。其次,並非所有提供文件夾的主屏幕都提供任何類型的API,以允許第三方應用程序創建此類文件夾。

+0

http://stackoverflow.com/questions/36007154/create-folder-on-home-screen-where-i-can-put-some-icons-在網格中請看到這個問題一次 –

0

您可以創建在主屏幕上的應用程序快捷方式在這裏的活動文件夾是一些有用的鏈接,幫助您:

1.android-developers

2.AudioBooksLiveFolder

3.betterandroid

,或者你可以去首頁屏幕使用意圖然後您可以創建一個文件夾。你可以去到主屏幕使用下面的代碼:

Intent startMain = new Intent(Intent.ACTION_MAIN); 
startMain.addCategory(Intent.CATEGORY_HOME); 
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
startActivity(startMain); 
+0

我試試這個,但沒有工作... –

+1

我想在主屏幕上以編程方式創建文件夾... –

相關問題