Open Intent without closing the TWA
See original GitHub issueHey
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:
- Created a year ago
- Reactions:1
- Comments:11
Top GitHub Comments
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 callfinish()
at the end ofonCreate
so thatReceiverActivity
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.
Or alternatively, could you give the output of
adb logcat
while reproducing this?