关于重新系统下载管理器中使用枚举出现的问题
2017-01-11 17:22
387 查看
最近在项目上遇到一个很特别的问题,当我们把测试通过sdk提供给第三方接入以后出现的问题。
他们的sdk通过代理的方式来调用我们sdk里边的services,provider,broadcaset。
具体调用方式是这样:
1、他们创建自己的service,provider,broadcast相关的类。然后实现里边必要的方法,在必要的方法中通过new 一个我们相应的service等的类来调用我们的方法
2、在清单文件中注册他们自己的service,provider,broadcast
3、然后通过隐式启动实现,代理service,provider,broadcast的实现。
具体代码:
service:
provider :
broadcast:
还有一个代理类:
在清单文件的注册:
这样就实现了不需要注册我们的Service或者provider等的组件,注册他们的就可以。
现在说下另外一个问题就是,关于枚举的,如果不是十分了解的话,可以看下这个地址:http://blog.csdn.net/ucxiii/article/details/48708455
因为枚举里边的一个函数 values()
这个方法可以返回当前枚举的类的一个数组。
这个方法是在编译器编译以后插入进去的,默认是没有的,如果打包平台或者打包工具没有对枚举的类编译以及插入values()函数
那么在使用这个函数的时候,返回值是null,会导致很多问题。
现在使用热修复。或者动态加载的应用越来越多,也需要关注这个问题。
如果有人在使用代理有问题,可以留言。
下边是只供参考的Demo:http://download.csdn.net/detail/u012808234/9735043
他们的sdk通过代理的方式来调用我们sdk里边的services,provider,broadcaset。
具体调用方式是这样:
1、他们创建自己的service,provider,broadcast相关的类。然后实现里边必要的方法,在必要的方法中通过new 一个我们相应的service等的类来调用我们的方法
2、在清单文件中注册他们自己的service,provider,broadcast
3、然后通过隐式启动实现,代理service,provider,broadcast的实现。
具体代码:
service:
package com.baidu.tbadk.plugins.gameCenter; import android.app.Service; import android.content.Intent; import android.content.res.Configuration; import android.os.IBinder; import com.duoku.platform.download.DownloadService; public class GameCenterDownloadService extends Service { @Override public IBinder onBind(Intent intent) { if (GameCenterPlugin.getDownloadService() != null) { return GameCenterPlugin.getDownloadService().onBind(intent); } return null; } @Override public void onCreate() { super.onCreate(); Service proxyProvider = this; GameCenterPlugin.setDownloadService(new DownloadService(proxyProvider)); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onCreate(); } } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onStart(intent, startId); } } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (GameCenterPlugin.getDownloadService() != null) { return GameCenterPlugin.getDownloadService().onStartCommand(intent, flags, startId); } return super.onStartCommand(intent, flags, startId); } @Override public void onRebind(Intent intent) { super.onRebind(intent); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onRebind(intent); } } @Override public boolean onUnbind(Intent intent) { if (GameCenterPlugin.getDownloadService() != null) { return GameCenterPlugin.getDownloadService().onUnbind(intent); } return super.onUnbind(intent); } @Override public void onDestroy() { super.onDestroy(); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onDestroy(); } } @Override public void onLowMemory() { super.onLowMemory(); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onLowMemory(); } } @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (GameCenterPlugin.getDownloadService() != null) { GameCenterPlugin.getDownloadService().onConfigurationChanged(newConfig); } } }
provider :
package com.baidu.tbadk.plugins.gameCenter; import android.content.ContentProvider; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; import com.duoku.platform.download.DownloadProvider; public class GameCenterDownloadProvider extends ContentProvider { private boolean isPluginSetted = false; @Override public boolean onCreate() { return false; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { setPlugin(); if (GameCenterPlugin.getDownloadProvider() != null) { return GameCenterPlugin.getDownloadProvider().query(uri, projection, selection, selectionArgs, sortOrder); } return null; } @Override public String getType(Uri uri) { setPlugin(); if (GameCenterPlugin.getDownloadProvider() != null) { return GameCenterPlugin.getDownloadProvider().getType(uri); } return null; } @Override public Uri insert(Uri uri, ContentValues values) { setPlugin(); if (GameCenterPlugin.getDownloadProvider() != null) { return GameCenterPlugin.getDownloadProvider().insert(uri, values); } return null; } @Override public int delete(Uri uri, String selection, String[] selectionArgs) { setPlugin(); if (GameCenterPlugin.getDownloadProvider() != null) { return GameCenterPlugin.getDownloadProvider().delete(uri, selection, selectionArgs); } return 0; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { setPlugin(); if (GameCenterPlugin.getDownloadProvider() != null) { return GameCenterPlugin.getDownloadProvider().update(uri, values, selection, selectionArgs); } return 0; } private void setPlugin() { if (!isPluginSetted) { ContentProvider proxyProvider = this; GameCenterPlugin.setDownloadProvider(new DownloadProvider(proxyProvider)); if (GameCenterPlugin.getDownloadProvider() != null) { GameCenterPlugin.getDownloadProvider().onCreate(); isPluginSetted = true; } } } }
broadcast:
package com.baidu.tbadk.plugins.gameCenter; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class GameCenterDownloadReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (GameCenterPlugin.getDownloadReceiver() != null) { GameCenterPlugin.getDownloadReceiver().onReceive(context, intent); } } }
还有一个代理类:
package com.baidu.tbadk.plugins.gameCenter; import android.app.Service; import android.content.BroadcastReceiver; import android.content.ContentProvider; /** * Created by zhangmingzhe01 on 16/12/29. */ public class GameCenterPlugin { private static Service mDownloadService; private static ContentProvider mDownloadProvider; private static BroadcastReceiver mDownloadReceiver; private static BroadcastReceiver mAppMonitorReceiver; public static Service getDownloadService() { return mDownloadService; } public static void setDownloadService(Service downloadService) { mDownloadService = downloadService; } public static ContentProvider getDownloadProvider() { return mDownloadProvider; } public static void setDownloadProvider(ContentProvider downloadProvider) { mDownloadProvider = downloadProvider; } public static BroadcastReceiver getDownloadReceiver() { return mDownloadReceiver; } public static void setDownloadReceiver(BroadcastReceiver downloadReceiver) { mDownloadReceiver = downloadReceiver; } public static BroadcastReceiver getAppMonitorReceiver() { return mAppMonitorReceiver; } public static void setAppMonitorReceiver(BroadcastReceiver appMonitorReceiver) { mAppMonitorReceiver = appMonitorReceiver; } }
在清单文件的注册:
<!-- 游戏下载service --> <service android:name="com.baidu.tbadk.plugins.gameCenter.GameCenterDownloadService"> <intent-filter> <action android:name="com.baidu.tieba.gameCenter.DownloadService"/> </intent-filter> </service> <!-- 监听安装完成以后更新数据库中状态 --> <receiver android:name="com.baidu.tbadk.plugins.gameCenter.GameCenterAppMonitorReceiver"> <intent-filter> <action android:name="android.intent.action.PACKAGE_ADDED"/> <action android:name="android.intent.action.PACKAGE_REMOVED"/> <action android:name="android.intent.action.PACKAGE_REPLACED"/> <action android:name="android.intent.action.PACKAGE_CHANGED"/> <data android:scheme="package"/> </intent-filter> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_MOUNTED"/> <action android:name="android.intent.action.MEDIA_UNMOUNTED"/> <data android:scheme="file"/> </intent-filter> </receiver> <receiver android:name="com.baidu.tbadk.plugins.gameCenter.GameCenterDownloadReceiver" android:exported="false"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> </intent-filter> <intent-filter> <action android:name="android.intent.action.MEDIA_MOUNTED"/> <data android:scheme="file"/> </intent-filter> </receiver> <!-- 需修改android:authorities="packagename"替换packagename为应用包名, 如:android:authorities="com.baidu.test" --> <provider android:name="com.baidu.tbadk.plugins.gameCenter.GameCenterDownloadProvider" android:authorities="com.example.demo" android:exported="false"/>
这样就实现了不需要注册我们的Service或者provider等的组件,注册他们的就可以。
现在说下另外一个问题就是,关于枚举的,如果不是十分了解的话,可以看下这个地址:http://blog.csdn.net/ucxiii/article/details/48708455
因为枚举里边的一个函数 values()
这个方法可以返回当前枚举的类的一个数组。
这个方法是在编译器编译以后插入进去的,默认是没有的,如果打包平台或者打包工具没有对枚举的类编译以及插入values()函数
那么在使用这个函数的时候,返回值是null,会导致很多问题。
现在使用热修复。或者动态加载的应用越来越多,也需要关注这个问题。
如果有人在使用代理有问题,可以留言。
下边是只供参考的Demo:http://download.csdn.net/detail/u012808234/9735043
相关文章推荐
- 使用Sysprep重新封装出现问题的XP系统
- 关于使用 session_start 出现的 Warning: session_start(): Cannot send sessioncache limiter - 问题的解决
- Oracle出现了问题“无法使用系统回滚段”并解决
- 关于Linux 下 使用JAVA出现中文小框框的问题
- win7下,使用锐捷出现“未能找到网卡或系统还未完成网卡初始化操作"问题解决
- 关于同 Struts 2.0.6 配合使用 Spring 出现的问题
- 关于使用VS.Net2003调试器出现的问题及相关解决方法
- 关于使用 jquery Validate 使用出现的问题
- 关于使用FCKedioor中出现的问题
- Ajax小系统使用效果,以及出现的问题(待朋友帮忙解答)
- 关于Vs 2005 中出现编译通过,但运行时出现“未使用调试信息生成二进制文件”的问题
- 关于使用VS.Net2003调试器出现的问题及相关解决方法
- 关于httpcontext实际使用时出现的一个问题
- 关于RCP中使用系统resource navigator图标和项目名称不显示的问题
- 在非英文区域系统中使用英文版Expression Encoder命令行可能出现的问题
- 关于httpcontext实际使用时出现的一个问题
- 关于HP-UX中出现无法使用历史命令的问题的解决方案
- 关于在Log4j中使用JDBCAppender时出现死循环的问题
- 关于使用showModalDialog传递参数出现中文乱码问题
- 关于WinCE下MC55使用Unimodem进行GPRS拨号,拨上出现断开连接,检查波特率的问题的另一种可能情况