List of usage examples for android.content.pm PackageManager getApplicationInfo
public abstract ApplicationInfo getApplicationInfo(String packageName, @ApplicationInfoFlags int flags) throws NameNotFoundException;
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.notification.NotificationClient.java
private int getNotificationIconResourceId(final String drawableResourceName) { final PackageManager packageManager = pinpointContext.getApplicationContext().getPackageManager(); try {/*from w ww . j a v a2 s .co m*/ final String packageName = pinpointContext.getApplicationContext().getPackageName(); final ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA); final Resources resources = packageManager.getResourcesForApplication(applicationInfo); if (drawableResourceName != null) { final int resId = resources.getIdentifier(drawableResourceName, "drawable", packageName); if (resId != INVALID_RESOURCE) { return resId; } } return applicationInfo.icon; } catch (final PackageManager.NameNotFoundException ex) { log.error("Can't find icon for our application package.", ex); // 0 is an invalid resource id, so use it to indicate failure to // retrieve the resource. return INVALID_RESOURCE; } }
From source file:org.navitproject.navit.Navit.java
private boolean extractRes(String resname, String result) { boolean needs_update = false; Log.e(TAG, "Res Name " + resname + ", result " + result); int id = NavitResources.getIdentifier(resname, "raw", NAVIT_PACKAGE_NAME); Log.e(TAG, "Res ID " + id); if (id == 0)// ww w .jav a 2 s. co m return false; File resultfile = new File(result); if (!resultfile.exists()) { needs_update = true; File path = resultfile.getParentFile(); if (!path.exists() && !resultfile.getParentFile().mkdirs()) return false; } else { PackageManager pm = getPackageManager(); ApplicationInfo appInfo; long apkUpdateTime = 0; try { appInfo = pm.getApplicationInfo(NAVIT_PACKAGE_NAME, 0); apkUpdateTime = new File(appInfo.sourceDir).lastModified(); } catch (NameNotFoundException e) { Log.e(TAG, "Could not read package infos"); e.printStackTrace(); } if (apkUpdateTime > resultfile.lastModified()) needs_update = true; } if (needs_update) { Log.e(TAG, "Extracting resource"); try { InputStream resourcestream = NavitResources.openRawResource(id); FileOutputStream resultfilestream = new FileOutputStream(resultfile); byte[] buf = new byte[1024]; int i = 0; while ((i = resourcestream.read(buf)) != -1) { resultfilestream.write(buf, 0, i); } resultfilestream.close(); } catch (Exception e) { Log.e(TAG, "Exception " + e.getMessage()); return false; } } return true; }
From source file:com.ccxt.whl.DemoApplication.java
private String getAppName(int pID) { String processName = null;/*from w ww .j ava 2 s. c om*/ ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List l = am.getRunningAppProcesses(); Iterator i = l.iterator(); PackageManager pm = this.getPackageManager(); while (i.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo) (i.next()); try { if (info.pid == pID) { CharSequence c = pm.getApplicationLabel( pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA)); // Log.d("Process", "Id: "+ info.pid +" ProcessName: "+ // info.processName +" Label: "+c.toString()); // processName = c.toString(); processName = info.processName; return processName; } } catch (Exception e) { // Log.d("Process", "Error>> :"+ e.toString()); } } return processName; }
From source file:com.android.messaging.util.PhoneUtils.java
/** * Returns the name of the default SMS app, or the empty string if there is * an error or there is no default app (e.g. JB and below). *//*from ww w . ja va 2 s. c o m*/ public String getDefaultSmsAppLabel() { if (OsUtil.isAtLeastKLP()) { final String packageName = Telephony.Sms.getDefaultSmsPackage(mContext); final PackageManager pm = mContext.getPackageManager(); try { final ApplicationInfo appInfo = pm.getApplicationInfo(packageName, 0); return pm.getApplicationLabel(appInfo).toString(); } catch (NameNotFoundException e) { // Fall through and return empty string } } return ""; }
From source file:com.nbplus.vbroadlauncher.HomeLauncherActivity.java
protected boolean checkAccessedUsageStats() { try {/*w w w . j a v a2s. co m*/ PackageManager packageManager = getPackageManager(); ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0); AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE); int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName); return (mode == AppOpsManager.MODE_ALLOWED); } catch (PackageManager.NameNotFoundException e) { return false; } }
From source file:com.localytics.phonegap.LocalyticsPlugin.java
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("integrate")) { String localyticsKey = (args.length() == 1 ? args.getString(0) : null); Localytics.integrate(cordova.getActivity().getApplicationContext(), localyticsKey); callbackContext.success();// w ww . j ava 2 s . c o m return true; } else if (action.equals("upload")) { Localytics.upload(); callbackContext.success(); return true; } else if (action.equals("autoIntegrate")) { /* App-key is read from meta-data LOCALYTICS_APP_KEY in AndroidManifest */ Application app = cordova.getActivity().getApplication(); app.registerActivityLifecycleCallbacks( new LocalyticsActivityLifecycleCallbacks(app.getApplicationContext())); callbackContext.success(); return true; } else if (action.equals("openSession")) { Localytics.openSession(); callbackContext.success(); return true; } else if (action.equals("closeSession")) { Localytics.closeSession(); callbackContext.success(); return true; } else if (action.equals("tagEvent")) { if (args.length() == 3) { String name = args.getString(0); if (name != null && name.length() > 0) { JSONObject attributes = null; if (!args.isNull(1)) { attributes = args.getJSONObject(1); } HashMap<String, String> a = null; if (attributes != null && attributes.length() > 0) { a = new HashMap<String, String>(); Iterator<?> keys = attributes.keys(); while (keys.hasNext()) { String key = (String) keys.next(); String value = attributes.getString(key); a.put(key, value); } } int customerValueIncrease = args.getInt(2); Localytics.tagEvent(name, a, customerValueIncrease); callbackContext.success(); } else { callbackContext.error("Expected non-empty name argument."); } } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("tagScreen")) { String name = args.getString(0); if (name != null && name.length() > 0) { Localytics.tagScreen(name); callbackContext.success(); } else { callbackContext.error("Expected non-empty name argument."); } return true; } else if (action.equals("setCustomDimension")) { if (args.length() == 2) { int index = args.getInt(0); String value = null; if (!args.isNull(1)) { value = args.getString(1); } Localytics.setCustomDimension(index, value); callbackContext.success(); } else { callbackContext.error("Expected two arguments."); } return true; } else if (action.equals("getCustomDimension")) { final int index = args.getInt(0); cordova.getThreadPool().execute(new Runnable() { public void run() { String value = Localytics.getCustomDimension(index); callbackContext.success(value); } }); return true; } else if (action.equals("setOptedOut")) { boolean enabled = args.getBoolean(0); Localytics.setOptedOut(enabled); callbackContext.success(); return true; } else if (action.equals("isOptedOut")) { cordova.getThreadPool().execute(new Runnable() { public void run() { boolean enabled = Localytics.isOptedOut(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled)); } }); return true; } else if (action.equals("setProfileAttribute")) { if (args.length() == 3) { String errorString = null; String attributeName = args.getString(0); Object attributeValue = args.get(1); String scope = args.getString(2); if (attributeValue instanceof Integer) { Localytics.setProfileAttribute(attributeName, (Integer) attributeValue, getProfileScope(scope)); } else if (attributeValue instanceof String) { Localytics.setProfileAttribute(attributeName, (String) attributeValue, getProfileScope(scope)); } else if (attributeValue instanceof Date) { Localytics.setProfileAttribute(attributeName, (Date) attributeValue, getProfileScope(scope)); } else if (attributeValue instanceof JSONArray) { JSONArray array = (JSONArray) attributeValue; Object item = getInitialItem(array); if (item instanceof Integer) { long[] longs = buildLongArray(array); if (longs != null) { Localytics.setProfileAttribute(attributeName, longs, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else if (item instanceof String) { if (parseISO8601Date((String) item) != null) { Date[] dates = buildDateArray(array); if (dates != null) { Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else { String[] strings = buildStringArray(array); if (strings != null) { Localytics.addProfileAttributesToSet(attributeName, strings, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } } } else { errorString = ERROR_UNSUPPORTED_TYPE; } if (errorString != null) { callbackContext.error(errorString); } else { callbackContext.success(); } } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("addProfileAttributesToSet")) { if (args.length() == 3) { String errorString = null; String attributeName = args.getString(0); Object attributeValue = args.get(1); String scope = args.getString(2); if (attributeValue instanceof JSONArray) { JSONArray array = (JSONArray) attributeValue; Object item = getInitialItem(array); if (item instanceof Integer) { long[] longs = buildLongArray(array); if (longs != null) { Localytics.addProfileAttributesToSet(attributeName, longs, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else if (item instanceof String) { // Check if date string first if (parseISO8601Date((String) item) != null) { Date[] dates = buildDateArray(array); if (dates != null) { Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else { String[] strings = buildStringArray(array); if (strings != null) { Localytics.addProfileAttributesToSet(attributeName, strings, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } } } else { errorString = ERROR_UNSUPPORTED_TYPE; } if (errorString != null) { callbackContext.error(errorString); } else { callbackContext.success(); } } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("removeProfileAttributesFromSet")) { if (args.length() == 3) { String errorString = null; String attributeName = args.getString(0); Object attributeValue = args.get(1); String scope = args.getString(2); if (attributeValue instanceof JSONArray) { JSONArray array = (JSONArray) attributeValue; Object item = getInitialItem(array); if (item instanceof Integer) { long[] longs = buildLongArray(array); if (longs != null) { Localytics.removeProfileAttributesFromSet(attributeName, longs, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else if (item instanceof String) { if (parseISO8601Date((String) item) != null) { Date[] dates = buildDateArray(array); if (dates != null) { Localytics.addProfileAttributesToSet(attributeName, dates, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } else { String[] strings = buildStringArray(array); if (strings != null) { Localytics.addProfileAttributesToSet(attributeName, strings, getProfileScope(scope)); } else { errorString = ERROR_INVALID_ARRAY; } } } } else { errorString = ERROR_UNSUPPORTED_TYPE; } if (errorString != null) { callbackContext.error(errorString); } else { callbackContext.success(); } } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("incrementProfileAttribute")) { if (args.length() == 3) { String attributeName = args.getString(0); long incrementValue = args.getLong(1); String scope = args.getString(2); Localytics.incrementProfileAttribute(attributeName, incrementValue, getProfileScope(scope)); } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("decrementProfileAttribute")) { if (args.length() == 3) { String attributeName = args.getString(0); long decrementValue = args.getLong(1); String scope = args.getString(2); Localytics.decrementProfileAttribute(attributeName, decrementValue, getProfileScope(scope)); } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("deleteProfileAttribute")) { if (args.length() == 2) { String attributeName = args.getString(0); String scope = args.getString(1); Localytics.deleteProfileAttribute(attributeName, getProfileScope(scope)); } else { callbackContext.error("Expected three arguments."); } return true; } else if (action.equals("setIdentifier")) { if (args.length() == 2) { String key = args.getString(0); if (key != null && key.length() > 0) { String value = null; if (!args.isNull(1)) { value = args.getString(1); } Localytics.setIdentifier(key, value); callbackContext.success(); } else { callbackContext.error("Expected non-empty key argument."); } } else { callbackContext.error("Expected two arguments."); } return true; } else if (action.equals("setCustomerId")) { String id = null; if (!args.isNull(0)) { id = args.getString(0); } Localytics.setCustomerId(id); callbackContext.success(); return true; } else if (action.equals("setCustomerFullName")) { String fullName = null; if (!args.isNull(0)) { fullName = args.getString(0); } Localytics.setCustomerFullName(fullName); callbackContext.success(); return true; } else if (action.equals("setCustomerFirstName")) { String firstName = null; if (!args.isNull(0)) { firstName = args.getString(0); } Localytics.setCustomerFirstName(firstName); callbackContext.success(); return true; } else if (action.equals("setCustomerLastName")) { String lastName = null; if (!args.isNull(0)) { lastName = args.getString(0); } Localytics.setCustomerLastName(lastName); callbackContext.success(); return true; } else if (action.equals("setCustomerEmail")) { String email = null; if (!args.isNull(0)) { email = args.getString(0); } Localytics.setCustomerEmail(email); callbackContext.success(); return true; } else if (action.equals("setLocation")) { if (args.length() == 2) { Location location = new Location(""); location.setLatitude(args.getDouble(0)); location.setLongitude(args.getDouble(1)); Localytics.setLocation(location); callbackContext.success(); } else { callbackContext.error("Expected two arguments."); } return true; } else if (action.equals("registerPush")) { String senderId = null; try { PackageManager pm = cordova.getActivity().getPackageManager(); ApplicationInfo ai = pm.getApplicationInfo(cordova.getActivity().getPackageName(), PackageManager.GET_META_DATA); Bundle metaData = ai.metaData; senderId = metaData.getString(PROP_SENDER_ID); } catch (PackageManager.NameNotFoundException e) { //No-op } Localytics.registerPush(senderId); callbackContext.success(); return true; } else if (action.equals("setPushDisabled")) { boolean enabled = args.getBoolean(0); Localytics.setPushDisabled(enabled); callbackContext.success(); return true; } else if (action.equals("isPushDisabled")) { cordova.getThreadPool().execute(new Runnable() { public void run() { boolean enabled = Localytics.isPushDisabled(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled)); } }); return true; } else if (action.equals("setTestModeEnabled")) { boolean enabled = args.getBoolean(0); Localytics.setTestModeEnabled(enabled); callbackContext.success(); return true; } else if (action.equals("isTestModeEnabled")) { cordova.getThreadPool().execute(new Runnable() { public void run() { boolean enabled = Localytics.isTestModeEnabled(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled)); } }); return true; } else if (action.equals("setInAppMessageDismissButtonImageWithName")) { //No-op return true; } else if (action.equals("setInAppMessageDismissButtonLocation")) { //No-op return true; } else if (action.equals("getInAppMessageDismissButtonLocation")) { //No-op return true; } else if (action.equals("triggerInAppMessage")) { //No-op return true; } else if (action.equals("dismissCurrentInAppMessage")) { //No-op return true; } else if (action.equals("setLoggingEnabled")) { boolean enabled = args.getBoolean(0); Localytics.setLoggingEnabled(enabled); callbackContext.success(); return true; } else if (action.equals("isLoggingEnabled")) { cordova.getThreadPool().execute(new Runnable() { public void run() { boolean enabled = Localytics.isLoggingEnabled(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, enabled)); } }); return true; } else if (action.equals("setSessionTimeoutInterval")) { int seconds = args.getInt(0); Localytics.setSessionTimeoutInterval(seconds); callbackContext.success(); return true; } else if (action.equals("getSessionTimeoutInterval")) { cordova.getThreadPool().execute(new Runnable() { public void run() { long timeout = Localytics.getSessionTimeoutInterval(); callbackContext.success(Long.valueOf(timeout).toString()); } }); return true; } else if (action.equals("getInstallId")) { cordova.getThreadPool().execute(new Runnable() { public void run() { String result = Localytics.getInstallId(); callbackContext.success(result); } }); return true; } else if (action.equals("getAppKey")) { cordova.getThreadPool().execute(new Runnable() { public void run() { String result = Localytics.getAppKey(); callbackContext.success(result); } }); return true; } else if (action.equals("getLibraryVersion")) { cordova.getThreadPool().execute(new Runnable() { public void run() { String result = Localytics.getLibraryVersion(); callbackContext.success(result); } }); return true; } return false; }
From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if all custom attributes are defined if (!checkTheming()) { finish();/*from w w w . jav a2 s . c o m*/ return; } /* * Check if we have the READ_CONTACTS permission, if not --> terminate. */ try { int pid = android.os.Process.myPid(); PackageManager pckMgr = getPackageManager(); int uid = pckMgr.getApplicationInfo(getComponentName().getPackageName(), PackageManager.GET_META_DATA).uid; enforcePermission(Manifest.permission.READ_CONTACTS, pid, uid, "Contact permission hasn't been granted to this app, terminating."); } catch (PackageManager.NameNotFoundException | SecurityException e) { Log.e(getClass().getSimpleName(), e.getMessage()); finish(); return; } mDefaultTitle = "Select Contacts"; mThemeResId = R.style.Theme_Light; Intent intent = getIntent(); if (savedInstanceState == null) { // /* // * Retrieve default title used if no contacts are selected. // */ // try { // PackageManager pkMgr = getPackageManager(); // ActivityInfo activityInfo = pkMgr.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); // mDefaultTitle = activityInfo.loadLabel(pkMgr).toString(); // } // catch (PackageManager.NameNotFoundException ignore) { // mDefaultTitle = getTitle().toString(); // } if (intent.hasExtra(EXTRA_PRESELECTED_CONTACTS)) { Collection<Long> preselectedContacts = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_CONTACTS); mSelectedContactIds.addAll(preselectedContacts); } if (intent.hasExtra(EXTRA_PRESELECTED_GROUPS)) { Collection<Long> preselectedGroups = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_GROUPS); mSelectedGroupIds.addAll(preselectedGroups); } // mThemeResId = intent.getIntExtra(EXTRA_THEME, R.style.ContactPicker_Theme_Light); } else { // mDefaultTitle = savedInstanceState.getString("mDefaultTitle"); // // mThemeResId = savedInstanceState.getInt("mThemeResId"); // Retrieve selected contact and group ids. try { mSelectedContactIds = (HashSet<Long>) savedInstanceState.getSerializable(CONTACT_IDS); mSelectedGroupIds = (HashSet<Long>) savedInstanceState.getSerializable(GROUP_IDS); } catch (ClassCastException ignore) { } } /* * Retrieve ContactPictureType. */ String enumName = intent.getStringExtra(EXTRA_CONTACT_BADGE_TYPE); mBadgeType = ContactPictureType.lookup(enumName); /* * Retrieve SelectContactsLimit. */ mSelectContactsLimit = intent.getIntExtra(EXTRA_SELECT_CONTACTS_LIMIT, 0); /* * Retrieve ShowCheckAll. */ mShowCheckAll = mSelectContactsLimit > 0 ? false : intent.getBooleanExtra(EXTRA_SHOW_CHECK_ALL, true); /* * Retrieve OnlyWithPhoneNumbers. */ mOnlyWithPhoneNumbers = intent.getBooleanExtra(EXTRA_ONLY_CONTACTS_WITH_PHONE, false); /* * Retrieve LimitReachedMessage. */ String limitMsg = intent.getStringExtra(EXTRA_LIMIT_REACHED_MESSAGE); if (limitMsg != null) { mLimitReachedMessage = limitMsg; } else { mLimitReachedMessage = getString(R.string.cp_limit_reached, mSelectContactsLimit); } /* * Retrieve ContactDescription. */ enumName = intent.getStringExtra(EXTRA_CONTACT_DESCRIPTION); mDescription = ContactDescription.lookup(enumName); mDescriptionType = intent.getIntExtra(EXTRA_CONTACT_DESCRIPTION_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME); /* * Retrieve ContactSortOrder. */ enumName = intent.getStringExtra(EXTRA_CONTACT_SORT_ORDER); mSortOrder = ContactSortOrder.lookup(enumName); setTheme(mThemeResId); setContentView(R.layout.cp_contact_tab_layout); // initialize TabLayout TabLayout tabLayout = (TabLayout) findViewById(R.id.tabContent); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); TabLayout.Tab tabContacts = tabLayout.newTab(); tabContacts.setText(R.string.cp_contact_tab_title); tabLayout.addTab(tabContacts); TabLayout.Tab tabGroups = tabLayout.newTab(); tabGroups.setText(R.string.cp_group_tab_title); tabLayout.addTab(tabGroups); // initialize ViewPager final ViewPager viewPager = (ViewPager) findViewById(R.id.tabPager); mAdapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount(), mSortOrder, mBadgeType, mDescription, mDescriptionType); viewPager.setAdapter(mAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
From source file:com.adwhirl.AdWhirlLayout.java
protected String getAdWhirlKey(Context context) { final String packageName = context.getPackageName(); final String activityName = context.getClass().getName(); final PackageManager pm = context.getPackageManager(); Bundle bundle = null;//from w w w . j ava 2 s .c om // Attempts to retrieve Activity-specific AdWhirl key first. If not // found, retrieve Application-wide AdWhirl key. try { ActivityInfo activityInfo = pm.getActivityInfo(new ComponentName(packageName, activityName), PackageManager.GET_META_DATA); bundle = activityInfo.metaData; if (bundle != null) { return bundle.getString(AdWhirlLayout.ADWHIRL_KEY); } } catch (NameNotFoundException exception) { // Activity cannot be found. Shouldn't be here. return null; } try { ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); bundle = appInfo.metaData; if (bundle != null) { return bundle.getString(AdWhirlLayout.ADWHIRL_KEY); } } catch (NameNotFoundException exception) { // Application cannot be found. Shouldn't be here. return null; } return null; }
From source file:com.nuvolect.deepdive.probe.DecompileApk.java
/** * Copy the specific APK to working folder. * Return a link to the parent folder.//from w w w . j a v a 2 s . co m * @return */ public JSONObject extractApk() { JSONObject wrapper = new JSONObject(); try { wrapper.put("extract_apk_status", 0);// 0==Start with failed file copy m_progressStream.putStream("Extract APK starting"); PackageManager pm = m_ctx.getPackageManager(); ApplicationInfo applicationInfo = pm.getApplicationInfo(m_packageName, PackageManager.GET_META_DATA); java.io.File inputFile = new File(applicationInfo.publicSourceDir); InputStream inputStream = new FileInputStream(inputFile); OutputStream outputStream = m_apkFile.getOutputStream(); int bytes_copied = Util.copyFile(inputStream, outputStream); String formatted_count = NumberFormat.getNumberInstance(Locale.US).format(bytes_copied); m_progressStream.putStream("Extract APK complete, " + formatted_count + " bytes"); wrapper.put("extract_apk_status", 1); // Change to success if we get here wrapper.put("extract_apk_url", m_appFolderUrl); } catch (PackageManager.NameNotFoundException | JSONException | IOException e) { LogUtil.logException(LogUtil.LogType.DECOMPILE, e); m_progressStream.putStream(e.toString()); m_progressStream.putStream("Extract APK failed"); } return wrapper; }
From source file:org.apache.cordova.AndroidWebView.java
/** * Initialize webview.//from w ww. jav a 2s . com */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setup() { this.setInitialScale(0); this.setVerticalScrollBarEnabled(false); if (shouldRequestFocusOnInit()) { this.requestFocusFromTouch(); } // Enable JavaScript WebSettings settings = this.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); // Set the nav dump for HTC 2.x devices (disabling for ICS, deprecated entirely for Jellybean 4.2) try { Method gingerbread_getMethod = WebSettings.class.getMethod("setNavDump", new Class[] { boolean.class }); String manufacturer = android.os.Build.MANUFACTURER; Log.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB && android.os.Build.MANUFACTURER.contains("HTC")) { gingerbread_getMethod.invoke(settings, true); } } catch (NoSuchMethodException e) { Log.d(TAG, "We are on a modern version of Android, we will deprecate HTC 2.3 devices in 2.8"); } catch (IllegalArgumentException e) { Log.d(TAG, "Doing the NavDump failed with bad arguments"); } catch (IllegalAccessException e) { Log.d(TAG, "This should never happen: IllegalAccessException means this isn't Android anymore"); } catch (InvocationTargetException e) { Log.d(TAG, "This should never happen: InvocationTargetException means this isn't Android anymore."); } //We don't save any form data in the application settings.setSaveFormData(false); settings.setSavePassword(false); // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) Level16Apis.enableUniversalAccess(settings); // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = this.cordova.getActivity().getApplicationContext() .getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabaseEnabled(true); settings.setDatabasePath(databasePath); //Determine whether we're in debug or release mode, and turn on Debugging! try { final String packageName = this.cordova.getActivity().getPackageName(); final PackageManager pm = this.cordova.getActivity().getPackageManager(); ApplicationInfo appInfo; appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } } catch (IllegalArgumentException e) { Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! "); e.printStackTrace(); } catch (NameNotFoundException e) { Log.d(TAG, "This should never happen: Your application's package can't be found."); e.printStackTrace(); } settings.setGeolocationDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Enable AppCache // Fix for CB-2282 settings.setAppCacheMaxSize(5 * 1048576); String pathToCache = this.cordova.getActivity().getApplicationContext() .getDir("database", Context.MODE_PRIVATE).getPath(); settings.setAppCachePath(pathToCache); settings.setAppCacheEnabled(true); // Fix for CB-1405 // Google issue 4641 this.updateUserAgentString(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { updateUserAgentString(); } }; this.cordova.getActivity().registerReceiver(this.receiver, intentFilter); } // end CB-1405 pluginManager = new PluginManager(this, this.cordova); jsMessageQueue = new NativeToJsMessageQueue(this, cordova); exposedJsApi = new AndroidExposedJsApi(pluginManager, jsMessageQueue); resourceApi = new CordovaResourceApi(this.getContext(), pluginManager); exposeJsInterface(); }