【问题标题】:ask website visitors to save your website on their homescreen-android要求网站访问者将您的网站保存在他们的主屏幕-android
【发布时间】:2016-03-13 11:38:06
【问题描述】:

是否可以要求网站访问者将您的网站保存在他们的主屏幕上? 安卓

【问题讨论】:

标签: android html


【解决方案1】:

在此处查看此答案,了解如何创建快捷方式:

How to add android bookmark on homescreen from web page?

如果您正在编写 Android 应用,则可以使用这种方法。但是,如果这是一个网站,则此方法将不起作用,因为 Android Intent 系统似乎忽略了网站生成的操作。


您可以使用此代码在主屏幕上创建网页快捷方式。提供必要的信息,如网址、标题等。

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-11-27
    相关资源
    最近更新 更多