@Override
  protected void onCreate(Bundle savedInstanceState) {
    SDKInitializer.initialize(getApplicationContext());
    super.onCreate(savedInstanceState);

    // 百度推送
    Utils.logStringCache = Utils.getLogText(getApplicationContext());
    Resources resource = this.getResources();
    String pkgName = this.getPackageName();
    // Push: 以apikey的方式登录,一般放在主Activity的onCreate中。
    // 这里把apikey存放于manifest文件中,只是一种存放方式,
    // 您可以用自定义常量等其它方式实现,来替换参数中的Utils.getMetaValue(PushDemoActivity.this,
    // "api_key")
    PushManager.startWork(
        getApplicationContext(),
        PushConstants.LOGIN_TYPE_API_KEY,
        Utils.getMetaValue(this, "api_key"));
    // Push: 如果想基于地理位置推送,可以打开支持地理位置的推送的开关
    // PushManager.enableLbs(getApplicationContext());

    // Push: 设置自定义的通知样式,具体API介绍见用户手册,如果想使用系统默认的可以不加这段代码
    // 请在通知推送界面中,高级设置->通知栏样式->自定义样式,选中并且填写值:1,
    // 与下方代码中 PushManager.setNotificationBuilder(this, 1, cBuilder)中的第二个参数对应
    CustomPushNotificationBuilder cBuilder =
        new CustomPushNotificationBuilder(
            getApplicationContext(),
            resource.getIdentifier("notification_custom_builder", "layout", pkgName),
            resource.getIdentifier("notification_icon", "id", pkgName),
            resource.getIdentifier("notification_title", "id", pkgName),
            resource.getIdentifier("notification_text", "id", pkgName));
    cBuilder.setNotificationFlags(Notification.FLAG_AUTO_CANCEL);
    cBuilder.setNotificationDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    cBuilder.setStatusbarIcon(this.getApplicationInfo().icon);
    cBuilder.setLayoutDrawable(
        resource.getIdentifier("simple_notification_icon", "drawable", pkgName));
    PushManager.setNotificationBuilder(this, 1, cBuilder);

    // ToastUtil.toast(getApplicationContext(), ""+PushConstants.LOGIN_TYPE_API_KEY);
    // Log.e("开始推动",""+ PushConstants.LOGIN_TYPE_API_KEY);

    Log.i(TAG, "=========开始定位=========");
    setContentView(R.layout.indoorsy_home);
    fragmentManager = getSupportFragmentManager(); // 获取FragmentManager实例
    init(); // 初始化页面
  }
Example #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Utils.logStringCache = Utils.getLogText(getApplicationContext());

    Resources resource = this.getResources();
    String pkgName = this.getPackageName();

    setContentView(resource.getIdentifier("main", "layout", pkgName));
    akBtnId = resource.getIdentifier("btn_initAK", "id", pkgName);
    initBtnId = resource.getIdentifier("btn_init", "id", pkgName);
    richBtnId = resource.getIdentifier("btn_rich", "id", pkgName);
    setTagBtnId = resource.getIdentifier("btn_setTags", "id", pkgName);
    delTagBtnId = resource.getIdentifier("btn_delTags", "id", pkgName);
    clearLogBtnId = resource.getIdentifier("btn_clear_log", "id", pkgName);

    initWithApiKey = (Button) findViewById(akBtnId);
    initButton = (Button) findViewById(initBtnId);
    displayRichMedia = (Button) findViewById(richBtnId);
    setTags = (Button) findViewById(setTagBtnId);
    delTags = (Button) findViewById(delTagBtnId);
    clearLog = (Button) findViewById(clearLogBtnId);

    logText = (TextView) findViewById(resource.getIdentifier("text_log", "id", pkgName));
    scrollView = (ScrollView) findViewById(resource.getIdentifier("stroll_text", "id", pkgName));

    initWithApiKey.setOnClickListener(this);
    initButton.setOnClickListener(this);
    setTags.setOnClickListener(this);
    delTags.setOnClickListener(this);
    displayRichMedia.setOnClickListener(this);
    clearLog.setOnClickListener(this);

    // Push: 以apikey的方式登录,一般放在主Activity的onCreate中。
    // 这里把apikey存放于manifest文件中,只是一种存放方式,
    // 您可以用自定义常量等其它方式实现,来替换参数中的Utils.getMetaValue(PushDemoActivity.this, "api_key")
    // 通过share preference实现的绑定标志开关,如果已经成功绑定,就取消这次绑定
    if (!Utils.hasBind(getApplicationContext())) {
      Log.d("YYY", "before start work at " + Calendar.getInstance().getTimeInMillis());
      PushManager.startWork(
          getApplicationContext(),
          PushConstants.LOGIN_TYPE_API_KEY,
          Utils.getMetaValue(PushDemoActivity.this, "api_key"));
      Log.d("YYY", "after start work at " + Calendar.getInstance().getTimeInMillis());
      // Push: 如果想基于地理位置推送,可以打开支持地理位置的推送的开关
      PushManager.enableLbs(getApplicationContext());
      Log.d("YYY", "after enableLbs at " + Calendar.getInstance().getTimeInMillis());
    }

    // Push: 设置自定义的通知样式,具体API介绍见用户手册,如果想使用系统默认的可以不加这段代码
    // 请在通知推送界面中,高级设置->通知栏样式->自定义样式,选中并且填写值:1,
    // 与下方代码中 PushManager.setNotificationBuilder(this, 1, cBuilder)中的第二个参数对应
    CustomPushNotificationBuilder cBuilder =
        new CustomPushNotificationBuilder(
            getApplicationContext(),
            resource.getIdentifier("notification_custom_builder", "layout", pkgName),
            resource.getIdentifier("notification_icon", "id", pkgName),
            resource.getIdentifier("notification_title", "id", pkgName),
            resource.getIdentifier("notification_text", "id", pkgName));
    cBuilder.setNotificationFlags(Notification.FLAG_AUTO_CANCEL);
    cBuilder.setNotificationDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
    cBuilder.setStatusbarIcon(this.getApplicationInfo().icon);
    cBuilder.setLayoutDrawable(
        resource.getIdentifier("simple_notification_icon", "drawable", pkgName));
    PushManager.setNotificationBuilder(this, 1, cBuilder);
  }