Android:ActivityNotFoundException

强颜欢笑 提交于 2019-12-11 04:01:38

问题


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);
}

These are few methods each attached to respective buttons, on clicking any of these button it shows ActivityNotFoundException except the onContacts() method which is not attached to any editext...

logcat result:

 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>

see if this can help.. I've run the a programme with same function where no string is retrieved from he edittext,i.e the required resources is provided in the method itshelf

source code for the one i'm talking about

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);
}

回答1:


I think your problem is that there is no Activity for handle the Intent.ACTION_VIEW and Intent.ACTION_WEB_SEARCH actions, to check if there is an Activity for handle your intent you could check this before:

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

if the number of Activity in List activities is 0 that means that there is no Activity for handle your Intent by the moment, before trying to start an Activity you should check this first..

EDIT: as we know those Actions are common to android device (maps and web browser), due to this you should check if the URI you are pasing are correct.




回答2:


Your Intent URI is wrong. Or rather the content of your TextView isn't constructed in a way which will open the search dialog you're expecting. Try, for example, entering:

google.com/search?q=blah

as your text in your TextView



来源:https://stackoverflow.com/questions/16778300/androidactivitynotfoundexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!