Trondro Mulligan
Trondro Mulligan

Reputation: 505

How to open another app in a popup/window?

I'm opening another app from my app using this code:

Uri uri = Uri.parse("http://url_to_app's_website");
Intent in = new Intent(Intent.ACTION_VIEW, uri);
in.setPackage("com.package.address");

try {
    startActivity(in);

} catch (ActivityNotFoundException e) {

    startActivity(new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://url_to_app's_website")));
}

This is working but it opens the app with full screen. I want to open it in a window/popup. How do I do that?

Upvotes: 0

Views: 2115

Answers (3)

CommonsWare
CommonsWare

Reputation: 1006674

On Android N, if the user has put the device into a multi-window mode, you can use FLAG_ACTIVITY_LAUNCH_ADJACENT to try to launch the other activity into a separate window. However, you cannot guarantee this will work, as the other app's developers have to agree.

Prior to Android N, you cannot open another application into any sort of popup, unless that application has some specific API for that.

Upvotes: 1

Viral Patel
Viral Patel

Reputation: 33408

You seem to be just opening a web app. If that is the case, you should do the following:

  • Create a dialog with WebView
  • Show the dialog
  • Load the url in the dialog's webView

Refer to this SO Question which provides a means to do that.

Here is the code that will get you what you want: (borrowed from the answer to the question referenced above)

Dialog Layout :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
>
    <WebView
        android:id="@+id/webview"
        android:scrollbars="vertical"
        android:scrollbarAlwaysDrawVerticalTrack="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</LinearLayout>

Load your url in the Dialog's webView:

final TextView seeMonthlyBill = (TextView) parentLayout
            .findViewById(R.id.my_ac_my_service_timewarnercable_link);
    seeMonthlyBill.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Dialog dialog = new Dialog(getActivity());
            dialog.setContentView(R.layout.web_dialog)
            WebView wb = (WebView) dialog.findViewById(R.id.webview);
            wb.getSettings().setJavaScriptEnabled(true);
            wb.loadUrl("http://www.google.com");
            wb.setWebViewClient(new HelloWebViewClient());
            dialog.setCancelable(true);
            dialog.setTitle("WebView");
            dialog.show();
        }
    });

Upvotes: 1

Amirshayan Aghamiri
Amirshayan Aghamiri

Reputation: 109

The destination activity should support popup mode and if it is supported you should put the setting into a Bundle Object and pass it to Intent and then startActivity();

Upvotes: -1

Related Questions