Android AppShortcuts 桌面启动图标长安弹出框 类似支付宝 出现扫一扫 付款

使用到的Android原生框架 AppShortcuts。桌面快捷 按钮

 

 

 有两种方式实现第一中在manifest配置静态方式。

使用:在启动类加入如下meta-adta

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data
        android:name="android.app.shortcuts"
        android:resource="@xml/shortcuts" />
</activity>

在xml文件夹创建shortcuts 文件:

每一个shortcut为弹出框的一个item。最大可加4个(google说是5个)

icon :item图标

shortcutId:item id 不可重复  如果重复只会显示第一个。

shortcutLongLabel: item文本

intent:点击目标intent

         targetClass :目标类路径

         targetPackage:目标应用包名(可以不是自己的应用只要安装了能找到对应类就可以跳转) 

 

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">

    <shortcut
        android:enabled="true"
        android:icon="@mipmap/del"
        android:shortcutDisabledMessage="@string/static_message"
        android:shortcutId="static1"
        android:shortcutLongLabel="@string/static_long_label_1"
        android:shortcutShortLabel="@string/static_short_label_1">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.example.myapplication.StaticTestActivity"
            android:targetPackage="com.example.myapplication" />
    </shortcut>

    <shortcut
        android:enabled="true"
        android:icon="@mipmap/close"
        android:shortcutDisabledMessage="@string/static_message"
        android:shortcutId="static2"
        android:shortcutLongLabel="@string/static_long_label_2"
        android:shortcutShortLabel="@string/static_short_label_2">
        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.example.myapplication.StaticTestActivity"
            android:targetPackage="com.example.myapplication" />
    </shortcut>

</shortcuts>

需要把显示内容设置到string.xml文件。否则报错:属性解析失败

<string name="static_message">asdf</string>
<string name="static_long_label_1">qwe</string>
<string name="static_short_label_1">qwe1</string>
<string name="static_long_label_2">qwe2</string>
<string name="static_short_label_2">qwe3</string>

第二种在代码中动态配置。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android应用中隐藏桌面图标,你可以通过以下步骤实现: 1. 在你的Android项目的AndroidManifest.xml文件中,找到你的启动Activity的声明。通常它是以`<activity>`标签表示的,并且在其中包含一个`<intent-filter>`标签。确保你的启动Activity有`MAIN`和`LAUNCHER`的intent-filter,类似这样: ```xml <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> ``` 2. 在上述`<activity>`标签中添加一个新的属性:`android:enabled="false"`。这将禁用该Activity的启用状态。 ```xml <activity android:name=".MainActivity" android:label="@string/app_name" android:enabled="false"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> ``` 3. 保存并重新构建你的应用程序,并将其安装到设备上。 现在,当你启动应用程序后,应用程序的图标将不再显示在设备的桌面上。然而,你仍然可以通过其他方式启动该应用程序,例如通过应用程序列表或通过其他应用程序的链接。 请注意,这种方法仅仅是隐藏了应用程序的桌面图标,并没有真正地隐藏或保护应用程序的内容。如果用户知道你的应用程序的包名,并且知道如何启动它,他们仍然可以访问你的应用程序。如果你需要更高级的应用程序隐藏和保护功能,你可能需要使用其他技术或库来实现,例如使用设备管理器API或加密应用程序内容。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值