shortcut+livefolder
Livefolder 组件 因为不是android刚开始支持的 导致先期开发的ContentProvider 并没有预先给予支持 而Livefolder对列名有一定限制 导致Livefolder显得有点鸡肋
所以 今天打算以shortcut形式 来使用livefolder
整个代码也比较简单 贴代码 如果有不懂得地方 诸位跟帖 再细说
源代码:
public class LivefolderTest extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
CursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,c,
new String[] {People.NAME,People.NUMBER},
new int[] {android.R.id.text1,android.R.id.text2});
setListAdapter(adapter);
if (getIntent().getAction()
.equals(Intent.ACTION_CREATE_SHORTCUT)) {
createShortcut("ContactLivefolder");
}
}
public void createShortcut(String name){
Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.setClassName(this, this.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addShortcut = new Intent();
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
Parcelable icon = Intent.ShortcutIconResource.fromContext(
this,R.drawable.icon);
addShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
this.setResult(RESULT_OK, addShortcut);
finish();
}
emulator 运行截图:
* 系统联系人:
* shortcut 运行:
done!!!