package com.withiter.quhao.activity; import java.io.IOException; import android.annotation.SuppressLint; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources.NotFoundException; import android.graphics.Point; import android.os.Bundle; import android.view.Display; import cn.jpush.android.api.InstrumentedActivity; import com.withiter.quhao.util.QuhaoLog; import com.withiter.quhao.util.tool.PhoneTool; import com.withiter.quhao.util.tool.QuhaoConstant; public abstract class QuhaoActivity extends InstrumentedActivity { private final static String TAG = QuhaoActivity.class.getName(); private static boolean inited = false; // for receive customer msg from jpush server private JPushReceiver mMessageReceiver; // public static final String MESSAGE_RECEIVED_ACTION = "com.withiter.quhao.MESSAGE_RECEIVED_ACTION"; public static final String KEY_TITLE = "title"; public static final String KEY_MESSAGE = "message"; public static final String KEY_EXTRAS = "extras"; public void registerMessageReceiver() { mMessageReceiver = new JPushReceiver(); IntentFilter filter = new IntentFilter(); filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY); // filter.addAction(MESSAGE_RECEIVED_ACTION); registerReceiver(mMessageReceiver, filter); } /* * (non-Javadoc) * * @see android.app.Activity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle savedInstanceState) { try { super.onCreate(savedInstanceState); registerMessageReceiver(); QuhaoLog.i(TAG, "QuhaoActivity onCreate invoked"); QuhaoLog.i(TAG, "QuhaoActivity already inited : " + inited); if (!inited) { initConfig(); inited = true; } } catch (NotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } @SuppressLint("NewApi") private void initConfig() throws IOException { // Get the value of test from AndroidManifest.xml try { ApplicationInfo appInfo = this.getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); boolean msg = appInfo.metaData.getBoolean("test"); QuhaoConstant.test = msg; QuhaoLog.i(TAG, "current deployment is test mode : " + msg); } catch (NameNotFoundException e) { e.printStackTrace(); } // Get the screen size Display display = getWindowManager().getDefaultDisplay(); int currentapiVersion = android.os.Build.VERSION.SDK_INT; Point size = new Point(); int width = 0; int height = 0; if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { // Do something for API 17 only (4.2) // getRealSize() display.getRealSize(size); width = size.x; height = size.y; } else if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) { // Do something for API 13 and above , but below API 17 (API 17 will // trigger the above block // getSize() display.getSize(size); width = size.x; height = size.y; } else { // do something for phones running an SDK before Android 3.2 (API // 13) // getWidth(), getHeight() width = display.getWidth(); height = display.getHeight(); } PhoneTool.setScreenWidth(width); PhoneTool.setScreenHeight(height); QuhaoLog.i(TAG, "device's screen width is: " + width); QuhaoLog.i(TAG, "device's screen height is: " + height); } /* * (non-Javadoc) * * @see android.app.Activity#onPause() */ @Override protected void onPause() { super.onPause(); } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(mMessageReceiver); } }