在androidStudio上利用依赖注入集成极光推送的步骤。
来源:互联网 发布:淘宝文具店怎么推广 编辑:程序博客网 时间:2024/06/18 12:44
在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);
}
}
然后启动应用就可以在极光开发者平台上发信息测试了。
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);
}
}
然后启动应用就可以在极光开发者平台上发信息测试了。
0 0
- 在androidStudio上利用依赖注入集成极光推送的步骤。
- 极光推送的集成步骤
- AndroidStudio集成极光推送
- AndroidStudio集成极光推送
- 极光推送的基本集成步骤
- 集成极光推送的几个步骤
- AndroidStudio集成极光推送SDK
- 极光推送集成步骤详解
- 极光推送SDK集成步骤
- 极光推送的集成
- 极光推送的集成
- 极光推送的集成
- 极光推送的集成
- 极光推送的步骤
- 极光推送集成及注意事项(AndroidStudio)
- AndroidStudio 集成极光推送(带源码)
- 极光推送集成步骤及注意事项
- Android 极光推送的集成
- ios怎么在cell上添加倒计时
- Android Studio打包全攻略---从入门到精通
- zookeeper 深入
- 数据库表锁定、解锁
- nRF52832 Power
- 在androidStudio上利用依赖注入集成极光推送的步骤。
- MySQL存储引擎--MyISAM与InnoDB区别
- javax.crypto.BadPaddingException: Blocktype mismatch: 0 RSA加密,Android到服务器解密报错
- Delphi中易混淆的概念 Owner, Parent, Self, Sender, Clientheight, Height
- Solr分析器、分词器、过滤器(2)
- centos7 安装配置 cacti
- 神经网络、深度学习创新点的思考
- 在使用Github下载的demo时出现问题
- PHP中的命名空间