Creating LiveFolder in Android

In Android, a live folder is simply a real-time view of a ContentProvider. LiveFolder allow displaying of data on home screen without launching the application.



public class CreateLiveFolder extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = Browser.BOOKMARKS_URI;
final Intent intent = getIntent();
final String action = intent.getAction();
if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
setResult(RESULT_OK, createLiveFolder(this, uri,
"Books", R.drawable.icon));
} 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;
}
}



The manifest file will look like this,



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.createlivefolder" android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".CreateLiveFolder"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.CREATE_LIVE_FOLDER"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>



In this case, I don't have any bookmark in my browser, so an empty content provider is shown.


Steps to launch LiveFolder :


After launching the application
-> Long press on the empty space of the home screen
-> Select "Folder" from the dialog that pop-up



-> Select "CreateLiveFolder".





This will create the live folder in home screen in the name of "SampleLiveFolder".



The screenshots are,



When we click on the icon, our live folder called "SampleLiveFolder" will open. As my "bookmarks" in browser is empty, it will show an empty dialog box

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android

Difference between SurfaceView and View in Android