ask website visitors to save your website on their homescreen-android - android

is it possible to ask website visitors to save your website on their home-screen?
android

Check out this answer here, on how to create a shortcut:
How to add android bookmark on homescreen from web page?
If you're writing an Android app, you can use this approach. However, if this is a website, this approach will not work, as it looks like the Android Intent system ignores website generated actions.
you can create a web page shortcut on home screen using this code. Provide the necessary info like url, title etc..
final Intent in = new Intent();
final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
long urlHash = url.hashCode();
long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
in.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
in.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
in.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(
BrowserBookmarksPage.this,
R.drawable.ic_launcher_shortcut_browser_bookmark));
in.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//or in.setAction(Intent.ACTION_CREATE_SHORTCUT);
sendBroadcast(in);

Related

How to open links in Android app in external browser?

Can anyone help me in Code for opening links in external browsers or other Android app?
Now the case is the link is opening in the app itself. But if the link belongs to an android app its not opening. It's showing install the Android app.
So I want that if the link can be opened in browsers, then it will ask from a list of browsers. Or if the links belongs to an app it must show the app in the list too.
Something like this could work
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"));
startActivity(browserIntent);
As #zain posted ago you can use.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
But if you have more then one browser installed in device and want to choose from one of them. Use intent chooser like this
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getResources().getText(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
refer from here
Show browser list when opening a link in android
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.co.in/"));
String title = "Complete Action Using";
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
If you are in a WebView in your App, and on clivking a link there, if the app opens the link in the App Itself, Then possibly u should have overridden this method.
myWebView.setWebViewClient(new WebViewClient()
{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
//view.loadUrl(url);
return false;
}
});
The return of false should ask the user, where to Open the link. With the browsers installed in the mobile

A general Android intent for a dictionary / encyclopedia / etc

Does there exist such a thing, where you send it a string as data, and it knows to open the application with the entry for that string?
Thanks.
if you want to allow user to search something new. Than you can not depend on other applications. This will launch the browser(which is present in all the android devices) with your text as the url so that user can search it using your app.
try this:
String url = "the text you want to search";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
Or
the dictionary must have Broadcast Reciever

Links in Sony Smartwatch 2

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.

Show browser list when opening a link in android

I want to open some links in an external browser. Before opening, I want to display the list of browsers on the device. I did this functionality using Intent.ACTION_VIEW. But as per my app's requirement, I want to display the list of browsers even if there is only one browser application on the device. Does anyone have any idea about this? Thanks.
If you have one browser application , the chooser will not launched , the URL will be loaded on that browser application. If you have two or more browser applications, the android system launch an IntentChooser the show the list of all browser apps installed on the device , so the user can choose his preferred browser to load the URL :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
EDIT :
to create your custom Intent Chooser :
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
// Always use string resources for UI text. This says something like "Share this photo with"
String title = getString(R.string.chooser_title);
// Create and start the chooser
Intent chooser = Intent.createChooser(intent, title);
startActivity(chooser);
refer this
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.maidofknowledge.com"));
Intent chooser = Intent.createChooser(sendIntent, "Choose Your Browser");
if (sendIntent.resolveActivity(getPackageManager()) != null) {
startActivity(chooser);
}
settings>apps>clear default (
this is if you have previously set "use as default app" for chrome
these 2 images are my source:
Message to select browser or select default:
http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-03.jpg
Clear default browser, show intent chooser again:
http://cdn2.ubergizmo.com/wp-content/uploads/2015/02/how-to-default-app-02.jpg

Android - Call default browser with and redirect to a designated url

Hi
I want to write an app to call default browser and redirect to a designated url.
Any suggestion to 1)call the default browser, 2)redirect to a designated url.
Thanks
you just want to launch an ACTION_VIEW intent with the Uri of the webpage as your data element :
Intent httpIntent = new Intent(Intent.ACTION_VIEW);
httpIntent.setData(Uri.parse("http://www.bbc.co.uk"));
startActivity(httpIntent);
To open the default browser use an Intent with the action VIEW. To tell the browser which page to load us the data-part of the Intent.
Example:
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com"));
startActivity(browse);
Since this is a basic task in Android you might want to read some basics about Intents in Android.

Categories

Resources