How can you programmatically open a page from the native Android settings menu using NativeScript?
Classic java examples show it can be done this way:
Intent intent = new Intent(Settings.ACTION_SETTINGS);
startActivity(intent);
but how to do the same in NativeScript?
This can be achieved using the module tns-core-modules/application, which will make startActivity available. An example using TypeScript is provided below:
import * as appM from 'tns-core-modules/application';
const intent = new android.content.Intent(android.provider.Settings.ACTION_SETTINGS);
const activity = appM.android.foregroundActivity || appM.android.startActivity;
activity.startActivityForResult(intent, 0);
Unfortunately, TypeScript types are not included for foregroundActivity and startActivity, which made finding a solution to this extremely hard.
A big thanks to user10655801 for his test repo containing the solution.
Related
for some time, I have been observing that modern android apps(Telegram) use a new way to open urls in the app. By default, the apps I have made, use ACTION_VIEW and the external browser open the url. These apps now manage that intent with a kind of in-app browser witch adapts to the same style. Any idea of what its?
sample
Those are Custom chrome tabs.In app browser.instead of using webview to open your Url, you are going to customize your chrome browser,to look alike your app.you can modify the toolbar tab color as per your app theme .You could give enter and exit animation like fragments transition.So the user wouldn't feel a big transition from your app to browser.For implementation details check this link https://developer.chrome.com/multidevice/android/customtabs
For security reasons also it could be useful,as because you are not going handle those url on you own or inside your app(there might be some security issues with JavaScript)
This is done with WebView. You will find the documentation very interesting https://developer.android.com/reference/android/webkit/WebView
This is achieved by WebView in an Activity that displays web pages. Instead of
Uri uri = Uri.parse("https://www.google.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
You will load the page by calling:
webviewObj.loadUrl("https://www.google.com/");
You can check the official document which describes the whole process. Basic Usage of WebView has been described in this blog which is easy to comprehend and implement.
do the following:
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
try this it helps you.
I am a tyro in Kotlin but I have a good Knowledge of Android and Core java. I am stuck on one condition while developing an android app via the Kotlin assistance.
I want that when user clicks a link present on the pdf document; the link should be opened on a browser (and if browser is opened then the link should open on the new window not new tab of the same window ).
I have achieved much of my objective but I didn't found out how to open a link in the new Window if the browser is open already?
I have tried the code below(when the link on the pdf is clicked then it redirects to the below function call):
fun web_page_open(urls: String) { // for more than one url
val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris)
startActivity(intents)
}
I have tried my level-best to explain my problem and also searched a lot(on github as well) but all my efforts went in vein.
Any help is warmly welcomed.
EDIT: Let's consider an instance if the user has already opened the default browser (say ABZfox) then when the link inside the pdf(or a doc) is clicked then the new Window of ABZfox opens instead of the same window in which the user was previously working. I'm sure the question makes some sense now!!!
You can try this one, might be helpful, open new tab of web browser like
fun openNewTabWindow(urls: String, context : Context) {
val uris = Uri.parse(urls)
val intents = Intent(Intent.ACTION_VIEW, uris)
val b = Bundle()
b.putBoolean("new_window", true)
intents.putExtras(b)
context.startActivity(intents)
}
You may use chrome custom tabs instead
To use it you need to add below dependency to your gradle
compile 'com.android.support:customtabs:23.1.1'
Now use below code to open the url
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.enableUrlBarHiding();
builder.setShowTitle(true);
builder.setToolbarColor(Color.TRANSPARENT);
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
I'm a web developer. I'm currently developing android application on Android Studio using WebView which access my website as an android application. One of my webpage contains many external links. My goal is to make the android application can handle external links like Gmail App does (also like facebook and Line do).
Below is the example of gmail app.
An email contains external link
Link clicked, then application open a new activity acts like a browser without leaving Gmail application
Any idea how to make it?
It is pretty simple. You have to use Chrome Custom Tabs as suggested by Gergely as well in comment. Below is the small functional code that will help you to achieve this.
First add this dependency to your build.gradle(Module:app)
compile 'com.android.support:customtabs:23.4.0'
Second add below function to your code and simply pass string URL to it.
private void redirectUsingCustomTab(String url)
{
Uri uri = Uri.parse(url);
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
// set desired toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
// add start and exit animations if you want(optional)
/*intentBuilder.setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
intentBuilder.setExitAnimations(this, android.R.anim.slide_in_left,
android.R.anim.slide_out_right);*/
CustomTabsIntent customTabsIntent = intentBuilder.build();
customTabsIntent.launchUrl(activity, uri);
}
Rest it will take care itself. Since Chrome Custom Tabs can customised so lot can be done like you can add menu to toolbar. For detailed information you can visit official documentation from Google itself here.
Hope it will help you to start with :)
Is is possible to open the Sonos android Controller passing for example a search query that the controller will process and display results for?
For example:
Intent i = getPackageManager().getLaunchIntentForPackage("com.sonos.acr");
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setData(Uri.parse("artist:The%20Doors"));
startActivity(i);
We don't support this today. I will bring this up with the team as a possible future feature.
I want to show an image in my Sony Smarwatch Sample project. How can I add a link to an external URL? The URL has to be shown in my device not in the SmartWatch. My code is the following, with this my image is shown in the layout:
Bundle iconBundle = new Bundle();
iconBundle.putInt(Control.Intents.EXTRA_LAYOUT_REFERENCE, R.id.thumbnail);
iconBundle.putString(Control.Intents.EXTRA_DATA_URI,
ExtensionUtils.getUriString(mContext, R.drawable.thumbnail_list_item));
¿How can I add a event to this bundle? I want to go to an external url. How can I add a link to my Preference Class?
I am not totally sure I understand what you are asking, but if you want to be able to click on something on the watch and have it launch a url you can use this code:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/developer?id=Sony+Mobile+Communications"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(intent);
If you want to launch the preference settings screen for your app you can do something like this:
Intent intent = new Intent(ctxt, HelloLayoutsPreferenceActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctxt.startActivity(intent);
This should work in the Hello Layouts sample project. The context is passed in the control extension constructor so you should be able to grab it from there. Please let me know if this is not what you were asking.