Skip to content

Instantly share code, notes, and snippets.

@SemonCat
Created April 15, 2015 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SemonCat/04b51ae8e8d4024c5a20 to your computer and use it in GitHub Desktop.
Save SemonCat/04b51ae8e8d4024c5a20 to your computer and use it in GitHub Desktop.
package com.asus.push.service;
import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import com.asus.push.analytics.zAnalytics;
import com.asus.push.receiver.zParsePushBroadcastReceiver;
import com.parse.ParseAnalytics;
/**
* Created by Ed_Chou on 2015/1/21.
*/
public class ProxyService extends IntentService {
public static final String KEY_ACTION_TYPE = "action_type";
public static final String KEY_ACTION_INTENT = "action_intent";
public static final String KEY_PARSE_INTENT = "parse_intent";
public static final String TYPE_ACTIVITY = "activity";
public static final String TYPE_SERVICE = "service";
public static final String TYPE_BROADCAST = "broadcast";
public ProxyService() {
super("ProxyService");
}
public static final String TAG = ProxyService.class.getName();
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "onHandleIntent");
Bundle extras = intent.getExtras();
Log.d(TAG, "extras:" + extras);
if (extras != null) {
Log.d(TAG, "extras != null");
zAnalytics.Click(this, intent.getStringExtra(zParsePushBroadcastReceiver.KEY_MESSAGE_ID));
if (extras.containsKey(KEY_ACTION_INTENT)) {
Log.d(TAG, "extrasGetActionIntent");
Intent action = extras.getParcelable(KEY_ACTION_INTENT);
Intent parse_intent = extras.getParcelable(KEY_PARSE_INTENT);
ParseAnalytics.trackAppOpenedInBackground(parse_intent);
action.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String type = extras.getString(KEY_ACTION_TYPE, TYPE_ACTIVITY);
if (TextUtils.equals(type, TYPE_SERVICE)) {
Log.d(TAG, "startService");
startService(action);
} else if (TextUtils.equals(type, TYPE_BROADCAST)) {
Log.d(TAG, "sendBroadcast");
sendBroadcast(action);
} else {
Log.d(TAG, "startActivity");
startActivity(action);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment