question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open Intent without closing the TWA

See original GitHub issue

Hey

Not sure if this is a bug, or something that could potentially be improved/implemented in the future.

In the scenario where my users have Blocked notifications in the past, and we want to instruct them to Unblock once they’ve changed their mind, I’m trying to send the user to the App Notifications Settings dialog.

What I’ve done so far is:

		<activity android:name="com.mypackage.ReceiverActivity" android:exported="true">
			<intent-filter>
				<action android:name="openSettings" />

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

				<data
					android:scheme="myscheme"
					android:host="myhost" />
			</intent-filter>
		</activity>
public class ReceiverActivity extends AppCompatActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		Intent intent = new Intent();
		intent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		
		//for Android 5-7
		intent.putExtra("app_package", getPackageName());
		intent.putExtra("app_uid", getApplicationInfo().uid);
		
		// for Android 8 and above
		intent.putExtra("android.provider.extra.APP_PACKAGE", getPackageName());
		
		startActivity(intent);
	}
}

And then a button in my website that points to:

intent://myhost#Intent;scheme=myscheme;package=com.mypackage;action=openSettings;end

This works well, in terms of opening the App Notifications Settings, but it appears that the TWA activity closed, so if I try to go “Back”, I go back to my homescreen. In some situations, I get an Android alert saying that my app “keeps closing”.

Is there a way we can preserve the TWA activity open, and this Notifications dialog simply opens as an extra view/layer?

Thank you!

Desktop:

  • OS: Windows 11
  • Version: 1.17.2

Smartphone:

  • Device: LG, Android 10
  • Browser: Chrome 101

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:11

github_iconTop GitHub Comments

1reaction
PEConncommented, Jul 5, 2022

So the 100% fullscreen white view is ReceiverActivity, which it looks like you aren’t doing anything with (as in, it doesn’t have any UI that you want the user to interact with). You should call finish() at the end of onCreate so that ReceiverActivity gets closed once you’ve launched the Settings Activity.

You’re right that there’s no way for the TWA shell to tell Chrome “look, my notification permission has updated, please notice” short of restarting the TWA, we could open a feature request for that.

1reaction
PEConncommented, Jul 4, 2022

Or alternatively, could you give the output of adb logcat while reproducing this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TWA autocloses on firing chrome intent - Stack Overflow
I have a MainActivity that starts a TWA (Trusted Web Activity based on CCT protocol). I have extended the TWA Launcher with a...
Read more >
Android Trusted Web Activity integration guide
Open Android Studio and click on Start a new Android Studio project. ... This intent-filter adds the Trusted Web Activity to the Android...
Read more >
Trans World Airlines - Wikipedia
In January 2001, TWA filed for a third and final bankruptcy and was acquired by American Airlines. American laid off many former TWA...
Read more >
Añejo="So Close", WeTakeBitcoin, 4/5 Stars, Weekly ...
Añejo=”So Close”, WeTakeBitcoin, 4/5 Stars, Weekly Challenge, Open Air Drug Mkts, WeCrashed, Cold H2O TWA 4.11.22.
Read more >
OYO Lite: a TWA with the best of web and Android apps
How a hospitality startup built an Android app that relies on web content to dramatically increase user engagement and keep file size low....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found