2013-05-27 192 views
2
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除了未连接到任何editext的onContacts()方法...机器人:ActivityNotFoundException

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> 

看看这可以帮助.. 我已经运行具有相同功能的一个程序,没有字符串是从他的EditText检索,即所需的资源,该方法提供itshelf

对于一个

源代码我谈论

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

你确定你通过你的EditText传递一个正确的URI? – eternay

回答

2

我认为你的问题是,有没有活动的处理Intent.ACTION_VIEW和Intent.ACTION_WEB_SEARCH行动,检查没有用于处理你的意图的活动,你可以前检查:

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

如果活动在列表中的号码活动是0,则意味着不存在由时刻处理你的意图,试图前没有活动开始一个活动,你应该先检查这个..

编辑:因为我们知道这些行动是Android设备(地图和网络浏览器)常见的,由于这一点,你应该检查,如果你是pasing的URI是正确的。

+0

我已经编辑了内容看看它 – ceanan007

+0

好的,我测试了你提供的代码,通过在真实的Android设备(Galaxy Tab)中进行编辑,除了'onCall'方法之外的所有工作(是Wi-Fi平板电脑) ,那么你在哪里运行你的代码,模拟器或真实设备?你确定URI字符串是有效的URI后,你从EditText解析它们或任何你得到它们? – JosephChilberry

+0

是的,它在电话中工作,而不是在模拟器中。我没有尝试更早... – ceanan007

1

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

google.com/search?q=blah 

为您的文本在TextView