安卓:有没有一种编程方式来创建在主屏幕上的Web快捷方式 [英] Android: Is there a programming way to create a web shortcut on home screen

查看:387
本文介绍了安卓:有没有一种编程方式来创建在主屏幕上的Web快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知不知道有没有的程序化的方式来创建手机用户的主屏幕上的快捷方式网络?

Do you know is there a programmatical way to create a web shortcut on the phone user's home screen?

我想要做的是:

当手机用户点击一个按钮,我们的Andr​​oid应用程序,该应用程序会然后把一个网站的快捷方式到手机用户的主屏幕上。

When the phone user clicks a button in our Android application, the application will then place a website shortcut onto the phone user's home screen.

推荐答案

首先,您需要一个允许添加到您的manifest.xml

First you'll need to add a permission to your manifest.xml

<uses-permission
            android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>

您将需要建立一个意图查看网页。喜欢的东西...

You'll need to build an intent to view the webpage. Something like...

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.blablaba.com"));

您可以通过创建一个小的测试应用程序,并做startActivity(一)测试此;这应该打开浏览器。一旦验证了上述目的是正确的,你应该在移动到下一个步骤。

You can test this by creating a little test app and doing startActivity(i); This should open the browser. Once you verified that the above intent is correct you should move on to the next step.

现在你需要实际安装的快捷方式。

Now you'll need to actually install the shortcut.

    Intent installer = new Intent();
    installer.putExtra("android.intent.extra.shortcut.INTENT", i);
    installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
    installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
    installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(installer)

也有可能一些主屏幕不接受这一点,但大多数人。所以欣赏。

It's also possible some home screens don't accept this, but most do. So enjoy.

编辑: 图标可以使用被设置为快捷:

Icon can be set to the shortcut using:

installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));

这篇关于安卓:有没有一种编程方式来创建在主屏幕上的Web快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆