【发布时间】:2017-03-20 19:53:05
【问题描述】:
我正在尝试解决我正在开发的 Android 应用程序上的一些安全审查项目,并且我正在查看一些与快捷方式相关的“高严重性”项目。
安全审查纯粹是一项静态代码分析工作,报告突出显示的许多项目都是红鲱鱼。我怀疑这些也是,但我正在寻找第二个意见。
已标记的代码/配置区域与设置快捷方式有关:
Intent shortcutIntent = new Intent(context, MyShortcutActivity.class);
shortcutIntent.setAction(Intent.ACTION_DEFAULT);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "My shortcut");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, getShortCutIconResource()));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
addIntent.putExtra("duplicate", false);
this.context.sendBroadcast(addIntent);
安全报告抱怨我创建这些意图时没有权限。但它们是预期由 Android 操作系统调用的意图——操作系统创建快捷方式,如果单击快捷方式,操作系统将启动 MyShortcutActivity。所以我觉得没有任何适用的特殊许可。
报告还标记了 MyShortcutActivity 的定义:
<activity
android:name=".MyShortcutActivity"
...
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
再次抱怨它缺乏许可。但是由于它可以通过快捷方式启动,所以我并没有真正看到适用的权限。
有什么建议吗?
更新:所以我的清单中已经有了 INSTALL_SHORTCUT 权限。根据答案,在这里,我更改了上面的代码,如下所示:
this.context.sendBroadcast(addIntent, Manifest.permission.INSTALL_SHORTCUT);
但这似乎不起作用。
【问题讨论】:
-
谷歌的easypermission非常推荐github.com/googlesamples/easypermissions
标签: android android-permissions android-security android-shortcut