安卓集成第三方--用androidStudio集成极光推送。

本文详细介绍了如何在Android Studio上使用依赖注入的方式集成极光推送服务。从添加依赖、配置应用信息、创建自定义广播接收器到实现消息接收等功能进行了全面讲解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在androidStudio上利用依赖注入集成的极光推送的步骤1.新建一个android工程,打开build.gradle(Module:app)添加jpush依赖:compile 'cn.jiguang:jpush:2.1.8'然后修改以下代码: android { compileSdkVersion 23 buildToolsVersion "24.0.2" defaultConfig { applicationId "com.example.administrator.android_school_system" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName "1.0" ndk { //选择要添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'armeabi-v8a' // 还可以添加 'x86', 'x86_64', 'mips', 'mips64' } manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "454554545464646555", //JPush上注册的包名对应的appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. ] } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }2.创建一个MyApplication继承自Application,把mainfast中的Application改成MyApplication。在MyApplication的oncreate方法中初始化极光推送//设置极光推送的调试模式 JPushInterface.setDebugMode(true);//初始化极光推送JPushInterface.init(this);3.自己写个BroadCastReceiver的类,如下: public class JpushReceiver extends BroadcastReceiver { private static final String TAG = "MyReceiver"; private NotificationManager nm; private Context _context; @Override public void onReceive(Context context, Intent intent) { this._context = context; if (null == nm) { nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } Bundle bundle = intent.getExtras(); Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + bundle); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { Log.d(TAG, "JPush用户注册成功"); } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "接受到推送下来的自定义消息"+bundle.getString(JPushInterface.EXTRA_MESSAGE)); // 把消息取出来,然后打印 String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); Log.d(TAG, "接受到推送下来的自定义消息"+message); } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { Log.d(TAG, "接受到推送下来的通知"); receivingNotification(context,bundle); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { Log.d(TAG, "用户点击打开了通知"); } else { Log.d(TAG, "Unhandled intent - " + intent.getAction()); } } private void receivingNotification(Context context, Bundle bundle){ String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE); Log.d(TAG, " title : " + title); String message = bundle.getString(JPushInterface.EXTRA_ALERT); Log.d(TAG, "message : " + message); String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); Log.d(TAG, "extras : " + extras); }}然后启动应用就可以在极光开发者平台上发信息测试了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值