gpt4 book ai didi

java - 安卓:ActivityNotFoundException

转载 作者:搜寻专家 更新时间:2023-11-01 08:59:04 25 4
gpt4 key购买 nike

public void onContacts(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI);
startActivity(i);
}

public void onBrowse(View v)
{

String s1= et1.getText().toString();
Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse(s1));
startActivity(i);

}

public void onSearch(View v)
{

String s1= et2.getText().toString();
Intent i=new Intent(Intent.ACTION_WEB_SEARCH);
i.putExtra(SearchManager.QUERY, s1);
startActivity(i);
}

public void onMap(View v)
{

String s1= et3.getText().toString();
Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("geo:0,0?q="+s1));
startActivity(i);
}

这些是每个附加到各自按钮的几个方法,单击这些按钮中的任何一个时,它都会显示 ActivityNotFoundException,但 onContacts() 方法除外,该方法未附加到任何编辑文本...

logcat 结果:

 05-27 23:18:42.984: E/AndroidRuntime(714): Caused by:    android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google }

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.AllIntent"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER" />
<uses-permission android:name="android.permission.CALL_PHONE"/>

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AllIntentActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

看看这个能不能帮上忙我已经运行了一个具有相同功能的程序,其中没有从他的编辑文本中检索到任何字符串,即在方法本身中提供了所需的资源

我正在谈论的源代码

public void onContents(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW,ContactsContract.Contacts.CONTENT_URI);
startActivity(i);
}

public void onBrowser(View v)
{
Intent i= new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(i);
}

public void onSearch(View v)
{
Intent i=new Intent(Intent.ACTION_WEB_SEARCH);

i.putExtra(SearchManager.QUERY, "tapu");
startActivity(i);
}

public void onMap(View v)
{
Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=hyderabad"));
startActivity(i);
}

public void onCall(View v)
{
Intent i=new Intent(Intent.ACTION_CALL,Uri.parse("tel:9776215312"));
startActivity(i);
}

最佳答案

我认为您的问题是没有用于处理 Intent.ACTION_VIEW 和 Intent.ACTION_WEB_SEARCH 操作的 Activity ,要检查是否有用于处理您的 Intent 的 Activity ,您可以先检查一下:

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;

如果 activities 列表中的 Activity 数量为 0,这意味着目前没有用于处理您的 Intent 的 Activity,在尝试启动 Activity 之前,您应该首先检查它..

编辑:据我们所知,这些操作对于 Android 设备( map 和 Web 浏览器)是通用的,因此您应该检查您传递的 URI 是否正确。

关于java - 安卓:ActivityNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16778300/

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