Rectangle 27 1

Intent i=new Intent(FirstActivity.this, SecondActivity.class);
 i.putExtra("file", fileUrl);
 startActivity(i);

in SeconActivity, Use WebView

Intent i = getIntent();
    String myPdfUrl = i.getStringExtra("file");
    String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
    String doc="<iframe src='"+url+"' width='100%' height='100%' style='border: none;'></iframe>";
    WebView web=(WebView)findViewById(R.id.webViewpdf);
    webView.getSettings().setJavaScriptEnabled(true); 
    webView.loadData(doc, "text/html", "UTF-8");
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

    <WebView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/webViewpdf"/>

</LinearLayout>

Thank you @userJP but this code providde options for opening PDF file in Drive or Browser(Chrome, firefox,etc.). I want to open inside the SecondActivity only.

Open PDF file in my android application without using any browser or t...

android pdf pdfviewer external-application
Rectangle 27 0

You can use webview.What you said,it doesn't show google.Maybe problem is in other place.There is no way of being an error while showing google.Webview is ofcourse for the purpose of showing web pages.

with webview it shows google.com but in the browser whereas i want the webpage to be displayed inside the application itself.

java - How can we view webpages in our android application without ope...

java android browser android-widget
Rectangle 27 0

it must useful to u.. it will not load in browser..

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;

public class WebViewDemo extends Activity {
    private class MyWebViewClient extends WebViewClient {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
          view.loadUrl(url);
          return true;
      }
  }
    private WebView webView;
    private EditText urlField;

    private Button goButton;

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

        // Create reference to UI elements
        webView  = (WebView) findViewById(R.id.webview_compontent);
        urlField = (EditText)findViewById(R.id.url);
        goButton = (Button)findViewById(R.id.go_button);

        // workaround so that the default browser doesn't take over
        webView.setWebViewClient(new MyWebViewClient());

        // Setup click listener
        goButton.setOnClickListener( new OnClickListener() {
            public void onClick(View view) {
                openURL();
            }
        });

        // Setup key listener
        urlField.setOnKeyListener( new OnKeyListener() {
            public boolean onKey(View view, int keyCode, KeyEvent event) {
                if(keyCode==KeyEvent.KEYCODE_ENTER) {
                    openURL();
                    return true;
                } else {
                    return false;
                }
            }
        });

    }

    /** Opens the URL in a browser */
    private void openURL() {
        webView.loadUrl(urlField.getText().toString());
        webView.requestFocus();
    }    
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content">

        <EditText  
        android:id="@+id/url" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"     
        android:lines="1"
        android:layout_weight="1.0" android:hint="http://"/>

        <Button
        android:id="@+id/go_button"
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"     
        android:text="@string/go_button"
        />

    </LinearLayout>

    <WebView  
        android:id="@+id/webview_compontent"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_weight="1.0"   
    />
</LinearLayout>

and in mainfiest file don't forget to give internet permission.. i hope this help u..

have tried this but the webpage is opening in the browser with this , whereas my problem was to load the webpage inside the application

no it will no load in browser.. you just decrease the height width of webview in xml.. u will see that its loading in particular portation,,,

java - How can we view webpages in our android application without ope...

java android browser android-widget
Rectangle 27 0

No. If multiple apps can handle the same http uri scheme the user will be given the choice which to use. They can of course then choose to "always use this option" when they choose the app to use.

It's not possible to launch an app directly and pass the uri as an extra to the intent?

Of course but that is not the same thing as your original question. Any such data can be sent with an intent. I was assuming you were using the system to launch the uri (you said launch with a web intent) and not starting an app with a specific extra.

Sorry if my question wasn't clear - but yeah, looks like I want to use setClassName and setData and that'll launch the app directly.

android - How do I launch an application via a web intent without prom...

android android-intent
Rectangle 27 0

Take a look at the activity lifecycle. You may want to move your intent to OnStart() for when the application comes back to the foreground after being stopped.

Thank you Bryan, but move my intent to onstart will cause the same webpage showing every time when I launch. Say, if I was in the middle of sending the email, I went to my music, and when I come back to start my app, then I will lose my email. So what I need is to go back to where I was before the interruption and not a new page.

Opening a web browser from an Android application - Stack Overflow

android browser android-intent
Rectangle 27 0

Why don't you use the android.webkit.WebView which will allow you to directly browse web pages in your app. Here the web content will remain persistent as long as the application is running. On the chance that your application stops you could save the url using WebView.getURL() which would allow you to continue from where you left of the next time you start your app. If this is what you want to do let me know and I will post some sample code.

Opening a web browser from an Android application - Stack Overflow

android browser android-intent
Rectangle 27 0

It looks like you are trying to combine all of your desired intent-filters into one intent filter. This is not how Android works; you must specify each desired intent filter in its own element. For example:

<activity
    android:name="mainActivity"
    android:label="@string/app_name"
    android:exported="true" >
    <intent-filter>
        <data  android:scheme="myurlscheme" />

        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

android - launch application from browser and start screen - Stack Ove...

android url browser android-manifest
Rectangle 27 0

This should just work. In fact, I just tried it my self with a similar URL and it works on my device. So my guess is that another app on your phone is interfering and receiving the intent, instead of the browser. You can check by inspecting "adb logcat" to see to which package the intent is sent.

NFC Tag is not opening URL in Browser on Android - Stack Overflow

android nfc ndef
Rectangle 27 0

I did not test this, but the most obvious way should be to use the PackageManager to find what application / Activity can resolve the Intent to browse a web address.

The Intent should have action ACTION_VIEW and the data could be "http://www.google.com" or any web URL you would like (as long as it starts with http)

java - How to fetch all the browser names installed on android mobile ...

java android
Rectangle 27 0

Couldn't find a direct solution, but used a workaround. I've figured out how to either force the music player to load the url (without giving you a choice of opening it via the browser), or initiate a direct download of the file.

To force the music player to load a url:

//...considering url contains the url string...
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "audio/*");
startActivity(intent);

To force the initiation of a download:

You need to implement this technique on the server-side... but with a few exceptions:

The content-type header should actually contain the right mime-type of the file (and not "application/octet-stream"). Also it is best to also send a "content-length" header with the file size - otherwise there might be problems with the download.

If using aspx: Response.TransmitFile is better than Response.WriteFile - and in that case Response.Buffer should be set to false.

browser - Android: "complete action using..." for custom WebView runni...

android browser download webview mp3
Rectangle 27 0

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

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

        mWebView = (WebView) findViewById(R.id.webView);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.google.com/");
    }
}
<uses-permission android:name="android.permission.INTERNET" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  
        android:id="@+id/webView"
        android:scrollbars="none" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>

well trying this also comes up with the same problem , i am redirected to the browser and once i get redirected i can come back to my application!

Okay , Basically i am working on an android application and i want to open a webpage inside my application so that i can close it anytime i want and can get back to my application , but with webview the webpage is getting displayed in the external browser and i find no way to return to my application from it.........

No,Anuj this webview demo is not open in browser its open in your application's webview . So when webpage is load you are in your application, not in another browser.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

java - How can we view webpages in our android application without ope...

java android browser android-widget
Rectangle 27 0

Try this if you want to open the browser OUTSIDE your app. I know it seems like a simple(and trivial) edit, but I've never had issues setting it up this way.

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    /** setup the url and start a browser with 
     *  the hotmial.com and return to the user
     * */
    String url = "http://www.hotmail.com";
    Uri uri = Uri.parse(url);
    Intent i= new Intent(Intent.ACTION_VIEW, uri);  
    startActivity(i);

}

Opening a web browser from an Android application - Stack Overflow

android browser android-intent
Rectangle 27 0

You use the Android Intent invocation that is available in the Android browser and demonstrated in here.

The problem that you will face is that not every app supports the ability to be opened from the Web Browser. This also relies on the fact that you are on the same machine and doesn't solve your "cabled" issue. You will also have to know how to exactly integrate with these Android apps, and that is not something that they often expose.

google chrome - Is there a way a browser can directly talk to android ...

android google-chrome
Rectangle 27 0

Maybe try opening a local html file which you can use to insert your javascript code and then load the page that you want to browse in an iframe?

Opening the Browser without address bar via an intent in an android ap...

android browser
Rectangle 27 0

To the best of my knowledge there is no way to specify if a new tab is opened or not using the Intent. I even did some looking and could not find anyway to check which tabs were open. Another thing you may be able to try is keeping track of if the user has recently been sent to the browser activity from your application, and check if the browser is still open, but once again I can see this going wrong in numerous ways.

Your activity idea would probably be one of the best bets in this situation, though I can understand why you would want to avoid that.

"You could always end the process for the browser, and that should close all tabs, but I doubt that is the ideal solution." -- that's not possible, except maybe if his app is running as root on a rooted phone.

Not possible? It is definitely possible to end a task, how else would there be so many task killers? Now I just tried it though and it opened the same tabs when I restarted the browser, so that part may not work, but you can definitely end tasks.

Worked fine on 2.3 just now...? Idk maybe I am missing something. Doesn't really matter, either way the browser came back on with the same tabs so it wouldn't work for him.

Open an url in android browser, avoid multiple tabs - Stack Overflow

android
Rectangle 27 0

Yes you can do this by the following code:

first of all you need to add the following code in your manifest file:

<activity android:name="YouActivityNameHere">
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
            <data android:mimeType="image/*" />
            <data android:mimeType="video/*" />
        </intent-filter>
        <meta-data/>
 </activity>

Now the above code tell the android OS to add this activity in shared list of only text,image and video.

And now your application have ability to handle share data only for text, image and video.

and next thing is that for handling data you have to handle the your YouActivityNameHere.java file and there code is neaar about similar to follows code:

if (intent.getAction().equals(Intent.ACTION_SEND)) {

        String text_data = intent.getStringExtra(Intent.EXTRA_TEXT);
        // and now you can handle this text here what you want to do. 
}

How to Share URL via browser to our application by intent filter in an...

android android-intent
Rectangle 27 0

Android is capable of detecting links to Google Maps in the browser and redirect the Intent to the native Google Maps app, if it is set as the default app. There is, however, no way to force the user to use the Google Maps app. Clicking the link can also show him the activity chooser or open Google Maps in the browser. It might also open a third-party app that is registered to handle the same Intent. The code snippet you posted will behave exactly like that, too.

This not only works from the browser, but with all links in the system. For example, I sent the link you posted via e-mail to myself and clicked it on my phone. I could open it with my Goolge Maps app. So there is really no need for JavaScript, you can just use a simple HTML link to send the Intent.

Can I launch an intent using only javascript in an Android browser? - ...

javascript android android-intent maps
Rectangle 27 0

Uri uri = Uri.parse("http://www.gmail.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

You need to specify permission in manifest file

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

java - How can we view webpages in our android application without ope...

java android browser android-widget