Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Simone Galimberti
Simone Galimberti
3,054 Points

URL not loading

Hello, premit that I have already read this(https://teamtreehouse.com/forum/url-not-loading-in-webview ). I am trying to make an application that simulate a calculator through wolfram alpha results.

I only tested it on KiKat devices/emulator.

This is the code of The Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="simone.math2" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >
        <activity
            android:name=".MyActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Visualize"
            android:label="@string/title_activity_visualize" >
        </activity>
    </application>

</manifest>

Of the Main Activty

public class MyActivity extends Activity {
EditText myText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        myText = (EditText) findViewById(R.id.Result);
    }

    public void buttonPressed(View v)
    {
        int id=v.getId();
        Button pressed= (Button) v;
        String appendMe;
        switch (id)
        {
            // Strange specific cases
            case R.id.button11:
                // Canc button

            case R.id.button17:
                // Pi button


            default:   // Generic case
                appendMe=pressed.getText().toString();
                break;
        }
        // Add the string to the edit text
        myText.append(appendMe);
    }

    public void sendResult(View v)
    {
        String temp= myText.getText().toString();
        String temp2="https://m.wolframalpha.com/input/?i=";
        StringBuilder request=new StringBuilder();
        temp.trim();           // Remove spaces
        temp=Uri.encode(temp);  // Transform into uri format
        request.append(temp2);
        request.append(temp);

        // Avvio la webView
        Intent change=new Intent(this,Visualize.class);
        change.setData(Uri.parse(request.toString()));
        Toast.makeText(this,"inviato a :"+Uri.parse(request.toString()),Toast.LENGTH_SHORT).show();
        startActivity(change);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

Of the Activty with the web View

public class Visualize extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_visualize);

        Intent intent=getIntent();  // The intent that started this page
        Uri link=intent.getData();

        WebView web= (WebView) findViewById(R.id.webView);
        web.loadUrl(link.toString());
    }

}

[Removed the import for avoiding a wall of text]

Please, help me.

3 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Okay, we'll try to help! What specific problem are you seeing? What isn't working? Do you get any error messages in logcat?

Simone Galimberti
Simone Galimberti
3,054 Points

I launched the app both on the emulator and on a real nexus 7 2012 (always tested on kitkat) and when the second activty starts: white page and a chooser appears with a list of browser.....if i choose a browser the page I wanted loads normally (on the browser chosen)

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Ugh...this is an ugly issue because of how WebViews work and how the Wolfram Alpha site is designed. It has a mobile redirect that is causing problems no matter what I try. I'm sure there is a workaround somehow, but I haven't been able to find one yet.

You can get the WebView to work by using a different URL, but to continue with Wolfram Alpha you'll need to do additional research on how to get a WebView to work with a site that automatically redirects to a mobile version. Sorry I can't be of more help!

Simone Galimberti
Simone Galimberti
3,054 Points

logcat right now :

07-02 21:13:57.904 12469-12469/simone.math I/Timeline? Timeline: Activity_launch_request id:simone.math time:101611942

07-02 21:13:58.254 12469-12469/simone.math V/WebViewChromium? Binding Chromium to the background looper Looper (main, tid 1) {41b102e8}

07-02 21:13:58.254 12469-12469/simone.math I/chromium? [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0

07-02 21:13:58.254 12469-12469/simone.math I/BrowserProcessMain? Initializing chromium process, renderers=0

07-02 21:13:58.274 12469-12844/simone.math W/chromium? [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation

07-02 21:13:58.684 12469-12469/simone.math I/Choreographer? Skipped 37 frames! The application may be doing too much work on its main thread.

07-02 21:13:58.974 12469-12469/simone.math W/AwContents? nativeOnDraw failed; clearing to background color.

07-02 21:13:59.444 12469-12469/simone.math W/AwContents? nativeOnDraw failed; clearing to background color.

07-02 21:13:59.664 12469-12469/simone.math W/AwContents? nativeOnDraw failed; clearing to background color.

07-02 21:13:59.994 12469-12469/simone.math I/chromium? [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported

07-02 21:14:00.134 12469-12892/simone.math I/chromium? [INFO:simple_index_file.cc(397)] Simple Cache Index is being restored from disk.

07-02 21:14:00.174 12469-12469/simone.math I/chromium? [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported

07-02 21:14:00.644 12469-12469/simone.math I/Timeline? Timeline: Activity_idle id: android.os.BinderProxy@41cbbd38 time:101614690