0

I am attempting to connect my emulator to a webpage using the eclipse android editor. I have been following some online tutorials from android and thought I had solved my problem, but I get an error that there is no action available to handle my intent when trying to redirect to google.com. Does anybody have any idea what I did wrong? I added the intent filler to my manifest and used the proper syntax, but I am unsure why I cannot get the emulator to redirect. Any help/advice would be appreciated, thanks!

MainActivity

package com.example.webpage;

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 MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
           Button mButton = (Button) findViewById(R.id.button1);
            mButton.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    Uri uri = Uri.parse("http://www.google.com");
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);


                }

            });

    }
}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.webpage"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.webpage.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />  
                <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
        </activity>
        <activity android:name="webpage"></activity>
    </application>

Logcat

06-06 16:39:37.090: E/AndroidRuntime(939): FATAL EXCEPTION: main
06-06 16:39:37.090: E/AndroidRuntime(939): Process: com.example.webpage, PID: 939
06-06 16:39:37.090: E/AndroidRuntime(939): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://www.google.com }
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Activity.startActivityForResult(Activity.java:3424)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Activity.startActivityForResult(Activity.java:3385)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Activity.startActivity(Activity.java:3627)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.Activity.startActivity(Activity.java:3595)
06-06 16:39:37.090: E/AndroidRuntime(939):  at com.example.webpage.MainActivity$1.onClick(MainActivity.java:23)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.view.View.performClick(View.java:4438)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.view.View$PerformClick.run(View.java:18422)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.os.Handler.handleCallback(Handler.java:733)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.os.Handler.dispatchMessage(Handler.java:95)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.os.Looper.loop(Looper.java:136)
06-06 16:39:37.090: E/AndroidRuntime(939):  at android.app.ActivityThread.main(ActivityThread.java:5042)
06-06 16:39:37.090: E/AndroidRuntime(939):  at java.lang.reflect.Method.invokeNative(Native Method)
06-06 16:39:37.090: E/AndroidRuntime(939):  at java.lang.reflect.Method.invoke(Method.java:515)
06-06 16:39:37.090: E/AndroidRuntime(939):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:776)
06-06 16:39:37.090: E/AndroidRuntime(939):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-06 16:39:37.090: E/AndroidRuntime(939):  at dalvik.system.NativeStart.main(Native Method)
wheatfairies
  • 355
  • 2
  • 7
  • 19

1 Answers1

0

You must start the Url with either http:// or https:// in order to avoid ActivityNotFoundException

so you should check for the condition like this:

if (!url.startsWith("https://") && !url.startsWith("http://")){
    url = "http://" + url;
}
Intent it = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(it);
Pankaj
  • 2,115
  • 2
  • 19
  • 39
  • I agree we should ehck to make sure it conforms to the scheme. But his example clearly has a URL starting with http:// – Raghu Jun 06 '14 at 18:04
  • I have my URL starting with http:// but I will add the code and see if it changes anything real quick. UPDATE - still nothing, I don't know why this isn't working. – wheatfairies Jun 06 '14 at 19:08
  • @Raghu Is it possible that there could be some kind of connection blockage between a firewall and the emulator? I enabled IIS and allowed the adk mime type to go through, but I can't even get a response from a post on a localhost machine that I am running this on. – wheatfairies Jun 06 '14 at 19:21
  • can you open any web page in your emulator web browser?? – Pankaj Jun 06 '14 at 19:22
  • @Pankaj No. The emulator returns an error when I try to redirect to a webpage. I assume I can connect to my localhost using post because I am able to grab a response and log it, but it is always unintelligible. I know my php script is okay because it works if I access the localhost and use another script. It has to be some sort of configuration error with my emulator. – wheatfairies Jun 06 '14 at 19:58
  • 1
    Look at this post. May be your emulator is missing the browser app? http://stackoverflow.com/questions/14596227/activitynotfoundexception-no-activity-found-to-handle-intent-act-android-inte One thing you can do is try creating a new VD and see if that helps. Also, did you try on a real device yet? – Raghu Jun 06 '14 at 20:31