gpt4 book ai didi

java - 无法解析方法 'isIntentAvailable(android.content.intent)'

转载 作者:行者123 更新时间:2023-11-30 00:20:22 28 4
gpt4 key购买 nike

我正在学习 Udemy.com 上的一些教程,但遇到此语法错误“无法解析方法‘isIntentAvailable(android.content.intent)’我尝试在网上查找但找不到解决方案。它是否被弃用了?

提前致谢

   mPerformButton = (Button) findViewById(R.id.performImplicit);
mPerformButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = mSpinner.getSelectedItemPosition();
Intent implicitIntent = null;
switch (position){

case 0 :
//nothing selected
break;
case 1:
//deltaprogram.us
implicitIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://deltaprogram.us"));
break;
case 2:
//call someone
implicitIntent = new Intent(Intent.ACTION_DIAL,
Uri.parse("tel:(+000)8675309"));
break;
case 3:
//map of YETspace
implicitIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("geo:30.2715,-97.742"));
break;
case 4:
//take a picture( not returning it here though)
implicitIntent = new Intent("android.media.action.IMAGE_CAPTURE");
break;
case 5:
//edit first contact
implicitIntent = new Intent(Intent.ACTION_EDIT,
Uri.parse("content://contacts/people/1"));
break;

}

if(implicitIntent != null){

if(isIntentAvailable(implicitIntent) == true){ //Syntax Problem here
startActivity(implicitIntent);
}else{
Toast.makeText(v.getContext(),"no application available", Toast.LENGTH_LONG).show();
}
}

}
});

最佳答案

添加这个方法:

private boolean isIntentAvailable(Intent intent) {
return getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
}

关于java - 无法解析方法 'isIntentAvailable(android.content.intent)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46406352/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com