您的位置:首页 > 移动开发 > Android开发

Android之创建实时文件夹

2012-04-28 15:18 288 查看
以下使用的是SDK自带的例子来进行分析:

首先,需要在 AndroidManifest.xml中添加<action android:name= "android.intent.action.CREATE_LIVE_FOLDER" />

然后如下分析:

public class MyLiveFolder extends Activity {
public static final Uri CONTENT_URI = Uri.parse("content://my.app/live");

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//获得Intent
final Intent intent = getIntent();
//获得在AndroidManifest中设定的action
final String action = intent.getAction();
//判定
if (LiveFolders.ACTION_CREATE_LIVE_FOLDER.equals(action)) {
setResult(RESULT_OK, createLiveFolder(this, CONTENT_URI, "My LiveFolder",
R.drawable.ic_launcher_contacts_phones));
} 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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: