首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:ActivityNotFoundException

Android:ActivityNotFoundException
EN

Stack Overflow用户
提问于 2013-05-27 17:56:06
回答 2查看 2.2K关注 0票数 2
代码语言:javascript
复制
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结果

代码语言:javascript
复制
 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

代码语言:javascript
复制
<?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>

看看能不能帮上忙..。我运行了一个具有相同函数的程序,其中没有从编辑文本中检索字符串,即在它的框架方法中提供所需的资源。

我说的那个的源代码

代码语言:javascript
复制
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);
}
EN

回答 2

Stack Overflow用户

发布于 2013-05-27 18:20:45

我认为您的问题是,没有处理Intent.ACTION_VIEW和Intent.ACTION_WEB_SEARCH操作的活动,要检查是否有处理您的意图的活动,可以在此之前检查以下内容:

代码语言:javascript
复制
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;

如果列表 Activity 中的活动数为0,这意味着此时还没有处理您的意图的活动,那么在尝试开始某个活动之前,您应该先检查一下。

编辑:正如我们所知,这些操作对于android设备(地图和web浏览器)来说是常见的,因此您应该检查您正在执行的URI是否正确。

票数 2
EN

Stack Overflow用户

发布于 2013-05-27 18:37:24

您的意图URI是错误的。或者更确切地说,TextView的内容不是以打开您所期望的搜索对话框的方式构造的。例如,尝试输入:

代码语言:javascript
复制
google.com/search?q=blah

作为您在TextView中的文本

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16778300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档