创建一个定制的;以“打开”;Android中的对话框
单击文件时,“打开方式”对话框中将显示多个选项。这是因为我用Action_视图发送了一个意图,并且有多个应用程序可以接收它创建一个定制的;以“打开”;Android中的对话框,android,android-intent,Android,Android Intent,单击文件时,“打开方式”对话框中将显示多个选项。这是因为我用Action_视图发送了一个意图,并且有多个应用程序可以接收它 intent.setAction(android.content.Intent.ACTION_VIEW); Uri fileUri = Uri.parse("file://" + location); 出于安全原因,我想禁用其中一些应用程序,例如,用于从我的应用程序打开文件的打印机应用程序 是否有一种机制来过滤选项或选择要显示的选项 如果知道应用程序名,可
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri fileUri = Uri.parse("file://" + location);
出于安全原因,我想禁用其中一些应用程序,例如,用于从我的应用程序打开文件的打印机应用程序
是否有一种机制来过滤选项或选择要显示的选项 如果知道应用程序名,可以尝试使用SetPackage。例如,在代码中,可以使用setPackage指定包名
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setPackage("com.test.print");
Uri fileUri = Uri.parse("file://" + location);
我之所以回答我的问题,是因为它可以让任何寻找类似产品的人受益。 因此,您可以通过以下方式自定义和创建自己的“打开方式”对话框: 步骤1:获取要显示的应用程序列表。为此,您需要从意图中筛选出应用程序
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(fileUri, mimeType);
List<ResolveInfo> getAllAppswhichcanViewtheFile = (List<ResolveInfo>)getApplicationContext().getPackageManager().queryIntentActivities(intent, 0);
Iterator<ResolveInfo> i = getAllAppswhichcanViewtheFile .iterator();
while (i.hasNext()) {
ResolveInfo file = i.next();
// Use condition to filter the List
if (file.activityInfo.packageName.contains(XXXX)) {
i.next();
} else {
i.remove();
}
List<ResolveInfo> resolvedPrintList = getAllAppswhichcanViewtheFile ;
intent1.setClassName(info.activityInfo.packageName、info.activityInfo.name);
星触觉(intent1)} }); 步骤3:创建适配器: 公共类OpenWithArrayList扩展了ArrayAdapter{
Context context;
Object[] items;
boolean[] arrows;
int layoutId;
public OpenWithArrayList(Context context, int resource,
int textViewResourceId, List<ResolveInfo> objects) {
super(context, resource, textViewResourceId, objects);
this.context = context;
this.items = objects.toArray();
this.layoutId = resource;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row==null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.basiclistview,parent, false);
TextView label=(TextView)row.findViewById(R.id.text1);
label.setText(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
ImageView image = (ImageView) row.findViewById(R.id.logo);
image.setImageDrawable(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadIcon(context.getPackageManager()));
}
return(row);
}
语境;
对象[]项;
布尔[]箭头;
国际布局;
公共OpenWithArrayList(上下文,int资源,
int textViewResourceId,列出对象){
超级(上下文、资源、textViewResourceId、对象);
this.context=上下文;
this.items=objects.toArray();
this.layoutId=资源;
//TODO自动生成的构造函数存根
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
视图行=转换视图;
if(行==null){
LayoutFlater充气器=(LayoutFlater)context.getSystemService(context.LAYOUT\u充气器\u服务);
行=充气机。充气(R.layout.basiclistview,父级,false);
TextView标签=(TextView)row.findViewById(R.id.text1);
label.setText(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
ImageView image=(ImageView)row.findViewById(R.id.logo);
image.setImageDrawable(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadIcon(context.getPackageManager());
}
返回(行);
}
}
builder.create();
builder.show();
Context context;
Object[] items;
boolean[] arrows;
int layoutId;
public OpenWithArrayList(Context context, int resource,
int textViewResourceId, List<ResolveInfo> objects) {
super(context, resource, textViewResourceId, objects);
this.context = context;
this.items = objects.toArray();
this.layoutId = resource;
// TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row==null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row=inflater.inflate(R.layout.basiclistview,parent, false);
TextView label=(TextView)row.findViewById(R.id.text1);
label.setText(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
ImageView image = (ImageView) row.findViewById(R.id.logo);
image.setImageDrawable(((ResolveInfo)items[position]).activityInfo.applicationInfo.loadIcon(context.getPackageManager()));
}
return(row);
}