Java Code Examples for android.app.Activity#getPackageName()
The following examples show how to use
android.app.Activity#getPackageName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceManager.java From weixin with Apache License 2.0 | 6 votes |
public ServiceManager(Context context) { this.context = context; if (context instanceof Activity) { L.i(TAG, "Callback Activity..."); Activity callbackActivity = (Activity) context; callbackActivityPackageName = callbackActivity.getPackageName(); callbackActivityClassName = callbackActivity.getClass().getName(); } props = loadProperties(); apiKey = props.getProperty("apiKey", ""); xmppHost = props.getProperty("xmppHost", "127.0.0.1"); xmppPort = props.getProperty("xmppPort", "5222"); L.i(TAG, "apiKey=" + apiKey); L.i(TAG, "xmppHost=" + xmppHost); L.i(TAG, "xmppPort=" + xmppPort); sp = new SpUtil(context); sp.saveString(Constants.API_KEY, apiKey); sp.saveString(Constants.VERSION, version); sp.saveString(Constants.XMPP_HOST, xmppHost); sp.saveInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort)); sp.saveString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, callbackActivityPackageName); sp.saveString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, callbackActivityClassName); }
Example 2
Source File: RNLockTaskModule.java From react-native-lock-task with MIT License | 6 votes |
@ReactMethod public void startLockTask() { try { Activity mActivity = reactContext.getCurrentActivity(); if (mActivity != null) { DevicePolicyManager myDevicePolicyManager = (DevicePolicyManager) mActivity.getSystemService(Context.DEVICE_POLICY_SERVICE); ComponentName mDPM = new ComponentName(mActivity, MyAdmin.class); if (myDevicePolicyManager.isDeviceOwnerApp(mActivity.getPackageName())) { String[] packages = {mActivity.getPackageName()}; myDevicePolicyManager.setLockTaskPackages(mDPM, packages); mActivity.startLockTask(); } else { mActivity.startLockTask(); } } } catch (Exception e) { } }
Example 3
Source File: BuildModule.java From debugdrawer with Apache License 2.0 | 6 votes |
@Override protected void onAttach(Activity activity, DebugView parent, ViewGroup content) { String packageName = activity.getPackageName(); String buildConfigPackage = packageName+".BuildConfig"; addElement(new TextElement("Name:", getViaReflection(String.class,buildConfigPackage,"VERSION_NAME"))); addElement(new TextElement("Code:", getViaReflection(Integer.class,buildConfigPackage,"VERSION_CODE")+"")); addElement(new TextElement("SHA:", getViaReflection(String.class,buildConfigPackage,"GIT_SHA"))); try { String buildTimeString = getViaReflection(String.class,buildConfigPackage,"BUILD_TIME"); // Parse ISO8601-format time into local time. DateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); inFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String buildTime = DATE_DISPLAY_FORMAT.format(inFormat.parseObject(buildTimeString)); addElement(new TextElement("Date:", buildTime)); } catch (Exception e) { } }
Example 4
Source File: FloatLifecycleReceiver.java From FloatWindow with Apache License 2.0 | 5 votes |
/** * 页面关闭时检查页面监听监视 * * @param activity */ private void checkConfigChangeWhenPause(Activity activity) { RotateUtil.getInstance().start(activity); if (mActivityAndLandscape.size() < 1) { // 有悬浮窗后的,首次关闭页面-(兼容页面打开,才展示悬浮窗,此时map无此页面信息) String activityName = activity.getPackageName() + "." + activity.getLocalClassName(); mActivityAndLandscape.put(activityName, ViewUtils.isActivityLandscape(activity)); } }
Example 5
Source File: AboutSettingsFragment.java From JumpGo with Mozilla Public License 2.0 | 5 votes |
private String getVersion() { try { Activity activity = getActivity(); String packageName = activity.getPackageName(); PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, 0); return packageInfo.versionName; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "getVersion: error", e); return "1.0"; } }
Example 6
Source File: AppRate.java From discreet-app-rate with Apache License 2.0 | 5 votes |
public static AppRate with(Activity activity) { if (activity == null) { throw new IllegalStateException("Activity cannot be null"); } AppRate instance = new AppRate(activity); instance.text = activity.getString(R.string.dra_rate_app); instance.settings = activity.getSharedPreferences(PREFS_NAME, 0); instance.editor = instance.settings.edit(); instance.packageName = activity.getPackageName(); return instance; }
Example 7
Source File: OrientationChangeAction.java From espresso-macchiato with MIT License | 5 votes |
protected boolean hasActivityFixedOrientation(Activity currentActivity) { ActivityInfo[] activities; String packageName = currentActivity.getPackageName(); // collect AndroidManifest.xml activities properties try { activities = InstrumentationRegistry.getTargetContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES).activities; } catch (PackageManager.NameNotFoundException e) { throw new IllegalStateException(e); } for (ActivityInfo activity : activities) { // skip if activity info is not for the current active activity if (!activity.name.equals(currentActivity.getClass().getName())) { continue; } // report if the activity requestedOrientation is fixed if (activity.screenOrientation != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { Log.d(OrientationChangeAction.class.getSimpleName(), "Ignore orientation change because orientation for this activity is fixed in AndroidManifest.xml."); return true; } } return false; }
Example 8
Source File: ServiceManager.java From AndroidPNClient with Apache License 2.0 | 5 votes |
public ServiceManager(Context context) { this.context = context; if (context instanceof Activity) { Log.i(LOGTAG, "Callback Activity..."); Activity callbackActivity = (Activity) context; callbackActivityPackageName = callbackActivity.getPackageName(); callbackActivityClassName = callbackActivity.getClass().getName(); } props = loadProperties(); apiKey = props.getProperty(Constants.PROP_API_KEY, ""); xmppHost = props.getProperty(Constants.PROP_XMPP_HOST, Constants.DEFAULT_HOST); xmppPort = props.getProperty(Constants.PROP_XMPP_PORT, Constants.DEFAULT_PORT); NotifierConfig.packetListener = props.getProperty(Constants.PROP_PACKET_LISTENER, null); NotifierConfig.iq = props.getProperty(Constants.PROP_IQ, null); NotifierConfig.iqProvider = props.getProperty(Constants.PROP_IQ_PROVIDER, null); NotifierConfig.notifyActivity = props.getProperty(Constants.PROP_NOTIFY_ACTIVITY, null); Log.i(LOGTAG, "apiKey=" + apiKey); Log.i(LOGTAG, "xmppHost=" + xmppHost); Log.i(LOGTAG, "xmppPort=" + xmppPort); Log.i(LOGTAG, "packetListener=" + NotifierConfig.packetListener); Log.i(LOGTAG, "iq=" + NotifierConfig.iq); Log.i(LOGTAG, "iqProvider=" + NotifierConfig.iqProvider); Log.i(LOGTAG, "notifyActivity" + NotifierConfig.notifyActivity); sharedPrefs = context.getSharedPreferences( Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPrefs.edit(); editor.putString(Constants.API_KEY, apiKey); editor.putString(Constants.VERSION, version); editor.putString(Constants.XMPP_HOST, xmppHost); editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort)); editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, callbackActivityPackageName); editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, callbackActivityClassName); editor.commit(); SmackConfiguration.setKeepAliveInterval(60000); }
Example 9
Source File: ServiceManager.java From androidpn-client with Apache License 2.0 | 5 votes |
public ServiceManager(Context context) { this.context = context; if (context instanceof Activity) { Log.i(LOGTAG, "Callback Activity..."); Activity callbackActivity = (Activity) context; callbackActivityPackageName = callbackActivity.getPackageName(); callbackActivityClassName = callbackActivity.getClass().getName(); } setSettings(); }
Example 10
Source File: ServiceManager.java From palmsuda with Apache License 2.0 | 5 votes |
public ServiceManager(Context context) { this.context = context; if (context instanceof Activity) { Log.i(LOGTAG, "Callback Activity..."); Activity callbackActivity = (Activity) context; callbackActivityPackageName = callbackActivity.getPackageName(); callbackActivityClassName = callbackActivity.getClass().getName(); } props = loadProperties(); apiKey = props.getProperty("apiKey", ""); xmppHost = props.getProperty("xmppHost", "127.0.0.1"); xmppPort = props.getProperty("xmppPort", "5222"); Log.i(LOGTAG, "apiKey=" + apiKey); Log.i(LOGTAG, "xmppHost=" + xmppHost); Log.i(LOGTAG, "xmppPort=" + xmppPort); sharedPrefs = context.getSharedPreferences( Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); Editor editor = sharedPrefs.edit(); editor.putString(Constants.API_KEY, apiKey); editor.putString(Constants.VERSION, version); editor.putString(Constants.XMPP_HOST, xmppHost); editor.putInt(Constants.XMPP_PORT, Integer.parseInt(xmppPort)); editor.putString(Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, callbackActivityPackageName); editor.putString(Constants.CALLBACK_ACTIVITY_CLASS_NAME, callbackActivityClassName); editor.commit(); // Log.i(LOGTAG, "sharedPrefs=" + sharedPrefs.toString()); }
Example 11
Source File: ShareHelper.java From 365browser with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1) static void sendChooserIntent(boolean saveLastUsed, Activity activity, Intent sharingIntent, @Nullable TargetChosenCallback callback) { synchronized (LOCK) { if (sTargetChosenReceiveAction == null) { sTargetChosenReceiveAction = activity.getPackageName() + "/" + TargetChosenReceiver.class.getName() + "_ACTION"; } Context context = activity.getApplicationContext(); if (sLastRegisteredReceiver != null) { context.unregisterReceiver(sLastRegisteredReceiver); // Must cancel the callback (to satisfy guarantee that exactly one method of // TargetChosenCallback is called). // TODO(mgiuca): This should be called immediately upon cancelling the chooser, // not just when the next share takes place (https://crbug.com/636274). sLastRegisteredReceiver.cancel(); } sLastRegisteredReceiver = new TargetChosenReceiver(saveLastUsed, callback); context.registerReceiver( sLastRegisteredReceiver, new IntentFilter(sTargetChosenReceiveAction)); } Intent intent = new Intent(sTargetChosenReceiveAction); intent.setPackage(activity.getPackageName()); intent.putExtra(EXTRA_RECEIVER_TOKEN, sLastRegisteredReceiver.hashCode()); final PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); Intent chooserIntent = Intent.createChooser(sharingIntent, activity.getString(R.string.share_link_chooser_title), pendingIntent.getIntentSender()); if (sFakeIntentReceiverForTesting != null) { sFakeIntentReceiverForTesting.setIntentToSendBack(intent); } fireIntent(activity, chooserIntent); }
Example 12
Source File: GooglePlay.java From force-update with Apache License 2.0 | 5 votes |
public static void openAppDetail(Activity gContext) { String appPackage = gContext.getPackageName(); Uri googlePlayUri = Uri.parse("market://details?id=" + appPackage); Intent googlePlayIntent = new Intent(Intent.ACTION_VIEW, googlePlayUri); boolean googlePlayAvailable = false; // try to find official Google Play app final List<ResolveInfo> availableApps = gContext.getPackageManager().queryIntentActivities(googlePlayIntent, 0); for (ResolveInfo app: availableApps) { if (app.activityInfo.applicationInfo.packageName.equals("com.android.vending")) { ActivityInfo appActivity = app.activityInfo; ComponentName component = new ComponentName( appActivity.applicationInfo.packageName, appActivity.name ); googlePlayIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); googlePlayIntent.setComponent(component); gContext.startActivity(googlePlayIntent); googlePlayAvailable = true; break; } } if (!googlePlayAvailable) { if (availableApps.size() > 0) { // fallback to universal Google Play Intent gContext.startActivity(googlePlayIntent); } else { // if there is no app bind to market:// open Google Play in browser Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackage)); gContext.startActivity(webIntent); } } }
Example 13
Source File: PSUtil.java From PictureSelector with Apache License 2.0 | 4 votes |
public static String getAuthorities(Activity activity) { return activity.getPackageName() + ConstantData.VALUE_AUTHORITIES; }
Example 14
Source File: FileUtils.java From reader with MIT License | 4 votes |
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = activity.getIntent().getStringExtra("androidpersistentfilelocation"); if (location == null) { location = "compatibility"; } tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. new File(tempRoot).mkdirs(); new File(persistentRoot).mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot)); this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot)); this.registerFilesystem(new ContentFilesystem(cordova, webView)); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
Example 15
Source File: FileUtils.java From keemob with MIT License | 4 votes |
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); this.pendingRequests = new PendingRequests(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = preferences.getString("androidpersistentfilelocation", "internal"); tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. File tmpRootFile = new File(tempRoot); File persistentRootFile = new File(persistentRoot); tmpRootFile.mkdirs(); persistentRootFile.mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile)); this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(), persistentRootFile)); this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi())); this.registerFilesystem(new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi())); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { LOG.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
Example 16
Source File: GPTInstrumentation.java From GPT with Apache License 2.0 | 4 votes |
/** * onCallActivityOnCreate * * @param activity Activity */ private void onCallActivityOnCreate(Activity activity) { String packageName = activity.getPackageName(); boolean isPlugin = isPlugin(packageName); if (!isPlugin) { return; } if (ProxyEnvironment.pluginHotStartTimeMap.get(packageName) != null) { long stamp = ProxyEnvironment.pluginHotStartTimeMap.get(packageName); long millis = SystemClock.elapsedRealtime() - stamp; if (stamp > -1 && millis > 0) { ReportManger.getInstance().onPluginHotLoad(activity.getApplicationContext(), packageName, millis); ProxyEnvironment.pluginHotStartTimeMap.remove(packageName); } } replacePluginPackageName2Host(activity); replaceSystemServices(activity); replaceWindow(activity); replaceExternalDirs(activity); // 初始化 activity layoutinflator and localactivity manager Activity parent = activity.getParent(); if (parent != null && parent instanceof ActivityProxy) { ((ActivityProxy) parent).onBeforeCreate(activity); } if (Build.VERSION.SDK_INT < 23 /*Android m 6.0*/) { // bindservice trick begin // 如果在actiivty的 oncreate 中 binder service,token 中的 activity 对象为 null String className = "android.app.LocalActivityManager$LocalActivityRecord"; Class clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { if (DEBUG) { e.printStackTrace(); } } IBinder token = JavaCalls.callMethod(activity.getBaseContext(), "getActivityToken"); if (clazz != null && token != null && token.getClass().equals(clazz)) { Activity a = (Activity) JavaCalls.getField(token, "activity"); if (a == null) { JavaCalls.setField(token, "activity", activity); } } // bindservice trick end } else { // 6.0 以上 Activity.mBase.mActvityToken 一直为 null,不使用也可以工作。 } }
Example 17
Source File: FileUtils.java From reader with MIT License | 4 votes |
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = activity.getIntent().getStringExtra("androidpersistentfilelocation"); if (location == null) { location = "compatibility"; } tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. new File(tempRoot).mkdirs(); new File(persistentRoot).mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot)); this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot)); this.registerFilesystem(new ContentFilesystem(cordova, webView)); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
Example 18
Source File: TextSearchFragment.java From trekarta with GNU General Public License v3.0 | 4 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Bundle arguments = getArguments(); double latitude = arguments.getDouble(ARG_LATITUDE); double longitude = arguments.getDouble(ARG_LONGITUDE); if (savedInstanceState != null) { latitude = savedInstanceState.getDouble(ARG_LATITUDE); longitude = savedInstanceState.getDouble(ARG_LONGITUDE); } Activity activity = getActivity(); mCoordinates = new GeoPoint(latitude, longitude); mDatabase = MapTrek.getApplication().getDetailedMapDatabase(); mAdapter = new DataListAdapter(activity, mEmptyCursor, 0); setListAdapter(mAdapter); QuickFilterAdapter adapter = new QuickFilterAdapter(activity); mViews.quickFilters.setAdapter(adapter); LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false); mViews.quickFilters.setLayoutManager(horizontalLayoutManager); Resources resources = activity.getResources(); String packageName = activity.getPackageName(); mKinds = new CharSequence[Tags.kinds.length]; // we add two kinds but skip two last mKinds[0] = activity.getString(R.string.any); mKinds[1] = resources.getString(R.string.kind_place); for (int i = 0; i < Tags.kinds.length - 2; i++) { // skip urban and barrier kinds int id = resources.getIdentifier(Tags.kinds[i], "string", packageName); mKinds[i + 2] = id != 0 ? resources.getString(id) : Tags.kinds[i]; } if (mUpdating || !MapTrekDatabaseHelper.hasFullTextIndex(mDatabase)) { mViews.searchFooter.setVisibility(View.GONE); mViews.ftsWait.spin(); mViews.ftsWait.setVisibility(View.VISIBLE); mViews.message.setText(R.string.msgWaitForFtsTable); mViews.message.setVisibility(View.VISIBLE); if (!mUpdating) { mUpdating = true; final Message m = Message.obtain(mBackgroundHandler, () -> { MapTrekDatabaseHelper.createFtsTable(mDatabase); hideProgress(); mUpdating = false; }); m.what = MSG_CREATE_FTS; mBackgroundHandler.sendMessage(m); } else { mBackgroundHandler.post(this::hideProgress); } } else { HelperUtils.showTargetedAdvice(getActivity(), Configuration.ADVICE_TEXT_SEARCH, R.string.advice_text_search, mViews.searchFooter, false); } }
Example 19
Source File: FileUtils.java From L.TileLayer.Cordova with MIT License | 4 votes |
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = activity.getIntent().getStringExtra("androidpersistentfilelocation"); if (location == null) { location = "compatibility"; } tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. new File(tempRoot).mkdirs(); new File(persistentRoot).mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", cordova, tempRoot)); this.registerFilesystem(new LocalFilesystem("persistent", cordova, persistentRoot)); this.registerFilesystem(new ContentFilesystem(cordova, webView)); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { Log.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
Example 20
Source File: PermissionsActivity.java From UCDLive_Android with MIT License | 3 votes |
public static void startActivityForResult(Activity activity, int requestCode, String... permissions) { Intent intent = new Intent(activity, PermissionsActivity.class); EXTRA_PERMISSIONS = activity.getPackageName() + ".extra_permission"; intent.putExtra(EXTRA_PERMISSIONS, permissions); ActivityCompat.startActivityForResult(activity, intent, requestCode, null); }