2011-06-07 32 views
0

我正在编写代码以打开浏览器。但是当我运行该程序时,它显示活动未找到。是否有必要在Mainfest文件中声明活动,当我在程序中使用Intent.Action_VIEW,Uri代码?在我的程序中使用(Intent.ACTION_VIEW)时发生异常

我在Google上没有很多R & D,但无法找到解决方案。请帮忙。代码如下。我应该怎样做才能恢复这个问题。

private void openBrowser() { 
     Uri uri = Uri.parse(urlText.getText().toString()); 
     Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
     startActivity(intent); 
    } 
} 
+1

是的,您应该将您的活动添加到清单中!如果您使用外部链接,则还应该将Internet访问权限添加到清单文件中。 – THelper 2011-06-07 09:03:42

回答

2

这取决于你在文本框中输入。尝试使用http://www.google.com。它为我工作。从您的评论中,似乎您键入google.com而不是http://www.google.com。尝试这个!!!

+0

感谢Sweety ...其工作..其实我已经通过ui edittext框输入了内容。当我通过google.com ..错误来了,但是当我写http://www.google.com。它移动到浏览器中的谷歌页面..再次感谢 – 2011-06-07 09:41:40

0

<uses-permission android:name="android.permission.INTERNET"></uses-permission> 应该在AndroidManifest.xml

+0

我已经在mainfeast文件中写入了internet权限。但活动开始时间异常。例外情况如下:ERROR/AndroidRuntime(703):android.content.ActivityNotFoundException:未找到处理Intent的动作{act = android.intent.action.VIEW dat = google.com} – 2011-06-07 09:15:23

0

声明我创建了一个“HelloWorld”的应用程序和VIEW_ACTION开放的代码在这很好,所以我不认为“活动未找到”错误与它或权限有关。您应该检查您是否在AndroidManifest.xml中添加了您的活动。

package org.example.app; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 

public class Main extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Button button = (Button) findViewById(R.id.button1); 
     button.setOnClickListener(new OnClickListener(){ 

      @Override 
      public void onClick(View v) { 
       String url = "http://www.google.com/"; 
       browseWebPage(url); 
      }}); 
    } 

    public void browseWebPage(final String url) { 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(intent); 
    } 

} 

问候

紫藤陈

相关问题