2011-06-07 83 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); 
    } 

} 

問候

紫藤陳

相關問題