用户第一次拖动widget到桌面上,不用授权提示,直接安装
来源:互联网 发布:四大名捕 知乎 编辑:程序博客网 时间:2024/05/18 10:21
做sp31项目时测试这边提出一个要求,
手机添加小部件时弹出对话框"是否允许launcher3创建小部件并查看其数据",建议去除该对话框
看了两天代码,结果只要加一行代码就能解决问题了。解决方法如下:
在Launcher.java里 函数
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell, int[] span, int[] loc) { if (LauncherLog.DEBUG) { LauncherLog.d(TAG, "addAppWidgetFromDrop: info = " + info + ", container = " + container + ", screenId = " + screenId); } resetAddInfo(); mPendingAddInfo.container = info.container = container; mPendingAddInfo.screenId = info.screenId = screenId; mPendingAddInfo.dropPos = loc; mPendingAddInfo.minSpanX = info.minSpanX; mPendingAddInfo.minSpanY = info.minSpanY; if (cell != null) { mPendingAddInfo.cellX = cell[0]; mPendingAddInfo.cellY = cell[1]; } if (span != null) { mPendingAddInfo.spanX = span[0]; mPendingAddInfo.spanY = span[1]; } AppWidgetHostView hostView = info.boundWidget; int appWidgetId; if (hostView != null) { appWidgetId = hostView.getAppWidgetId(); addAppWidgetImpl(appWidgetId, info, hostView, info.info); } else { // In this case, we either need to start an activity to get permission to bind // the widget, or we need to start an activity to configure the widget, or both. appWidgetId = getAppWidgetHost().allocateAppWidgetId(); Bundle options = info.bindOptions; boolean success = false; mAppWidgetManager.setBindAppWidgetPermission(this.getPackageName(), true); //txk add if (options != null) { success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName, options); } else { success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName); } if (success) { addAppWidgetImpl(appWidgetId, info, null, info.info); } else { /* 当用户第一次添加widget的时候会走到这里,弹出一个提示框让用户授权。为了不让代码走到这里,只要在 * mAppWidgetManager.bindAppWidgetIdIfAllowed(……)之前提前授权就好了。添加一行授权代码 * * mAppWidgetManager.setBindAppWidgetPermission(this.getPackageName(), true); * * 但是需要在Launcher3的AndroidManifest.xml里添加相应权限 * <uses-permission android:name="android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS"/> * 而这个权限是系统级权限,所以还需要把Launcher3改为系统级应用,在AndroidManifest.xml添加 * android:sharedUserId="android.uid.system" 这个标签 * 还需要在Android.mk里 把LOCAL_CERTIFICATE := shared 改为LOCAL_CERTIFICATE := platform */ mPendingAddWidgetInfo = info.info; Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); // TODO: we need to make sure that this accounts for the options bundle. // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options); startActivityForResult(intent, REQUEST_BIND_APPWIDGET); } } }
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.launcher3" android:sharedUserId="android.uid.system" > <uses-sdk android:targetSdkVersion="21" android:minSdkVersion="16"/> ……………… <!-- xuankai.tang add 2015.5.20 start--> <uses-permission android:name="android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS"/> <!-- xuankai.tang add 2015.5.20 end --> ………………</manifest>
0 0
- 用户第一次拖动widget到桌面上,不用授权提示,直接安装
- 相册权限 第一次安装、用户是否授权
- 无法使用程序将widget添加到桌面上
- 直接对用户授权与间接对用户授权
- 在服务里面弹出一个窗口到用户的桌面上
- 更新windows10系统PS无法打开,安装PS软件后无法直接拖动图片到ps里面的解决方案
- 两种方法教你直接将文字写到桌面上。
- Windows图形编程——Hello World(版本2):直接绘制到桌面上
- 显示Dashboard里的widget在桌面上
- 桌面上的最小化提示Tip
- mysql卸载、安装、备份以及用户授权
- 安装MongoDB配置及用户授权
- 将用户中的表授权到另一个用户
- iOS 8.0 之后相册授权直接跳转到设置
- IPA 包不经过APP Store直接发布到网站供用户下载安装
- iOS — IPA 包不经过APP Store直接发布到网站供用户下载安装
- 微信授权登录,提示-2,用户取消
- 2.10-如何使文档自动保存,而不用提示用户?
- leetcode | 3Sum
- Java接口
- 《c++ primer》4 指针和const限定符
- nunit用法
- java中System.getProperty()方法详解
- 用户第一次拖动widget到桌面上,不用授权提示,直接安装
- QT学习(1)Windows环境下的串口编写
- Java Collection框架简略
- 收集android上开源的酷炫的交互动画和视觉效果:Interactive-animation
- vi使用
- ubuntu 12.04安装ffmpeg
- 所有常见排序算法,笔试必看
- Leetcode 33 Search in Rotated Sorted Array
- EasyUI 树形菜单的显示(SpringMVC+Hibernate)