首页 > 编程知识 正文

android应用图标,shortcuts下载

时间:2023-05-03 13:17:59 阅读:121063 作者:2858

创建当前活动的快捷方式

私密void添加短路

添加操作

intent shortcut=new intent (com.Android.launcher.action.install _ shortcut );

//shortcut的名称

shortcut.put extra (intent.extra _ shortcut _ name,getstring(r.string.app_name ) );

//不允许重复添加

shortcut.putextra('duplicate ',false );

设置shortcut图标

parcelableicon=intent.shortcuticonresource.from context (this,R.drawable.icon );

shortcut.put extra (intent.extra _ shortcut _ icon _ resource,icon );

//设置用于启动的intent

//使用以下Intent时,会出现快捷方式访问和APP应用程序集合访问打开SplashActivity两次的问题

//解决的关键是添加Action_Main

//intentintent=newintent(this,SplashActivity.class );

componentnamecomp=newcomponentname (this.getpackagename ),this.get package name ) '.' this.getLocalClassName ' )

intent intent=new intent (intent.action _ main ).set component (comp );

intent.setflags (intent.flag _ activity _ reset _ task _ if _ needed );

intent.add flags (intent.flag _ activity _ launched _ from _ history );

intent.add category (intent.category _ launcher;

shortcut.put extra (intent.extra _ shortcut _ intent,intent );

//发送广播让Launcher接收制作shortcut

发送广播(shortcut;

}

}

确定是否创建了快捷方式

首先,必须获得Launcher许可证。 在此,将其理解为系统的Launcher.settings软件包名称。 由于Android碎片化,各机型的Laucher软件包名称可能与官方软件包名称不同,因此可通过以下方法获取

私密性上下文,字符串权限)。

if(permission==null )返回空值;

list packs=context.getpackagemanager ().getinstalledpackages ) packagemanager.get_providers );

if (包!=空) {

for (packageinfopack :包) {

提供商info [ ]提供商=pack.providers;

提供商!=空) {

提供商信息提供商(for )。

if (permission.equals (provider.readpermission ) ) return provider.authority;

if (permission.equals (提供程序. write permission ) ) return提供程序. authority;

}

}

}

}

返回空值;

}

``````

###然后判断是否安装了快捷方式

` ` ` java

专用布尔型isaddedshortcut (

布尔is added=false;

调用活动的获取内容资源器(;

finalcontentresolvercr=get content resolver (;

string authority=getauthorityfrompermission (this.getapplicationcontext )、' com.Android.launcher.permission.re esssssion

//默认' com.android.launcher2.settings ';

finaluricontenturi=uri.parse (' content ://' authority '/favorites? 通告=true ';

cursorc=Cr.query(contenturi,new String[] { 'title ',' iconResource' },' title=?'

、new string [ ] { getstring (r.string.app _ name )、null;

if(c!=null c.getCount ()0) {

is添加=true;

}

返回is添加;

}

注意:将访问权限com.Android.launcher.action.install _ shortcut添加到Manifest文件中

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。