@Override public void onCreate() { Utils.logger("d", "service created", DEBUG_TAG); BugSenseHandler.initAndStartSession(this, YTD.BugsenseApiKey); BugSenseHandler.leaveBreadcrumb("AutoUpgradeApkService_onCreate"); registerReceiver(apkReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); try { currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionName; Utils.logger("d", "current version: " + currentVersion, DEBUG_TAG); } catch (NameNotFoundException e) { Log.e(DEBUG_TAG, "version not read: " + e.getMessage()); currentVersion = "100"; } ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.isConnected() && matchedVersion != "n.a.") { try { // init version and changelog matchedChangeLog = null; matchedVersion = null; asyncAutoUpdate = new AsyncUpdate(); webPage = "http://sourceforge.net/projects/ytdownloader/files/"; asyncAutoUpdate.execute(webPage); } catch (NullPointerException e) { Log.e(DEBUG_TAG, "unable to retrieve update data."); } } else { Log.e(DEBUG_TAG, getString(R.string.no_net)); } }
@Override public void onReceive(Context context, Intent intent) { try { DownloaderClientMarshaller.startDownloadServiceIfRequired( context, intent, MapFileDownloaderService.class); } catch (NameNotFoundException e) { Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e); } } // onReceive
/** * 获取版本号 vername type:String * * @author Sogrey * @date 2015年4月24日 * @param context * @return */ public static String getVerName(Context context) { String pkgName = getPackageName(context); String verName = ""; try { verName = context.getPackageManager().getPackageInfo(pkgName, 0).versionName; } catch (NameNotFoundException e) { LogUtil.e("err", e.getMessage()); e.printStackTrace(); } return verName; }
private String getVersionName() { String retval; try { retval = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Debug.e(TAG, e.getMessage()); retval = "Unknown"; } return retval; }
/** * 获取应用程序版本号 getVersionName * * @param context * @return * @since 1.0 */ public static String getVersionName(Context context) { if (TextUtils.isEmpty(sVersionName)) { try { String name = getApplicationPackageName(context); sVersionName = context.getPackageManager().getPackageInfo(name, 0).versionName; } catch (NameNotFoundException e) { Log.e(LOG_TAG, e.getMessage()); } } return sVersionName; }
/** * 获取应用VersionCode getVersionCode * * @param context * @return * @since 1.0 */ public static int getVersionCode(Context context) { if (sVersionCode == -1) { try { String name = getApplicationPackageName(context); sVersionCode = context.getPackageManager().getPackageInfo(name, 0).versionCode; } catch (NameNotFoundException e) { Log.e(LOG_TAG, e.getMessage()); } } return sVersionCode; }
public boolean isInstalled(String packageName) { boolean isInstalled = false; try { context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); isInstalled = true; } catch (NameNotFoundException e) { if (Constants.DEBUG) Log.e(TAG, e.getMessage(), e); } return isInstalled; }
private void initAppVersion(Context context) { if (context == null) { mAppVersion = "0.0"; return; } try { mAppVersion = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Logging.out(LOG_TAG, "Can't get app version. Exception: " + e.getMessage(), LogLevel.ERROR); mAppVersion = "0.0"; } }
protected Context getPackageContext(Context context, String packageName) { Context packageContext = null; if (StringUtil.isEmpty(packageName)) { return packageContext; } try { packageContext = context.createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY); } catch (NameNotFoundException e) { if (Constants.DEBUG) Log.e(TAG, e.getMessage(), e); } return packageContext; }
/** * Get the current package version. * * @return The current version. */ private String getVersion() { String result = ""; try { PackageManager manager = getActivity().getPackageManager(); PackageInfo info = manager.getPackageInfo(getActivity().getPackageName(), 0); result = String.format("%s (%s)", info.versionName, info.versionCode); } catch (NameNotFoundException e) { Log.w(Constants.TAG, "Unable to get application version: " + e.getMessage()); result = "Unable to get application version."; } return result; }
public app2class1(Context context) { try { Log.i(LOG, "--app2class1() called."); Context mmsCtx = context.createPackageContext( "com.example.app1", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); Class<?> cl = Class.forName("com.example.app1.app1class1", true, mmsCtx.getClassLoader()); Log.i(LOG, "--getCanonicalName()= " + cl.getCanonicalName()); // cl.getMethod("init", Context.class).invoke(null, mmsCtx); app1Method = cl.getMethod("getString", String.class); Log.i(LOG, "--getMethod got a method"); app1Object = cl.getMethod("getInstance").invoke((Object[]) null); // Method app1Metho2 = cl.getm Log.i(LOG, "--getInstance passed"); // app1Object = cl.getMethod("getInstance").invoke("s"); // cl.getMethod("getString", String.class).invoke(cl, // " static method invocation worked "); // // app1Method = cl.getMethod("voidMethod", Void.class); } catch (NameNotFoundException ex) { Log.e(LOG, "--constructor() created NameNotFoundException: " + ex.getMessage()); } catch (ClassNotFoundException ex) { // TODO Auto-generated catch block Log.e(LOG, "--constructor() created ClassNotFoundException: " + ex.getMessage()); } catch (NoSuchMethodException ex) { // TODO Auto-generated catch block Log.e(LOG, "--constructor() created NoSuchMethodException: " + ex.getMessage()); } catch (IllegalArgumentException ex) { // TODO Auto-generated catch block Log.e(LOG, "--constructor() created IllegalArgumentException: " + ex.getMessage()); } catch (IllegalAccessException ex) { // TODO Auto-generated catch block Log.e(LOG, "--constructor() created IllegalAccessException: " + ex.getMessage()); } catch (InvocationTargetException ex) { // TODO Auto-generated catch block Log.e(LOG, "--constructor() created InvocationTargetException: " + ex.getMessage()); } catch (Exception ex) { Log.e(LOG, "--constructor() created Exception: " + ex.getMessage()); } }
@Override public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.dialog_about); // Header Resources res = mContext.getResources(); String appName = res.getString(R.string.app_name); TextView title = (TextView) findViewById(R.id.title); title.setText("About " + appName); // Application info TextView head = (TextView) findViewById(R.id.header); String appVersion = "Revision: "; try { appVersion += mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { Log.v(TAG, e.getMessage()); } head.setText(appVersion); // From About.html web page WebView wv = (WebView) findViewById(R.id.content); wv.loadUrl("file:///android_asset/about.html"); // Dismiss button Button okButton = (Button) findViewById(R.id.buttonOK); okButton.setOnClickListener(mOkListener); // Device information TextView foot = (TextView) findViewById(R.id.footer); String txt = Build.MANUFACTURER.toUpperCase() + " " + Build.MODEL + " Android " + Build.VERSION.RELEASE + " " + Build.DISPLAY; foot.setText(txt); }
private boolean unlockPremium() { boolean unlocked = false; PackageManager pm = mContext.getPackageManager(); List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo applicationInfo : packages) { try { PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_PERMISSIONS); if ("org.gots.premium".equals(packageInfo.packageName)) { unlocked = true; } } catch (NameNotFoundException e) { Log.e(TAG, e.getMessage(), e); } } return unlocked; }
/** * 获取APP崩溃异常报告 * * @param ex * @return */ private String getCrashReport(Context context, Throwable ex) { PackageInfo pinfo = null; try { pinfo = context .getApplicationContext() .getPackageManager() .getPackageInfo(context.getApplicationContext().getPackageName(), 0); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return e.getMessage(); } StringBuffer exceptionStr = new StringBuffer(); exceptionStr.append("Version: " + pinfo.versionName + "(" + pinfo.versionCode + ")\n"); exceptionStr.append( "Android: " + android.os.Build.VERSION.RELEASE + "(" + android.os.Build.MODEL + ")\n"); exceptionStr.append("Exception: " + ex.getMessage() + "\n"); StackTraceElement[] elements = ex.getStackTrace(); for (int i = 0; i < elements.length; i++) { exceptionStr.append(elements[i].toString() + "\n"); } return exceptionStr.toString(); }
/** * Instantiates a new object to retrieve and persist app data. * * @param context The application context. */ @TargetApi(13) public AppData(Context context) { hardwareInfo = new HardwareInfo(); packageName = context.getPackageName(); PackageInfo info; String version = ""; int versionCode = -1; try { info = context.getPackageManager().getPackageInfo(packageName, 0); version = info.versionName; versionCode = info.versionCode; } catch (NameNotFoundException e) { Log.e("AppData", e.getMessage()); } appVersion = version; appVersionCode = versionCode; // Directories if (DOWNLOAD_TO_SDCARD) { storageDir = Environment.getExternalStorageDirectory().getAbsolutePath(); coreSharedDataDir = storageDir + "/Android/data/" + packageName; } else { storageDir = context.getFilesDir().getAbsolutePath(); coreSharedDataDir = storageDir; } tempDir = coreSharedDataDir + "/tmp"; String _libsDir = context.getFilesDir().getParentFile().getAbsolutePath() + "/lib/"; if (!(new File(_libsDir)).exists() && IS_GINGERBREAD) _libsDir = context.getApplicationInfo().nativeLibraryDir; libsDir = _libsDir; touchscreenSkinsDir = coreSharedDataDir + "/skins/touchscreen/"; touchpadSkinsDir = coreSharedDataDir + "/skins/touchpad/"; profilesDir = coreSharedDataDir + "/profiles"; // Files coreLib = libsDir + "/libmupen64plus-core.so"; rspLib = libsDir + "/libmupen64plus-rsp-hle.so"; inputLib = libsDir + "/libmupen64plus-input-android.so"; gln64_conf = coreSharedDataDir + "/gln64.conf"; glide64mk2_ini = coreSharedDataDir + "/Glide64mk2.ini"; mupencheat_default = coreSharedDataDir + "/mupencheat.default"; mupencheat_txt = coreSharedDataDir + "/mupencheat.txt"; mupen64plus_ini = coreSharedDataDir + "/mupen64plus.ini"; controllerProfiles_cfg = profilesDir + "/controller.cfg"; touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg"; touchpadProfiles_cfg = profilesDir + "/touchpad.cfg"; emulationProfiles_cfg = profilesDir + "/emulation.cfg"; // Installation validity // @formatter:off isValidInstallation = libraryExists("ae-exports") && libraryExists("ae-imports") && libraryExists("freetype") && libraryExists("mupen64plus-audio-sdl") && libraryExists("mupen64plus-audio-sles") && libraryExists("mupen64plus-core") && libraryExists("mupen64plus-input-android") && libraryExists("mupen64plus-rsp-hle") && libraryExists("mupen64plus-ui-console") && libraryExists("mupen64plus-video-glide64mk2") && libraryExists("mupen64plus-video-gliden64-gles20") && libraryExists("mupen64plus-video-gliden64-gles30") && libraryExists("mupen64plus-video-gliden64-gles31") && libraryExists("mupen64plus-video-gln64") && libraryExists("mupen64plus-video-rice") && libraryExists("SDL2") && libraryExists("xperia-touchpad"); // @formatter:on // Preference object for persisting app data String appDataFilename = packageName + "_appdata"; mPreferences = context.getSharedPreferences(appDataFilename, Context.MODE_PRIVATE); if (AppData.IS_ICE_CREAM_SANDWICH) { UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE); isAndroidTv = uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; } else { isAndroidTv = false; } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btnClockIn: if (allowedToPress()) { clickedClockIn(); } else { // buildNeedUpdateDialog(); //Disabled, no need for dialog. } break; case R.id.btnProjects: if (allowedToPress()) { startActivity(new Intent(this, ManageProjectsActivity.class)); } break; case R.id.btnClockOut: if (allowedToPress()) { clickedClockOut(); } break; case R.id.btnExport: if (allowedToPress()) { Intent i2 = new Intent(this, ListActivity.class); i2.putExtra(Constants.KEY_SHOW_TYPE, Constants.TYPE_EXPORT); startActivity(i2); } break; case R.id.btnInfo: String name = null; try { name = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { e.printStackTrace(); name = this.getString(R.string.version_name_unable) + e.getMessage(); } final AlertDialog.Builder builder2 = new AlertDialog.Builder(this); builder2.setMessage(TimeClock.this.getString(R.string.version_name) + name); builder2 .setTitle(R.string.app_name) .setCancelable(true) .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int id) { dialog.dismiss(); } }); final AlertDialog alert2 = builder2.create(); alert2.show(); break; case R.id.btnList: if (allowedToPress()) { Intent i = new Intent(this, ListActivity.class); i.putExtra(Constants.KEY_SHOW_TYPE, Constants.TYPE_LIST); startActivity(i); } break; case R.id.btnSettings: if (allowedToPress()) { startActivity(new Intent(TimeClock.this, MyPrefsActivity.class)); } break; } }
@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) ); }