1

The following piece of code successfully transfers the putExtra value when the app is not running in the instant version. However, when I switch to the instant module, the intent does not transfer it. Any idea what I'm doing wrong? I tried going through the instant apps FAQ and saw some sample instant apps code, but couldn't find a solution.

Intent intent = new Intent();
String packageName = "com.example";
String className = "com.example.InfoActivity";
if(InstantApps.isInstantApp(getApplicationContext()))
{
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("https://www.example.com/instant/info"));
}
else {
    intent.setClassName(packageName, className);
}
intent.putExtra("value", 2);
startActivity(intent);

The links have been mapped to URLs, and the activity opens, however the data is not passed through.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Advait Saravade
  • 3,029
  • 29
  • 34
  • Try to catch the `ActivityNotFoundException` exception. This exception is thrown when no application can handle the `ACTION_VIEW` event. – Maxouille Oct 07 '18 at 15:44
  • The activity is found by the app, and is opening it, but the data is not going through. There is no `ActivityNotFoundExceptions` – Advait Saravade Oct 07 '18 at 15:45
  • Have you added the `build.gradle` the dependency : implementation `'com.google.android.instantapps:instantapps:1.0.0'`? – Jessica Rodriguez Oct 08 '18 at 10:00
  • @jess yeah the dependancy is in the `build.gradle` of the baseFeature module. The version is 1.1.0 though. – Advait Saravade Oct 08 '18 at 19:49
  • Have you already checked this [SO post](https://stackoverflow.com/questions/44309515/is-there-an-android-build-flag-to-check-for-apk-versus-instant-app-version-of-an)? – Jessica Rodriguez Oct 09 '18 at 00:54
  • @jess yep. I'm doing everything they've mentioned: using google's maven as well as implementing the instant apps library. – Advait Saravade Oct 09 '18 at 03:25
  • It's probably more reliable to add these extras as query parameters to your URL. Since the intent goes through different steps for an instant app (Chrome, Google Play Services, etc...), probably the intent extras are lost. – Hassan Ibraheem Oct 09 '18 at 04:08
  • @HassanIbraheem you're absolutely right. The technique you mentioned worked. Could you please write it as an answer and I'll mark it as correct. – Advait Saravade Oct 09 '18 at 05:04
  • @Advait S, could you try to run your code on O+ device and see if this works? I was able to successfully transfer data through intent extras on O+ devices, but this doesn't work for me on pre-O. – Julia K Oct 09 '18 at 19:23
  • @JuliaK Yes, I have the same issue. I ended up going with Hassan's solution of passing the extra values via query params in URL (example.com/instant/info?key=value) and getting the URI in the receiving activity. – Advait Saravade Oct 09 '18 at 19:43

0 Answers0