Intent.ACRION.view , Intent.Action.pick intent.action.get_content几个的理解

来源:互联网 发布:hilbert矩阵 matlab 编辑:程序博客网 时间:2024/05/22 13:11

1、实现调用系统音乐播放器的方法有

(1)Intent intent_music = new Intent(Intent.ACTION_PICK);  
intent_music.setDataAndType(Uri.EMPTY,"vnd.android.cursor.dir/playlist");  
intent_music.putExtra("withtabs", true); // 显示tab选项卡  
intent_music.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 

Intent j =Intent.createChooser(intent_music, "Choose an application to open with:");
if (j == intent_music) {
startActivity(j); 
} else {
Intent intent = new Intent("android.intent.action.MUSIC_PLAYER"); 
startActivity(intent);
}

(2)

public void playAudioUserSystemPlayer(String audioPath,Context context ){
Intent i=new Intent(Intent.ACTION_VIEW);
Uri uri=Uri.parse("file://"+audioPath);
/ /Uri uri=Uri.fromFile(filemusic);
i.setDataAndType(uri, "audio/*");
context.startActivity(i);
}

2、pick ,get_content 的区别 (英文不行 就不献丑了)
Activity Action: Allow the user to select a particular kind of data and return it. This is different than ACTION_PICK in that here we just say what kind of data is desired, not a URI of existing data from which the user can pick. A ACTION_GET_CONTENT could allow the user to create the data as it runs (for example taking a picture or recording a sound), let them browse over the web and download the desired data, etc.
看下面代码 就可以理解了

(一)、调用本地联系人:

 Intent intent = new Intent(Intent.ACTION_PICK);

 intent.setType(ContactsContract.Contacts.CONTENT_TYPE);

 startActivityForResult(intent, PICK_CONTACT);


(二)、调用图库,获取所有本地图片:

Intent imageIntent = new Intent(Intent.ACTION_GET_CONTENT);

 imageIntent.setType("image/*");

 startActivityForResult(imageIntent, PICK_IMAGE);


(三)、调用音乐,获取所有本地音乐文件:

Intent audioIntent = new Intent(Intent.ACTION_GET_CONTENT);

audioIntent.setType("audio/*");

startActivityForResult(audioIntent, PICK_AUDIO);


(四)、调用图库,获取所有本地视频文件:

Intent videoIntent = new Intent(Intent.ACTION_GET_CONTENT);

videoIntent.setType("video/*");

startActivityForResult(videoIntent, PICK_VIDEO

3、而这里还有一个问题 就是 action.view 和 action.pick的区别 就是为什么一样可以调用这个 音乐播放器
临时有事 明天继续研究
     ACTION_VIEW
    最通用的动作。View动作要求Intent URI中的数据以最合理的方式显示。不同的应用程序将处理View请求,依赖于URI中的数据。一般的,http:地址会在浏览器中打开,tel:地址会在拨号工具中打开并呼叫号码,geo:地址会在Google地图应用程序中显示,联系人内容会在联系人管理器中显示。
参考资料 http://www.eoeandroid.com/thread-75418-1-1.html
 so 就可以理解了 本人菜鸟 随便写 也可随便看看 有空多指点

0 0