public static void setup(Context c) { context = c; app_opt = context.getDir("opt", Context.MODE_WORLD_READABLE).getAbsoluteFile(); app_log = context.getDir("log", Context.MODE_PRIVATE).getAbsoluteFile(); app_home = context.getDir("home", Context.MODE_PRIVATE).getAbsoluteFile(); app_gnupghome = context.getDir("gnupghome", Context.MODE_WORLD_WRITEABLE).getAbsoluteFile(); environmentConf = new File(app_opt, "etc/environment.conf"); versionFile = new File(app_opt, "VERSION"); /* * MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE were removed in Android * 4.3 (android-18) so force it that way. Yes, we really want this stuff * to be world read/write accessible since any app should be able to use * the command line tools */ Posix.chmod("755", app_opt); // 755 is MODE_WORLD_READABLE Posix.chmod("773", app_gnupghome); // 773 is MODE_WORLD_WRITEABLE File bin = new File(app_opt, "bin"); String logging = "--debug-level basic --log-file " + NativeHelper.app_log + "/gpg2.log "; gpg2 = new File(bin, "gpg2").getAbsolutePath() + " --no-tty --trust-model always " + logging; gpg_agent = new File(bin, "gpg-agent").getAbsolutePath(); pinentry_android = new File(bin, "pinentry-android").getAbsolutePath(); dirmngr = new File(bin, "dirmngr").getAbsolutePath(); sdcard = Environment.getExternalStorageDirectory().getAbsolutePath(); String lib = ""; try { lib = new File(c.getApplicationInfo().nativeLibraryDir).getCanonicalPath(); } catch (Exception e) { e.printStackTrace(); lib = new File(c.getApplicationInfo().nativeLibraryDir).getAbsolutePath(); } ldLibraryPath = lib + ":" + NativeHelper.app_opt + "/lib" + ":" + System.getenv("LD_LIBRARY_PATH"); String path = System.getenv("PATH"); envp = new String[] { "HOME=" + NativeHelper.app_home, "GNUPGHOME=" + NativeHelper.app_home, "LD_LIBRARY_PATH=" + ldLibraryPath, "PATH=" + path + ":" + bin.getAbsolutePath(), "app_opt=" + app_opt.getAbsolutePath() }; log = new StringBuffer(); constructEnvironmentConf(); Log.i(TAG, "Finished NativeHelper.setup()"); }
/** * Execute command to print all keys and values stored in the shared preferences which match the * optional given prefix */ private void doPrint(PrintStream writer, List<String> args) { String rootPath = mAppContext.getApplicationInfo().dataDir + "/shared_prefs"; String offsetPrefix = args.isEmpty() ? "" : args.get(0); String keyPrefix = (args.size() > 1) ? args.get(1) : ""; printRecursive(writer, rootPath, "", offsetPrefix, keyPrefix); }
public static Typeface loadTypeface(Context context, int font) { Typeface typeface = FontLoader.FONT_CACHE.get(font); if (typeface == null) { try { File file = new File(context.getApplicationInfo().dataDir + "/fonts"); if (!file.exists()) { file.mkdirs(); } file = new File(file, Integer.toHexString(font)); if (file.exists()) { file.delete(); } Resources res = context.getResources(); InputStream is = new BufferedInputStream(res.openRawResource(font)); OutputStream os = new ByteArrayOutputStream(Math.max(is.available(), 1024)); byte[] buffer = new byte[1024]; int read; while ((read = is.read(buffer)) > 0) { os.write(buffer, 0, read); } is.close(); os.flush(); buffer = ((ByteArrayOutputStream) os).toByteArray(); os.close(); os = new FileOutputStream(file); os.write(buffer); os.flush(); os.close(); FontLoader.FONT_CACHE.put(font, typeface = Typeface.createFromFile(file)); } catch (Exception e) { Log.e(FontLoader.TAG, "Error of loading font", e); } } return typeface; }
/** * 连接融云服务器 * * @param c * @param token 用户令牌 */ public static void ConnectRongYun(final Context c, String token) { RongYunFrindsManager.getInstance(c); if (c.getApplicationInfo() .packageName .equals(App.getCurrentPidName(c.getApplicationContext()))) { RongIM.connect( token, new ConnectCallback() { @Override public void onTokenIncorrect() { // TODO Auto-generated method stub Toast.makeText(c.getApplicationContext(), "获取令牌失败", Toast.LENGTH_SHORT).show(); } @Override public void onError(ErrorCode arg0) { // TODO Auto-generated method stub Toast.makeText(c.getApplicationContext(), "服务器故障,请稍候重试", Toast.LENGTH_SHORT).show(); } @Override public void onSuccess(String arg0) { // TODO Auto-generated method stub Toast.makeText(c.getApplicationContext(), "登录成功", Toast.LENGTH_SHORT).show(); } }); } }
public static ApplicationRatingInfo createApplicationInfo(Context context) { PackageManager packageManager = context.getPackageManager(); ApplicationInfo applicationInfo = null; PackageInfo packageInfo = null; try { applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0); packageInfo = packageManager.getPackageInfo(context.getApplicationInfo().packageName, 0); } catch (final PackageManager.NameNotFoundException e) { } ApplicationRatingInfo resultInfo = new ApplicationRatingInfo(); resultInfo.applicationName = packageManager.getApplicationLabel(applicationInfo).toString(); resultInfo.applicationVersionCode = packageInfo.versionCode; resultInfo.applicationVersionName = packageInfo.versionName; return resultInfo; }
public static int isPackageMalicious(Context context, PackageInfo packageInfo) { // If the package being checked is this one, it's not malicious if (packageInfo.packageName.equals(context.getPackageName())) { return MALICIOUS_NOT; } // If the package being checked shares a UID with Superuser, it's // probably malicious if (packageInfo.applicationInfo.uid == context.getApplicationInfo().uid) { return MALICIOUS_UID; } // Finally we check for any permissions that other apps should not have. if (packageInfo.requestedPermissions != null) { String[] bannedPermissions = new String[] { "com.noshufou.android.su.RESPOND", "com.noshufou.android.su.provider.WRITE" }; for (String s : packageInfo.requestedPermissions) { for (int i = 0; i < 2; i++) { if (s.equals(bannedPermissions[i]) && context .getPackageManager() .checkPermission(bannedPermissions[i], packageInfo.packageName) == PackageManager.PERMISSION_GRANTED) { return i + 2; } } } } return MALICIOUS_NOT; }
public static String getScreenWidthAndHeight(Context var0) { try { DisplayMetrics var1 = new DisplayMetrics(); WindowManager var2 = (WindowManager) ((WindowManager) var0.getSystemService(Context.WINDOW_SERVICE)); var2.getDefaultDisplay().getMetrics(var1); int var3 = -1; int var4 = -1; if ((var0.getApplicationInfo().flags & 8192) == 0) { var3 = getDisplayMetricsFiled((Object) var1, (String) "noncompatWidthPixels"); var4 = getDisplayMetricsFiled((Object) var1, (String) "noncompatHeightPixels"); } if (var3 == -1 || var4 == -1) { var3 = var1.widthPixels; var4 = var1.heightPixels; } StringBuffer var5 = new StringBuffer(); var5.append(var3); var5.append("*"); var5.append(var4); return var5.toString(); } catch (Exception var6) { YLog.e(TAG, "read resolution fail--->" + var6); return "Unknown"; } }
@Override public void onDownloadFinished(Context context, DownloadsUtil.DownloadInfo info) { File localFile = new File(info.localFilename); if (!localFile.isFile()) return; if (moduleVersion.md5sum != null && !moduleVersion.md5sum.isEmpty()) { try { String actualMd5Sum = HashUtil.md5(localFile); if (!moduleVersion.md5sum.equals(actualMd5Sum)) { Toast.makeText( context, context.getString( R.string.download_md5sum_incorrect, actualMd5Sum, moduleVersion.md5sum), Toast.LENGTH_LONG) .show(); DownloadsUtil.removeById(context, info.id); return; } } catch (Exception e) { Toast.makeText( context, context.getString(R.string.download_could_not_read_file, e.getMessage()), Toast.LENGTH_LONG) .show(); DownloadsUtil.removeById(context, info.id); return; } } PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = pm.getPackageArchiveInfo(info.localFilename, 0); if (packageInfo == null) { Toast.makeText(context, R.string.download_no_valid_apk, Toast.LENGTH_LONG).show(); DownloadsUtil.removeById(context, info.id); return; } if (!packageInfo.packageName.equals(moduleVersion.module.packageName)) { Toast.makeText( context, context.getString( R.string.download_incorrect_package_name, packageInfo.packageName, moduleVersion.module.packageName), Toast.LENGTH_LONG) .show(); DownloadsUtil.removeById(context, info.id); return; } Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE); installIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); installIntent.setDataAndType(Uri.fromFile(localFile), DownloadsUtil.MIME_TYPE_APK); // installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true); // installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true); installIntent.putExtra( Intent.EXTRA_INSTALLER_PACKAGE_NAME, context.getApplicationInfo().packageName); context.startActivity(installIntent); }
public void createNotification(Context context, Bundle extras) { NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String appName = getAppName(this); Intent notificationIntent = new Intent(this, PushHandlerActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("pushBundle", extras); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setDefaults(Notification.DEFAULT_ALL) .setSmallIcon(context.getApplicationInfo().icon) .setWhen(System.currentTimeMillis()) .setContentTitle(extras.getString("title")) .setTicker(extras.getString("title")) .setContentIntent(contentIntent); String message = extras.getString("message"); if (message != null) { mBuilder.setContentText(message); } else { mBuilder.setContentText("<missing message content>"); } String msgcnt = extras.getString("msgcnt"); if (msgcnt != null) { mBuilder.setNumber(Integer.parseInt(msgcnt)); } mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build()); }
@Override protected void attachBaseContext(Context context) { mIncrementalDeploymentDir = getIncrementalDeploymentDir(context) + '/'; instantiateRealApplication( context.getCacheDir(), context.getApplicationInfo().nativeLibraryDir, context.getApplicationInfo().dataDir); // This is called from ActivityThread#handleBindApplication() -> LoadedApk#makeApplication(). // Application#mApplication is changed right after this call, so we cannot do the monkey // patching here. So just forward this method to the real Application instance. super.attachBaseContext(context); if (real_application_not_instantiated) // it is in the bootstrap process with Seppuku. return; try { Method attachBaseContext = ContextWrapper.class.getDeclaredMethod("attachBaseContext", Context.class); attachBaseContext.setAccessible(true); attachBaseContext.invoke(realApplication, context); } catch (Exception e) { throw new IllegalStateException(e); } }
public boolean validateSignature(Context context, String packageName) { String brand = Build.BRAND; int applicationFlags = context.getApplicationInfo().flags; if (brand.startsWith("generic") && (applicationFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { // We are debugging on an emulator, don't validate package signature. return true; } PackageInfo packageInfo = null; try { packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException e) { return false; } for (Signature signature : packageInfo.signatures) { String hashedSignature = Utility.sha1hash(signature.toByteArray()); if (validAppSignatureHashes.contains(hashedSignature)) { return true; } } return false; }
public static void LoadApplication(Context context, String runtimeDataDir, String[] apks) { synchronized (lock) { if (!initialized) { System.loadLibrary("monodroid"); Locale locale = Locale.getDefault(); String language = locale.getLanguage() + "-" + locale.getCountry(); String filesDir = context.getFilesDir().getAbsolutePath(); String cacheDir = context.getCacheDir().getAbsolutePath(); String dataDir = context.getApplicationInfo().dataDir + "/lib"; ClassLoader loader = context.getClassLoader(); Runtime.init( language, apks, runtimeDataDir, new String[] { filesDir, cacheDir, dataDir, }, loader, new java.io.File( android.os.Environment.getExternalStorageDirectory(), "Android/data/" + context.getPackageName() + "/files/.__override__") .getAbsolutePath(), MonoPackageManager_Resources.Assemblies); initialized = true; } } }
private void scanForModel(Context context) throws IOException { String packageName = context.getPackageName(); String sourcePath = context.getApplicationInfo().sourceDir; List<String> paths = new ArrayList<String>(); if (sourcePath != null && !(new File(sourcePath).isDirectory())) { DexFile dexfile = new DexFile(sourcePath); Enumeration<String> entries = dexfile.entries(); while (entries.hasMoreElements()) { paths.add(entries.nextElement()); } } // Robolectric fallback else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Enumeration<URL> resources = classLoader.getResources(""); while (resources.hasMoreElements()) { String path = resources.nextElement().getFile(); if (path.contains("bin") || path.contains("classes")) { paths.add(path); } } } for (String path : paths) { File file = new File(path); scanForModelClasses(file, packageName, context.getClassLoader()); } }
private static File searchLibrary(Context context) { // Search for library path String[] libraryPaths = null; final ApplicationInfo applicationInfo = context.getApplicationInfo(); if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String property = System.getProperty("java.library.path"); libraryPaths = property.split(":"); } else { libraryPaths = new String[1]; if (isGingerbreadOrLater()) libraryPaths[0] = applicationInfo.nativeLibraryDir; else libraryPaths[0] = applicationInfo.dataDir + "/lib"; } if (libraryPaths == null) { Log.e(TAG, "can't find library path"); return null; } // Search for libvlcjni.so File lib = null; for (String libraryPath : libraryPaths) { lib = new File(libraryPath, "libvlcjni.so"); if (lib.exists() && lib.canRead()) return lib; ; } Log.e(TAG, "WARNING: Can't find shared library"); return null; }
public FlutterView(Context context, AttributeSet attrs) { super(context, attrs); // TODO(abarth): Remove this static and instead make everything that // depends on it into a view-associated service. ActivityImpl.setCurrentActivity((Activity) context); mMetrics = new ViewportMetrics(); mMetrics.devicePixelRatio = context.getResources().getDisplayMetrics().density; setFocusable(true); setFocusableInTouchMode(true); attach(); assert mNativePlatformView != 0; mSurfaceCallback = new SurfaceHolder.Callback() { @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} @Override public void surfaceCreated(SurfaceHolder holder) { assert mNativePlatformView != 0; nativeSurfaceCreated(mNativePlatformView, holder.getSurface()); } @Override public void surfaceDestroyed(SurfaceHolder holder) { assert mNativePlatformView != 0; nativeSurfaceDestroyed(mNativePlatformView); } }; getHolder().addCallback(mSurfaceCallback); mKeyboardState = new KeyboardViewState(this); mRawKeyboardState = new RawKeyboardServiceState(); Core core = CoreImpl.getInstance(); mPlatformServiceProvider = new ServiceProviderImpl(core, this, ServiceRegistry.SHARED); ServiceRegistry localRegistry = new ServiceRegistry(); configureLocalServices(localRegistry); mViewServiceProvider = new ServiceProviderImpl(core, this, localRegistry); mAccessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); mOnMessageListeners = new HashMap<String, OnMessageListener>(); mAsyncOnMessageListeners = new HashMap<String, OnMessageListenerAsync>(); mActivityLifecycleListeners = new ArrayList<ActivityLifecycleListener>(); setLocale(getResources().getConfiguration().locale); if ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { discoveryReceiver = new DiscoveryReceiver(); context.registerReceiver(discoveryReceiver, new IntentFilter(ACTION_DISCOVER)); } }
public void sendNotification(String message, boolean isForeground) { Context appContext = HXSDKHelper.getInstance().getAppContext(); if (notificationManager == null) { notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE); } try { String notifyText = message; PackageManager packageManager = appContext.getPackageManager(); String appname = (String) packageManager.getApplicationLabel(appContext.getApplicationInfo()); // notification titile String contentTitle = appname; String packageName = appContext.getApplicationInfo().packageName; Uri defaultSoundUrlUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // create and send notificaiton NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(appContext) .setSmallIcon(appContext.getApplicationInfo().icon) .setSound(defaultSoundUrlUri) .setWhen(System.currentTimeMillis()) .setAutoCancel(true); Intent msgIntent = appContext.getPackageManager().getLaunchIntentForPackage(packageName); PendingIntent pendingIntent = PendingIntent.getActivity( appContext, notifyID, msgIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentTitle(contentTitle); mBuilder.setTicker(notifyText); mBuilder.setContentText(notifyText); mBuilder.setContentIntent(pendingIntent); Notification notification = mBuilder.build(); notificationManager.notify(notifyID, notification); } catch (Exception e) { e.printStackTrace(); } }
private AndroidActions(final Context appContext, boolean silentErrors) { if (D) Log.d(TAG, "AndroidActions()"); mAppContext = appContext.getApplicationContext(); mSilentErrors = silentErrors; mAppName = appContext.getApplicationInfo().name; }
private PluginResult startServer(JSONArray inputs, CallbackContext callbackContext) { Log.w(LOGTAG, "startServer"); fromApplicationData = false; final String docRoot; // Get the input data. try { docRoot = inputs.getString(WWW_ROOT_ARG_INDEX); port = inputs.getInt(PORT_ARG_INDEX); cordovaRoot = inputs.getString(CORDOVA_ROOT_ARG_INDEX); } catch (JSONException exception) { Log.w(LOGTAG, String.format("JSON Exception: %s", exception.getMessage())); callbackContext.error(exception.getMessage()); return null; } if (docRoot.startsWith("../../Documents/meteor")) { Context ctx = cordova.getActivity().getApplicationContext(); localPath = new File(ctx.getApplicationInfo().dataDir, docRoot.substring(6)).getAbsolutePath(); Log.w(LOGTAG, "setting app dir path to " + localPath); fromApplicationData = true; } else { if (docRoot.startsWith("/")) { // localPath = // Environment.getExternalStorageDirectory().getAbsolutePath(); localPath = docRoot; } else { // localPath = "file:///android_asset/www"; localPath = "www"; if (docRoot.length() > 0) { localPath += "/"; localPath += docRoot; } } } Log.w(LOGTAG, "localpath is set to " + docRoot); final CallbackContext delayCallback = callbackContext; cordova .getActivity() .runOnUiThread( new Runnable() { @Override public void run() { String errmsg = __startServer(); if (errmsg != "") { delayCallback.error(errmsg); } else { url = "http://" + __getLocalIpAddress() + ":" + port; delayCallback.success(url); } } }); return null; }
/** * Constructor to be used when creating the {@link NavigationBar} as a regular control. This is * currently used by the theme editor. */ public NavigationBar(Context context, AttributeSet attrs) throws XmlPullParserException { this( (BridgeContext) context, Density.getEnum(((BridgeContext) context).getMetrics().densityDpi), LinearLayout.HORIZONTAL, // In this mode, it doesn't need to be render vertically ((BridgeContext) context).getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL, (context.getApplicationInfo().flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0, 0); }
@SuppressLint("NewApi") public _SharedPreferencesImpl_JSON(Context context, String name, int mode) { setCharset("utf-8"); try { File tempFile = new File(context.getApplicationInfo().dataDir + "/shared_prefs"); if (tempFile.exists()) { if (!tempFile.isDirectory()) { if (!tempFile.delete() && !tempFile.mkdirs()) { throw new CouldNotCreateStorage( tempFile, "Сann't create a storage for the preferences."); } if (VERSION.SDK_INT >= 9) { tempFile.setWritable(true); tempFile.setReadable(true); } } } else { if (!tempFile.mkdirs()) { throw new CouldNotCreateStorage(tempFile, "Сann't create a storage for the preferences."); } if (VERSION.SDK_INT >= 9) { tempFile.setWritable(true); tempFile.setReadable(true); } } tempFile = new File(tempFile, name + ".json"); if (!tempFile.exists() && !tempFile.createNewFile()) { throw new CouldNotCreateStorage(tempFile, "Сann't create a storage for the preferences."); } if (VERSION.SDK_INT >= 9) { switch (mode) { case Context.MODE_WORLD_WRITEABLE: tempFile.setWritable(true, false); tempFile.setReadable(true, false); break; case Context.MODE_WORLD_READABLE: tempFile.setWritable(true, true); tempFile.setReadable(true, false); break; case Context.MODE_PRIVATE: default: tempFile.setWritable(true, true); tempFile.setReadable(true, true); break; } } file = tempFile; fileTag = file.getAbsolutePath().intern(); if (getReference().data == null) { getReference().data = readDataFromFile(file); } } catch (IOException e) { throw new RuntimeException("IOException", e); } }
/** @return the path to native libraries. */ @SuppressWarnings("unused") @CalledByNative private static String getNativeLibraryDirectory(Context appContext) { ApplicationInfo ai = appContext.getApplicationInfo(); if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return ai.nativeLibraryDir; } return "/system/lib/"; }
public static String getNativeLibraryDirectory(Context appContext) { ApplicationInfo ai = context.getApplicationInfo(); Log.w("NDKHelper", "ai.nativeLibraryDir:" + ai.nativeLibraryDir); if ((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0 || (ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { return ai.nativeLibraryDir; } return "/system/lib/"; }
// Get location data for a trail if it exists public static int getResourceString(String name, Context context) { int nameResourceID = context .getResources() .getIdentifier(name, "xml", context.getApplicationInfo().packageName); if (nameResourceID == 0) { throw new IllegalArgumentException("No resource string found with name " + name); } else { return nameResourceID; } }
@Override public Xobc_xodir_dir[] Get_dirs(Xoa_app app) { Ordered_hash hash = Ordered_hash_.New(); // add default app dir String default_data_dir = context.getApplicationInfo().dataDir + "/"; String selected = app.User() .User_db_mgr() .Cfg() .Get_app_str_or(Xobc_xodir_cfg.Key__selected_dir, default_data_dir); Xobc_xodir_dir itm = new Xobc_xodir_dir( String_.Eq(selected, default_data_dir), false, Bry_.new_u8(default_data_dir)); hash.Add(default_data_dir, itm); // add "guessed" external dirs Sdcard_detection_strategy[] strategy_ary = new Sdcard_detection_strategy[] { new Strategy__storage_dir(-1), new Strategy__envvar__external_storage(-1), new Strategy__envvar__secondary_storage( -1) // NOTE: needed for BLU-STUDIO C 5+5 LTE; DATE: 2016-06-28 }; int len = strategy_ary.length; String root_rhs = Sdcard_detection_mgr.Get_root_rhs() + "/"; for (int i = 0; i < len; ++i) { Sdcard_detection_strategy strategy = strategy_ary[i]; String[] dir_strs = strategy.Get_dirs(context); for (String dir_str : dir_strs) { if (dir_str == null) continue; dir_str += root_rhs; if (hash.Has(dir_str)) continue; File dir = new File(dir_str); if (!dir.exists()) continue; // dir doesn't exist; don't bother trying to create b/c permission won't be // available at 4.4+ if (!Sdcard_detection_mgr.Dir_is_writeable(dir)) continue; itm = new Xobc_xodir_dir(String_.Eq(selected, dir_str), false, Bry_.new_u8(dir_str)); hash.Add(dir_str, itm); } } // add custom dir String custom = app.User() .User_db_mgr() .Cfg() .Get_app_str_or(Xobc_xodir_cfg.Key__custom_dir, "(choose your own folder)"); itm = new Xobc_xodir_dir(String_.Eq(selected, custom), true, Bry_.new_u8(custom)); hash.Add(custom, itm); return (Xobc_xodir_dir[]) hash.To_ary(Xobc_xodir_dir.class); }
private void copyDataBase() throws IOException { InputStream mInput = _context.getApplicationContext().getAssets().open("horoscope.sqlite"); String outFileName = _context.getApplicationInfo().dataDir + "/databases/" + "horoscope.sqlite"; OutputStream mOutput = new FileOutputStream(outFileName); byte[] mBuffer = new byte[1024]; int mLength; while ((mLength = mInput.read(mBuffer)) > 0) { mOutput.write(mBuffer, 0, mLength); } mOutput.flush(); mOutput.close(); mInput.close(); }
public String GetStoragePath() { String storagePath = ""; SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(mContext); boolean use_sdcard = settings.getBoolean("use_sdcard", false); if (use_sdcard) { File sdCard = Environment.getExternalStorageDirectory(); storagePath = sdCard.getAbsolutePath() + "/org.radare.installer/"; } else { // storagePath = "/data/data/org.radare.installer/"; storagePath = mContext.getApplicationInfo().dataDir; } return storagePath; }
public DatabaseHelper(Context context, String dbname, CursorFactory factory, int version) { // TODO Auto-generated constructor stub super(context, dbname, null, 1); this.context = context; // this is the path given to store db on phone ,as learnt from // stackoverflow DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; // the database is being created at the following path in phone // /data/data/com.example.mobilebooks/files/databases/ // DB_PATH = context.getFilesDir().getPath() + "/databases/"; System.out.println(DB_PATH); }
/** * Assembles the default db location for old version of the app. * * @return the legacy location of the database used with v1.4 */ public String getLegacyDbPath() { String dbPath; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { dbPath = mContext.getApplicationInfo().dataDir; } else { dbPath = "/data/data/" + mContext.getApplicationContext().getPackageName(); } // This was the default database name and it was impossible to create another one // at this location. dbPath += "/databases/data.mmb"; // dbPath += "/databases/"; // There are other internal databases, like webview.db, google_analytics, etc. return dbPath; }
/** * Create a helper object to create, open, and/or manage a database. This method always returns * very quickly. The database is not actually created or opened until one of {@link * #getWritableDatabase} or {@link #getReadableDatabase} is called. * * @param context to use to open or create the database * @param name of the database file * @param factory to use for creating cursor objects, or null for the default * @param version number of the database (starting at 1); if the database is older, SQL file(s) * contained within the application assets folder will be used to upgrade the database */ public SQLiteAssetHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); if (version < 1) throw new IllegalArgumentException("Version must be >= 1, was " + version); if (name == null) throw new IllegalArgumentException("Databse name cannot be null"); mContext = context; mName = name; mFactory = factory; mNewVersion = version; mArchivePath = ASSET_DB_PATH + "/" + name + ".zip"; mDatabasePath = context.getApplicationInfo().dataDir + "/databases"; mUpgradePathFormat = ASSET_DB_PATH + "/" + name + "_upgrade_%s-%s.sql"; }
private Prompt createDefaultStartPrompt() { if (this._speechKit != null) { int beepResId = _context .getResources() .getIdentifier("rawbeep", "raw", _context.getApplicationInfo().packageName); return _speechKit.defineAudioPrompt(beepResId); } else { Log.e( PLUGIN_NAME, "Cannot create Start Prompt: SpeechKit not initialized, returning default prompt [NONE]..."); } return null; }