如何把网页添加到手机屏幕上,快捷小图标!安卓系统!

如何把网页添加到手机屏幕上,快捷小图标!安卓系统!,第1张

Android应用,创建桌面图标先在注册activity时,需要添加一个action为android.intent.action.CREATE_SHOERTCUT的intentFilter。

1.创建图标代码如下:

<activity android:name=".MainActivity">

<intent-filter>

<action android:name="android.intent.action.CREATE_SHORTCUT"/>

</intent-filter>

</activity>

2.接下来就是就是设置快捷方式的图标、名称、事件等属性。

public void createShortCut(){

Intent addShortCut

if(getIntent().getAction().equals(Intent.ACTION_CREATE_SHORTCUT)){//判断是否需要添加快捷方式

addShortCut = new Intent()

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME , "快捷方式")//快捷方式的名称

Parcelable icon = ShortcutIconResource.fromContext(this, R.drawable.icon)//显示的图片

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon)//快捷方式激活的activity,需要执行的intent,自己定义

addShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent())

setResult(RESULT_OK, addShortCut)//OK,生成

}else{//取消

setResult(RESULT_CANCELED)

}

}

3.向桌面再增加一个图标

Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT") //快捷方式的名称

shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name))

shortcut.putExtra("duplicate", false)//不允许重复创建

//指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer

//注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序

// ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName())

// shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp))

shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this,WXEntryActivity.class))//快捷方式的图标

ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher)

shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes)

sendBroadcast(shortcut)

1、在浏览器中,打开一个网站。

2、打开网站后,点击菜单键,点击书签,点击添加书签,确定即可加入书签。

3、长按需要添加在手机桌面上的网站书签。

4、选择向主屏幕添加快捷方式,即可成功将网页放在手机桌面。

5、将网页保存为文件放入手机中,在桌面直接添加该网页网址的快捷方式即可。此种情况可以在没有网络链接时,离线打开观看网页。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11725027.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-18
下一篇 2023-05-18

发表评论

登录后才能评论

评论列表(0条)

保存