标签:key 服务 dem ide tco tca 添加 文件 .class
当前版本号:v3.0.5
1.下载SDK解压并导入(import module,compile project(‘:PushSDK‘)),里面有demo,用demo的包名去官网添加一个应用,然后替换demo中的manifest文件里面的appkey和message_secret,就可以直接运行。
2.初始化SDK
-
public class App extends Application {
-
-
public PushAgent mPushAgent;
-
-
-
-
-
mPushAgent = PushAgent.getInstance(this);
-
-
mPushAgent.register(new IUmengRegisterCallback() {
-
-
-
public void onSuccess(String deviceToken) {
-
-
Log.e("deviceToken-------",deviceToken);
-
-
-
-
public void onFailure(String s, String s1) {
-
-
-
-
-
mPushAgent.setPushIntentServiceClass(UmengPushIntentService.class);
-
-
-
这样就已经可以测试了。
3.打开指定页面
包名加activity名,com.umeng.demo.SecondActivity
4.自定义参数
自定义一个service去继承UmengMessageService
public class UmengPushIntentService extends UmengMessageService {
-
-
public void onMessage(Context context, Intent intent) {
-
Intent data = new Intent(intent);
-
data.setClass(context, TestActivity.class);
-
-
data.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
context.startActivity(data);
-
-
-
-
在跳转的activity中去接收数据并解析
-
public class TestActivity extends AppCompatActivity {
-
-
public static final String TAG = "TestActivity";
-
-
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_test);
-
-
-
final String message = getIntent().getStringExtra(MESSAGE_BODY);
-
if (TextUtils.isEmpty(message))
-
-
-
-
msg = new UMessage(new JSONObject(message));
-
UTrack.getInstance(this).trackMsgClick(msg);
-
Map<String, String> extra = msg.extra;
-
Log.d(TAG, "message=" + message);
-
Log.d(TAG, "custom=" + msg.custom);
-
Log.d(TAG, "title=" + msg.title);
-
Log.d(TAG, "text=" + msg.text);
-
-
if (null != extra && extra.containsKey("msgType"))
-
dialog = new AlertDialog.Builder(this)
-
-
.setMessage(msg.text+"11111")
-
-
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
-
-
public void onClick(DialogInterface dialog, int which) {
-
-
-
-
-
dialog = new AlertDialog.Builder(this)
-
-
-
-
.setPositiveButton("确认", null)
-
-
-
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
-
-
public void onDismiss(DialogInterface dialog) {
-
-
-
-
-
} catch (JSONException e) {
-
-
-
-
自定义的service需要在application类中调用
mPushAgent.setPushIntentServiceClass(UmengPushIntentService.class);
同时需要在manifest在注册
-
<service android:name=".UmengPushIntentService"
-
android:process=":push"/>
官方文档:http://dev.umeng.com/push/android/integration#4
Android友盟推送
标签:key 服务 dem ide tco tca 添加 文件 .class
原文地址:https://www.cnblogs.com/yelanggu/p/9549540.html