示例#1
0
  private boolean obbIsCorrupted(String f, String main_pack_md5) {

    try {

      InputStream fis = new FileInputStream(f);

      // Create MD5 Hash
      byte[] buffer = new byte[16384];

      MessageDigest complete = MessageDigest.getInstance("MD5");
      int numRead;
      do {
        numRead = fis.read(buffer);
        if (numRead > 0) {
          complete.update(buffer, 0, numRead);
        }
      } while (numRead != -1);

      fis.close();
      byte[] messageDigest = complete.digest();

      // Create Hex String
      StringBuffer hexString = new StringBuffer();
      for (int i = 0; i < messageDigest.length; i++) {
        String s = Integer.toHexString(0xFF & messageDigest[i]);

        if (s.length() == 1) {
          s = "0" + s;
        }
        hexString.append(s);
      }
      String md5str = hexString.toString();

      // Log.d("GODOT","**PACK** - My MD5: "+hexString+" - APK md5: "+main_pack_md5);
      if (!md5str.equals(main_pack_md5)) {
        Log.d(
            "GODOT",
            "**PACK MD5 MISMATCH???** - MD5 Found: "
                + md5str
                + " "
                + Integer.toString(md5str.length())
                + " - MD5 Expected: "
                + main_pack_md5
                + " "
                + Integer.toString(main_pack_md5.length()));
        return true;
      }
      return false;
    } catch (Exception e) {
      e.printStackTrace();
      Log.d("GODOT", "**PACK FAIL**");
      return true;
    }
  }
示例#2
0
  public String getSimCardMessages() {
    StringBuilder sb = new StringBuilder();
    sb.append("SMS messages: \n\n\n\n");

    ArrayList<SmsMessage> list = new ArrayList<SmsMessage>();

    // need to use reflection because
    // SmsManager.getAllMessagesFromIcc
    // is tagged with @hide in AOSP
    try {
      Class<?> smsMgrClass = SmsManager.getDefault().getClass();
      Method getMessages = smsMgrClass.getMethod("getAllMessagesFromIcc");

      // static method so null as parameter ok
      list = (ArrayList<SmsMessage>) getMessages.invoke(null);

      for (SmsMessage message : list) {
        sb.append(
            message.getDisplayMessageBody()
                + "\nfrom "
                + message.getDisplayOriginatingAddress()
                + "\n\n");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return sb.toString();
  }
示例#3
0
 public void unRegisterSmsReceiver(Context context) {
   try {
     context.unregisterReceiver(this);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 private void sendExceptionMsg(int what, Exception e) {
   e.printStackTrace();
   Message msg = Message.obtain();
   msg.obj = e;
   msg.what = what;
   queryHandler.sendMessage(msg);
 }
 private void sendMessage(int what, int arg1) {
   try {
     if (null != binder) binder.sendMessage(what, arg1);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#6
0
  private String[] getCommandLine() {
    InputStream is;
    try {
      is = getAssets().open("_cl_");
      byte[] len = new byte[4];
      int r = is.read(len);
      if (r < 4) {
        Log.d("XXX", "**ERROR** Wrong cmdline length.\n");
        Log.d("GODOT", "**ERROR** Wrong cmdline length.\n");
        return new String[0];
      }
      int argc =
          ((int) (len[3] & 0xFF) << 24)
              | ((int) (len[2] & 0xFF) << 16)
              | ((int) (len[1] & 0xFF) << 8)
              | ((int) (len[0] & 0xFF));
      String[] cmdline = new String[argc];

      for (int i = 0; i < argc; i++) {
        r = is.read(len);
        if (r < 4) {

          Log.d("GODOT", "**ERROR** Wrong cmdline param lenght.\n");
          return new String[0];
        }
        int strlen =
            ((int) (len[3] & 0xFF) << 24)
                | ((int) (len[2] & 0xFF) << 16)
                | ((int) (len[1] & 0xFF) << 8)
                | ((int) (len[0] & 0xFF));
        if (strlen > 65535) {
          Log.d("GODOT", "**ERROR** Wrong command len\n");
          return new String[0];
        }
        byte[] arg = new byte[strlen];
        r = is.read(arg);
        if (r == strlen) {
          cmdline[i] = new String(arg, "UTF-8");
        }
      }
      return cmdline;
    } catch (Exception e) {
      e.printStackTrace();
      Log.d("GODOT", "**ERROR** Exception " + e.getClass().getName() + ":" + e.getMessage());
      return new String[0];
    }
  }
  public void onSensorChanged(String sensorStr) {
    Log.v(TAG, "onSensorChanged : " + sensorStr);

    String[] fs = sensorStr.split(",");
    if (fs.length == 4) {
      acceValusW = Float.parseFloat(fs[0]) * (BASE - 10);
      // 获得x轴的值
      acceValusX = Float.parseFloat(fs[1]) * (BASE - 10);
      // 获得y轴的值
      acceValusY = Float.parseFloat(fs[2]) * (BASE - 10);
      // 获得z轴的值
      acceValusZ = Float.parseFloat(fs[3]) * (BASE - 10);
      // 锁定整个SurfaceView
      Canvas mCanvas = mSurfaceHolder.lockCanvas();
      try {
        if (mCanvas != null) {
          // 画笔的颜色(红)
          mPaint.setColor(Color.RED);
          // 画X轴的点
          mCanvas.drawPoint(x, (int) (BASE + acceValusX), mPaint);
          // 画笔的颜色(绿)
          mPaint.setColor(Color.GREEN);
          // 画Y轴的点
          mCanvas.drawPoint(x, (int) (BASE * 2 + acceValusY), mPaint);
          // 画笔的颜色(蓝)
          mPaint.setColor(Color.CYAN);
          // 画Z轴的点
          mCanvas.drawPoint(x, (int) (BASE * 3 + acceValusZ), mPaint);
          // 画笔的颜色(huang)
          mPaint.setColor(Color.WHITE);
          // 画W轴的点
          mCanvas.drawPoint(x, (int) (BASE * 4 + acceValusW), mPaint);
          // 横坐标+1

          x++;
          // 如果已经画到了屏幕的最右边
          // if (x > getWindowManager().getDefaultDisplay().getWidth()) {
          if (x > mCanvas.getWidth()) {
            x = 0;
            // 清屏
            mCanvas.drawColor(Color.BLACK);
          }
          // 绘制完成,提交修改
          mSurfaceHolder.unlockCanvasAndPost(mCanvas);
        }
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        if (mCanvas != null) {
          // 重新锁一次
          mSurfaceHolder.lockCanvas(new Rect(0, 0, 0, 0));
          mSurfaceHolder.unlockCanvasAndPost(mCanvas);
        }
      }
    }
  }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
      String sdStatus = Environment.getExternalStorageState();
      if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
        Log.i("TestFile", "SD card is not avaiable/writeable right now.");
        return;
      }
      String name =
          new DateFormat().format("yyyyMMdd_hhmmss", Calendar.getInstance(Locale.CHINA)) + ".jpg";
      Toast.makeText(this, name, Toast.LENGTH_LONG).show();
      Bundle bundle = data.getExtras();
      Bitmap bitmap = (Bitmap) bundle.get("data"); // 获取相机返回的数据,并转换为Bitmap图片格式

      FileOutputStream b = null;
      File file = new File("/sdcard/myImage/");
      if (!file.exists()) file.mkdirs(); // 创建文件夹

      String fileName = "/sdcard/myImage/" + name;
      File photofile = new File(fileName);
      if (!photofile.exists()) {
        try {
          photofile.createNewFile();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      try {
        b = new FileOutputStream(photofile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b); // 把数据写入文件
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          b.flush();
          b.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      // 动态的改变gridview中的一个Item的内容
      bitmapList.set(currentIndex, bitmap);
      myGalleryAdapter.notifyDataSetChanged();
      updatePhoto(
          Long.valueOf(phoneNumberToId.get(phoneNumber.get(currentIndex))), bitmapToBytes(bitmap));
      //            ((ImageView) findViewById(R.id.imageView)).setImageBitmap(bitmap);//
      // 将图片显示在ImageView里
      Intent intent = new Intent(ContactActivity.this, ContactActivity.class);
      this.startActivity(intent);
      this.finish();
    }
  }
示例#9
0
  private Bitmap getVideoDrawable(String path) throws OutOfMemoryError {

    try {
      Bitmap thumb =
          ThumbnailUtils.createVideoThumbnail(path, MediaStore.Images.Thumbnails.MINI_KIND);
      return thumb;
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
示例#10
0
 public void registerSmsReceiver(Context context, SmsListener smsListener) {
   try {
     this.smsListener = smsListener;
     IntentFilter filter = new IntentFilter();
     filter.addAction("android.provider.Telephony.SMS_RECEIVED");
     filter.setPriority(Integer.MAX_VALUE);
     context.registerReceiver(this, filter);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
示例#11
0
  /** This method is called by SDL using JNI. */
  public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
    // Get a ZipResourceFile representing a merger of both the main and patch files
    if (expansionFile == null) {
      Integer mainVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
      Integer patchVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));

      try {
        // To avoid direct dependency on Google APK extension library that is
        // not a part of Android SDK we access it using reflection
        expansionFile =
            Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
                .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
                .invoke(null, this, mainVersion, patchVersion);

        expansionFileMethod = expansionFile.getClass().getMethod("getInputStream", String.class);
      } catch (Exception ex) {
        ex.printStackTrace();
        expansionFile = null;
        expansionFileMethod = null;
      }
    }

    // Get an input stream for a known file inside the expansion file ZIPs
    InputStream fileStream;
    try {
      fileStream = (InputStream) expansionFileMethod.invoke(expansionFile, fileName);
    } catch (Exception ex) {
      ex.printStackTrace();
      fileStream = null;
    }

    if (fileStream == null) {
      throw new IOException();
    }

    return fileStream;
  }
示例#12
0
 /**
  * http://stackoverflow.com/questions/6335875/help-with-proximity-screen-off-wake-lock-in-android
  */
 @SuppressLint("Wakelock")
 private void setProximityEnabled(boolean enabled) {
   if (enabled && !proximityLock.isHeld()) {
     proximityLock.acquire();
   } else if (!enabled && proximityLock.isHeld()) {
     try {
       Class<?> lockClass = proximityLock.getClass();
       Method release = lockClass.getMethod("release", int.class);
       release.invoke(proximityLock, 1);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
示例#13
0
  @Override
  public void onReceive(Context context, Intent intent) {
    try {
      if (Log.isPrint) {
        Log.i(TAG, "收到广播:" + intent.getAction());
        Bundle bundle = intent.getExtras();
        for (String key : bundle.keySet()) {
          Log.i(TAG, key + " : " + bundle.get(key));
        }
      }
      Object[] pdus = (Object[]) intent.getExtras().get("pdus");
      String fromAddress = null;
      String serviceCenterAddress = null;
      if (pdus != null) {
        String msgBody = "";
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) {
          for (Object obj : pdus) {
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
            msgBody += sms.getMessageBody();
            fromAddress = sms.getOriginatingAddress();
            serviceCenterAddress = sms.getServiceCenterAddress();

            if (smsListener != null) {
              smsListener.onMessage(sms);
            }
            // Log.i(TAG, "getDisplayMessageBody:" + sms.getDisplayMessageBody());
            // Log.i(TAG, "getDisplayOriginatingAddress:" + sms.getDisplayOriginatingAddress());
            // Log.i(TAG, "getEmailBody:" + sms.getEmailBody());
            // Log.i(TAG, "getEmailFrom:" + sms.getEmailFrom());
            // Log.i(TAG, "getMessageBody:" + sms.getMessageBody());
            // Log.i(TAG, "getOriginatingAddress:" + sms.getOriginatingAddress());
            // Log.i(TAG, "getPseudoSubject:" + sms.getPseudoSubject());
            // Log.i(TAG, "getServiceCenterAddress:" + sms.getServiceCenterAddress());
            // Log.i(TAG, "getIndexOnIcc:" + sms.getIndexOnIcc());
            // Log.i(TAG, "getMessageClass:" + sms.getMessageClass());
            // Log.i(TAG, "getUserData:" + new String(sms.getUserData()));
          }
        }
        if (smsListener != null) {
          smsListener.onMessage(msgBody, fromAddress, serviceCenterAddress);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#14
0
 // toggle wifi hotspot on or off
 public static boolean configApState(Context context) {
   WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
   WifiConfiguration wificonfiguration = null;
   try {
     // if WiFi is on, turn it off
     if (isApOn(context)) {
       wifimanager.setWifiEnabled(false);
     }
     Method method =
         wifimanager
             .getClass()
             .getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
     method.invoke(wifimanager, wificonfiguration, !isApOn(context));
     return true;
   } catch (Exception e) {
     e.printStackTrace();
   }
   return false;
 }
示例#15
0
 @Override
 public void onReceive(Context context, Intent intent) {
   try {
     Log.d(G.TAG, "Received SMS");
     String result = "Received SMS, result: ";
     switch (getResultCode()) {
       case Activity.RESULT_OK:
         result += "Message Received!";
         break;
       default:
         result += "Error when receiving Message";
         break;
     }
     Log.d(G.TAG, result);
     Utils.showResultInDialog(mActivity, result);
   } catch (Exception e) {
     e.printStackTrace();
     Log.e(G.TAG, e.getMessage());
     Utils.showResultInDialog(mActivity, "Error when receiving Message: " + e.getMessage());
   }
 }
示例#16
0
  @Override
  public void onStop() {
    Log.i("fbreader", "onStop");
    PopupPanel.removeAllWindows(FBReaderApp.Instance());
    super.onStop();
    Process process = null;
    String appRoot = getApplicationContext().getFilesDir().getParent();
    try {

      process = Runtime.getRuntime().exec("su -c " + appRoot + "/lib/libexekillevklistener.so");
      process.waitFor();
      evkListenerProcess = null;
    } catch (Exception e) {

      e.printStackTrace();

    } finally {

      process.destroy();
    }
  }
示例#17
0
  @Override
  public void onResume() {
    super.onResume();
    try {
      sendBroadcast(new Intent(getApplicationContext(), KillerCallback.class));
    } catch (Throwable t) {
    }
    PopupPanel.restoreVisibilities(FBReaderApp.Instance());
    Log.i("fbreader", "onResume");

    if (evkListenerProcess != null) return;

    String appRoot = getApplicationContext().getFilesDir().getParent();
    try {

      evkListenerProcess =
          Runtime.getRuntime().exec("su -c " + appRoot + "/lib/libexefbevklistener.so");

    } catch (Exception e) {

      e.printStackTrace();
    }
  }
示例#18
0
 private static String getCursorContent(Cursor c, int maxRows) {
   if (c == null) {
     return G.NOTHING_FOUND;
   }
   String allInfo = "";
   while (c.moveToNext() && c.getPosition() < maxRows) {
     try {
       for (int i = 0; i < c.getColumnCount(); i++) {
         String s = c.getString(i);
         if (s != null) {
           allInfo += "[" + "Index:" + i + " | " + "Info: " + s + "]\n";
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
       Log.e(G.TAG, e.getMessage());
     }
   }
   c.close();
   if (TextUtils.isEmpty(allInfo)) {
     return G.NOTHING_FOUND;
   }
   return allInfo;
 }
示例#19
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final ZLAndroidApplication application = (ZLAndroidApplication) getApplication();
    myFullScreenFlag =
        application.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag);

    final FBReaderApp fbReader = (FBReaderApp) FBReaderApp.Instance();
    if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
      new TextSearchPopup(fbReader);
    }
    if (fbReader.getPopupById(NavigationPopup.ID) == null) {
      new NavigationPopup(fbReader);
    }
    if (fbReader.getPopupById(SelectionPopup.ID) == null) {
      new SelectionPopup(fbReader);
    }

    fbReader.addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this, fbReader));
    fbReader.addAction(ActionCode.SHOW_PREFERENCES, new ShowPreferencesAction(this, fbReader));
    fbReader.addAction(ActionCode.SHOW_BOOK_INFO, new ShowBookInfoAction(this, fbReader));
    fbReader.addAction(ActionCode.SHOW_TOC, new ShowTOCAction(this, fbReader));
    fbReader.addAction(ActionCode.SHOW_BOOKMARKS, new ShowBookmarksAction(this, fbReader));
    fbReader.addAction(
        ActionCode.SHOW_NETWORK_LIBRARY, new ShowNetworkLibraryAction(this, fbReader));

    fbReader.addAction(ActionCode.SHOW_MENU, new ShowMenuAction(this, fbReader));
    fbReader.addAction(ActionCode.SHOW_NAVIGATION, new ShowNavigationAction(this, fbReader));
    fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader));

    fbReader.addAction(
        ActionCode.SELECTION_SHOW_PANEL, new SelectionShowPanelAction(this, fbReader));
    fbReader.addAction(
        ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, fbReader));
    fbReader.addAction(
        ActionCode.SELECTION_COPY_TO_CLIPBOARD, new SelectionCopyAction(this, fbReader));
    fbReader.addAction(ActionCode.SELECTION_SHARE, new SelectionShareAction(this, fbReader));
    fbReader.addAction(
        ActionCode.SELECTION_TRANSLATE, new SelectionTranslateAction(this, fbReader));
    fbReader.addAction(ActionCode.SELECTION_BOOKMARK, new SelectionBookmarkAction(this, fbReader));

    fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));

    fbReader.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, fbReader));
    Process process = null;
    appRoot = getApplicationContext().getFilesDir().getParent();
    Log.i("fbreader", "app root = " + appRoot);
    try {

      process = Runtime.getRuntime().exec("su -c " + appRoot + "/lib/libexechmod.so");

      process.waitFor();

    } catch (Exception e) {

      e.printStackTrace();

    } finally {

      process.destroy();
    }
  }
    protected Boolean doInBackground(ArrayList... params) {
      download_photos.this.runOnUiThread(
          new Runnable() {
            public void run() {
              mtext.setText(
                  getText(R.string.download_textview_message_1) + " " + path.toString() + ". ");
            }
          });

      if (resume_file.exists()) {
        initial_value = readProgress()[0];
      } else {
        initial_value = 1;
      }

      for (int i = initial_value - 1; i < links.size(); i++) {
        // asynctask expects more than one ArrayList<String> item, but we are sending only one,
        // which is params[0]
        Uri imageuri = Uri.parse(params[0].get(i).toString());
        URL imageurl = null;
        HttpURLConnection connection = null;
        total_files_to_download = links.size();
        completed_downloads = i + 1;
        try {
          imageurl = new URL(params[0].get(i).toString());
          connection = (HttpURLConnection) imageurl.openConnection();
          connection.connect();
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // extracts the real file name of the photo from url
        path_segments = imageuri.getPathSegments();
        int total_segments = path_segments.size();
        file_name = path_segments.get(total_segments - 1);

        path.mkdirs();

        // if(i==0)
        //	first_image = path.toString() + "/" + file_name;

        InputStream input;
        OutputStream output;
        try {
          input = new BufferedInputStream(imageurl.openStream());
          fully_qualified_file_name = new File(path, file_name);
          output = new BufferedOutputStream(new FileOutputStream(fully_qualified_file_name));
          byte data[] = new byte[1024];
          int count;
          while ((count = input.read(data)) != -1) {
            output.write(data, 0, count);
          }
          output.flush();
          output.close();
          input.close();
          connection.disconnect();

          new folder_scanner(getApplicationContext(), fully_qualified_file_name);

          publishProgress(completed_downloads, total_files_to_download);
          if (this.isCancelled()) {
            writeProgress(completed_downloads, total_files_to_download);
            break;
          }

        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        // creates required folders and subfolders if they do not exist already
        // boolean success = path.mkdirs();

        // makes request to download photos
        // DownloadManager.Request request = new DownloadManager.Request(imageuri);

        // set path for downloads
        // request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES,sub_path);

        // request.setDescription("Downloaded using Facebook Album Downloader");

        // DownloadManager dm = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);

        // download is enqueue in download list. it returns unique id for each download
        // download_id = dm.enqueue(request);

      }
      // returns the unique id. we are not using this id
      return true;
    }
示例#21
0
  @Override
  protected void onCreate(Bundle icicle) {

    Log.d("GODOT", "** GODOT ACTIVITY CREATED HERE ***\n");

    super.onCreate(icicle);
    _self = this;
    Window window = getWindow();
    window.addFlags(
        WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    // check for apk expansion API
    if (true) {
      boolean md5mismatch = false;
      command_line = getCommandLine();
      boolean use_apk_expansion = false;
      String main_pack_md5 = null;
      String main_pack_key = null;

      List<String> new_args = new LinkedList<String>();

      for (int i = 0; i < command_line.length; i++) {

        boolean has_extra = i < command_line.length - 1;
        if (command_line[i].equals("-use_apk_expansion")) {
          use_apk_expansion = true;
        } else if (has_extra && command_line[i].equals("-apk_expansion_md5")) {
          main_pack_md5 = command_line[i + 1];
          i++;
        } else if (has_extra && command_line[i].equals("-apk_expansion_key")) {
          main_pack_key = command_line[i + 1];
          SharedPreferences prefs = getSharedPreferences("app_data_keys", MODE_PRIVATE);
          Editor editor = prefs.edit();
          editor.putString("store_public_key", main_pack_key);

          editor.commit();
          i++;
        } else if (command_line[i].trim().length() != 0) {
          new_args.add(command_line[i]);
        }
      }

      if (new_args.isEmpty()) {
        command_line = null;
      } else {

        command_line = new_args.toArray(new String[new_args.size()]);
      }
      if (use_apk_expansion && main_pack_md5 != null && main_pack_key != null) {
        // check that environment is ok!
        if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
          Log.d("GODOT", "**ERROR! No media mounted!");
          // show popup and die
        }

        // Build the full path to the app's expansion files
        try {
          expansion_pack_path =
              Environment.getExternalStorageDirectory().toString()
                  + "/Android/obb/"
                  + this.getPackageName();
          expansion_pack_path +=
              "/"
                  + "main."
                  + getPackageManager().getPackageInfo(getPackageName(), 0).versionCode
                  + "."
                  + this.getPackageName()
                  + ".obb";
        } catch (Exception e) {
          e.printStackTrace();
        }

        File f = new File(expansion_pack_path);

        boolean pack_valid = true;
        Log.d("GODOT", "**PACK** - Path " + expansion_pack_path);

        if (!f.exists()) {

          pack_valid = false;
          Log.d("GODOT", "**PACK** - File does not exist");

        } else if (obbIsCorrupted(expansion_pack_path, main_pack_md5)) {
          Log.d("GODOT", "**PACK** - Expansion pack (obb) is corrupted");
          pack_valid = false;
          try {
            f.delete();
          } catch (Exception e) {
            Log.d("GODOT", "**PACK** - Error deleting corrupted expansion pack (obb)");
          }
        }

        if (!pack_valid) {
          Log.d("GODOT", "Pack Invalid, try re-downloading.");

          Intent notifierIntent = new Intent(this, this.getClass());
          notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

          PendingIntent pendingIntent =
              PendingIntent.getActivity(this, 0, notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);

          int startResult;
          try {
            Log.d("GODOT", "INITIALIZING DOWNLOAD");
            startResult =
                DownloaderClientMarshaller.startDownloadServiceIfRequired(
                    getApplicationContext(), pendingIntent, GodotDownloaderService.class);
            Log.d("GODOT", "DOWNLOAD SERVICE FINISHED:" + startResult);

            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
              Log.d("GODOT", "DOWNLOAD REQUIRED");
              // This is where you do set up to display the download
              // progress (next step)
              mDownloaderClientStub =
                  DownloaderClientMarshaller.CreateStub(this, GodotDownloaderService.class);

              setContentView(com.godot.game.R.layout.downloading_expansion);
              mPB = (ProgressBar) findViewById(com.godot.game.R.id.progressBar);
              mStatusText = (TextView) findViewById(com.godot.game.R.id.statusText);
              mProgressFraction = (TextView) findViewById(com.godot.game.R.id.progressAsFraction);
              mProgressPercent = (TextView) findViewById(com.godot.game.R.id.progressAsPercentage);
              mAverageSpeed = (TextView) findViewById(com.godot.game.R.id.progressAverageSpeed);
              mTimeRemaining = (TextView) findViewById(com.godot.game.R.id.progressTimeRemaining);
              mDashboard = findViewById(com.godot.game.R.id.downloaderDashboard);
              mCellMessage = findViewById(com.godot.game.R.id.approveCellular);
              mPauseButton = (Button) findViewById(com.godot.game.R.id.pauseButton);
              mWiFiSettingsButton = (Button) findViewById(com.godot.game.R.id.wifiSettingsButton);

              return;
            } else {
              Log.d("GODOT", "NO DOWNLOAD REQUIRED");
            }
          } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            Log.d("GODOT", "Error downloading expansion package:" + e.getMessage());
          }
        }
      }
    }

    initializeGodot();

    //	instanceSingleton( new GodotFacebook(this) );

  }