极光推送使用

来源:互联网 发布:观察者手机控制软件 编辑:程序博客网 时间:2024/05/17 04:55
1,极光推送SDK下载:http://docs.jiguang.cn/resources/


2,加压下载的压缩包,将libs中的文件夹或文件放入项目中libs,把res下对应资源一一放入项目中对应名称文件夹。


3,根据你使用的开发工具的不同,打开对应的manifest文件进行对照更改。


4,注意在manifest中的application标签中添加属性name并赋值下面class的名称:
import cn.jpush.android.api.JPushInterface;
import android.app.Application;


public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
//设置极光推送的debug
JPushInterface.setDebugMode(true);
//初始化极光推送
JPushInterface.init(this);
}


}


5,在MainActivity中添加统计代码:


@Override
protected void onResume() {
super.onResume();
JPushInterface.onResume(this);
}

@Override
protected void onPause() {
super.onPause();
JPushInterface.onPause(this);
}


*6,如果使用的是AndroidStudio:


请在src---build.gradle下添加以下代码帮助加载so文件:
sourceSets.main{
jniLibs.srcDirs=['libs']
}


7,建立个人MyReceiver用于接收处理msg或notification:


public class MyReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(JPushInterface.ACTION_MESSAGE_RECEIVED)){
Bundle b= intent.getExtras();
String title = b.getString(JPushInterface.EXTRA_TITLE);
String content = b.getString(JPushInterface.EXTRA_MESSAGE);

Toast.makeText(context, "title========="+title+"............msg======="+content, 1).show();
}


}


}


0 0