android获取安装的视频播放软件信息

1、曾经遇到过一个需求,获取手机已安装的播放软件信息,整理下代码如下:

package cn.geekapp.util;

import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

public class PackageUtil {
private static PackageUtil instance_ = null;

private static Context context_ = null;

private PackageUtil() {
}

public static PackageUtil getInstance(Context context){
if(instance_ == null){
instance_ = new PackageUtil();
}
context_ = context;
return instance_;
}

public List getVideoInfos(){
PackageManager pm = context_.getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("video/*");
List list = pm.queryIntentActivities(intent, 0);
return list;
}

public List getVideoInfos(){
PackageManager pm = context_.getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("video/*");
List list = pm.queryIntentActivities(intent, 0);
List infoList = new ArrayList();
for(ResolveInfo rInfo : list){
PackageUtil.InfoBean bean = new PackageUtil.InfoBean();
bean.label = (String) rInfo.loadLabel(pm);
bean.icon = rInfo.loadIcon(pm);
bean.name = rInfo.activityInfo != null ? rInfo.activityInfo.name : null;
bean.packageName = rInfo.activityInfo != null ? rInfo.activityInfo.packageName : null;
infoList.add(bean);
}
return infoList;
}

public class InfoBean{
public String label;
public Drawable icon;
public String name;
public String packageName;
}
}

2、若想获取其他软件,如安装的音乐播放器信息,修改intent.setType(“video/*”)为intent.setType(“audio/*”)即可,以此类推,就可以发出不同的意图,返回相应的处理软件信息。

3、ResolveInfo类常用方法:

public Drawable loadIcon(PackageManager pm)//获取应用图标
public CharSequence loadLabel(PackageManager pm)//获取应用名称

原创内容转载请保留出处GEEK笔记(https://www.geekapp.cn/)。

原创博客,转载请标明出处:https://www.geekapp.cn/archives/139.html
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇