1

When I test instant app it works properly but after uploading on Play Store when I click on "Try Now button" app crash.

Here is my code when I click on Try Now button:

package com.journaldev.androidinstantapps.feature;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class ActivitySplash extends Activity {


        @Override
        protected void onCreate(Bundle savedInstanceState) {

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


            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://quickeselling.com/splash"));
            intent.setPackage(getPackageName());
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            startActivity(intent);
        }
    }

In manifest:

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

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />

    <application>
        <meta-data
            android:name="asset_statements"
            android:resource="@string/asset_statements" />
        <activity
            android:name=".ActivitySplash"
            android:label="@string/app_name">

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

            <meta-data
                android:name="default-url"
                android:value="https://quickeselling.com/preview" />

            <intent-filter
                android:autoVerify="true"
                android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="quickeselling.com"
                    android:pathPrefix="/preview"
                    android:scheme="http" />
            </intent-filter>
            <intent-filter
                android:autoVerify="true"
                android:order="1">
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="quickeselling.com"
                    android:pathPrefix="/preview"
                    android:scheme="https" />
            </intent-filter>

        </activity>
    </application>

</manifest>

In URL mapping I have opened my main app through URL from splash. Here is the URL mapping image.

enter image description here

I tried a lot but din't know what's wrong. Please help me to solve this issue. Here is the crash log:

enter image description here

Neal
  • 379
  • 4
  • 9
  • May be this is how you need to build the intent, https://stackoverflow.com/questions/14420167/launching-an-activity-with-an-intent – Jitendar M Dec 22 '18 at 07:39

2 Answers2

4

Clicking try now works and your ActivitySplash is launched. As you can see from the stacktrace, the crash happens from the second intent you launch yourself within onCreate. The problem is that you're specifying package on the intent

intent.setPackage(getPackageName());

Since your application isn't installed, Android won't find anything to match this intent. If the Activity you want to launch is in the same module, convert this intent to an explicit one by specifying the Activity class. Otherwise, remove setPackage, then Android will load the feature module handling that link and show it to the user (or open that URL in browser, if it can't find a matching feature module)

By the way, if you want to support both HTTP and HTTPS in intent-filters, you don't need to write the intent-filter twice. Just add

<data android:scheme="https" />

to the existing HTTP intent-filter, and both schemes will match your Activity.

Hassan Ibraheem
  • 2,329
  • 1
  • 17
  • 23
  • I removed line intent.setPackage(getPackageName()); but still after that uploading on playstore it gives same error. – Neal Dec 25 '18 at 04:53
  • Does it work if you install the instant app directly to your phone? Instant apps take a while to be rolled out to Google Play, did you confirm if you received the updated version of the app? – Hassan Ibraheem Dec 25 '18 at 05:08
  • Yes it works when I install in my phone. Actually in feature module I just have splash screen and I call this Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://quickeselling.com/splash")); intent.addCategory(Intent.CATEGORY_BROWSABLE); startActivity(intent); so it will open app module in which whole code is available. So still it gives error the same activity not found. Hope i have done proper – Neal Dec 25 '18 at 08:37
  • Regarding the 'app' module. This is the module building the full app with 'com.android.application' gradle plugin, right? In that case, it won't exist in instant app, since you will only get feature modules in there. How are you installing the instant app? There's a gradle task to do it in the instant app module, called sideloadDebug if I remember correctly. – Hassan Ibraheem Dec 25 '18 at 09:17
  • Yes the problem was that only and it solved. Thanks Bro. But while I upload app again on play store, it gives error while app open "org.apache.http.conn.HttpHostConnectException: Connection to http://crm.quickeselling.net refused". when in normal app work with this URL perfect. Any idea why it's giving error in instant app – Neal Jan 16 '19 at 05:50
  • Check if you're using "http" instead of "https" on that call. All plain text traffic isn't allowed in instant apps. – Hassan Ibraheem Jan 16 '19 at 06:07
  • yes URL was https and it worked but when app opened, it crash and gives error : Caused by: android.view.InflateException: Binary XML file line #14: Binary XML file line #7: Error inflating class in xml in 14 line i have – Neal Jan 30 '19 at 10:08
1

The URL you are trying to launch from your instant app's ActivitySplash: https://quickeselling.com/splash is not supported in your instant app (at least not from the feature manifests you have shown). The feature manifest you have provided only supports /preview.

So yes, the exception is correct, no activity will be found to handle this intent/URL.

Now, you've got a screenshot that shows your com.android.application module supporting the /splash URL. However, your application module is not installed as part of the instant app, it only gets installed when the user installs the full app.

Nothing from the application module can be accessed from the instant modules during its state as an instant app, if you were thinking otherwise.

You will have to move the activity that supports /splash to one of your feature modules for this to work.

This will help you understand a bit about the structure of instant apps: What dependencies should one be putting in each module of an instant app?

note: there should have been no way for this to work when you were developing from studio, unless you were unknowingly running it as an installed app instead of an instant app (which looks to be the case, from that screenshot, showing app as the selected run build).

TWL
  • 6,228
  • 29
  • 65
  • I just checked your Try Now button, and I don't see any crash, must mean your update to Hassan's answer fixed it, but it is launching the browser for your `/splash` instead. To continue onto your instant app, you should refactor your project as I have suggested. – TWL Dec 26 '18 at 19:05
  • Yes, it works and i changed but giving me "org.apache.http.conn.HttpHostConnectException: Connection to http://crm.quickeselling.net refused" error. While in normal app it works with this URL perfect. – Neal Jan 16 '19 at 05:53
  • Instant Apps only allows https connections, this crm.* url of yours is only on http. – TWL Jan 16 '19 at 17:47