極光推送:
1、使用第三方推送第一步新建賬號這個是肯定的
2、創建應用將包名確定(同時會生成appkeyss)
3、注意libs裏邊必須有兩個一定要存在的東西,一個是armeabi文件夾一個是jpush-sdk-release1.6.3.jar包,這兩個東西都在官方demo中可以找到,直接複製就可以
4、下載三分鐘快速demo
5、運行測試如果提示[PushService] Login succeed! registrationID=050ab696fa9 證明環境搭建配置成功,可以從官方推送消息並接受了
-------------------
以上是使用官方的配置環境
下面是自己的應用,主體來說都一樣,按照官方的架構搭好基本的架構
1、創建自己的應用(注意包名是網站創建好的包名這個是不能變的,更改mainfest.xml 注意尤其包名,appkey,建議直接從官方demo拷貝,然後修改 )
2、在MainActivity中需要初始化推送服務並設置debugMode模式
JPushInterface.init(this);
JPushInterface.setDebugMode(true);
(官方會提示加上統計信息這個可有可無,無所謂,看自己情況)
3、創建成功後接受推送的消息需要自己重寫一個MyReceiver 來 extends BroadcastReceiver
這個直接貼上代碼---隨便寫了點可以運行就沒在考慮,深層次的大家後期可以共同討論討論
MainActivity
---------------------------------------------------
package com.qiao.jpush;
import cn.jpush.android.api.JPushInterface;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JPushInterface.init(this);
JPushInterface.setDebugMode(true);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
JPushInterface.onResume(this);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
JPushInterface.onPause(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
}
----------------------------------------------------
package com.qiao.jpush;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import cn.jpush.android.api.JPushInterface;
public class MyReceiver extends BroadcastReceiver {
private static final String TAG = "MyReceiver";
private String message ="";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "==" + intent.getAction());
Bundle bundle = intent.getExtras();
if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
Log.i(TAG, "=="+message+"message輸出了");
}else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Intent i = new Intent(context,TextActivity.class); //自定義打開的界面
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
// Activity 被打開,上報服務器統計。
JPushInterface.reportNotificationOpened(context, bundle.getString(JPushInterface.EXTRA_MSG_ID));
}
}
}