List of usage examples for android.content.pm PackageManager getPackageInfo
public abstract PackageInfo getPackageInfo(VersionedPackage versionedPackage, @PackageInfoFlags int flags) throws NameNotFoundException;
From source file:com.tweetlanes.android.App.java
@Override public void onCreate() { Log.d("tweetlanes url fetch", "*** New run"); Log.d("AsyncTaskEx", "*** New run"); Log.d("StatusCache", "*** New run"); super.onCreate(); java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST); java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug"); try {//from www.j a va2 s. com PackageManager packageManager = getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); mAppVersionName = packageInfo.versionName; List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo app : apps) { if (app.packageName != null && app.packageName.equalsIgnoreCase("com.chrislacy.actionlauncher.pro")) { mActionLauncherInstalled = true; break; } } } catch (NameNotFoundException e) { e.printStackTrace(); } mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mPreferences.edit().putInt(SHARED_PREFERENCES_KEY_VERSION, Constant.SHARED_PREFERENCES_VERSION); mAccounts = new ArrayList<AccountDescriptor>(); updateTwitterAccountCount(); SocialNetConstant.Type socialNetType = SocialNetConstant.Type.Twitter; AccountDescriptor currentAccountDescriptor = getCurrentAccount(); if (currentAccountDescriptor != null) { socialNetType = currentAccountDescriptor.getSocialNetType(); if (socialNetType == null) { socialNetType = SocialNetConstant.Type.Twitter; } TwitterManager.initModule(socialNetType, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY, socialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET : ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, currentAccountDescriptor.getOAuthToken(), currentAccountDescriptor.getOAuthSecret(), currentAccountDescriptor.getAccountKey(), mConnectionStatusCallbacks); } else { TwitterManager.initModule(SocialNetConstant.Type.Twitter, ConsumerKeyConstants.TWITTER_CONSUMER_KEY, ConsumerKeyConstants.TWITTER_CONSUMER_SECRET, null, null, null, mConnectionStatusCallbacks); } setLaneDefinitions(socialNetType); AppSettings.initModule(this); }
From source file:system.info.reader.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); resolutions = Properties.resolution(dm); Properties.resolution = resolutions[0] + "*" + resolutions[1]; int tabHeight = 30, tabWidth = 80; if (dm.widthPixels >= 480) { tabHeight = 40;/*from ww w. j a va 2 s . com*/ tabWidth = 120; } tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true); tabHost.addTab( tabHost.newTabSpec("tab1").setIndicator(getString(R.string.brief)).setContent(R.id.PropertyList)); tabHost.addTab( tabHost.newTabSpec("tab2").setIndicator(getString(R.string.online)).setContent(R.id.ViewServer)); tabHost.addTab( tabHost.newTabSpec("tab3").setIndicator(getString(R.string.apps)).setContent(R.id.sViewApps)); tabHost.addTab( tabHost.newTabSpec("tab4").setIndicator(getString(R.string.process)).setContent(R.id.sViewProcess)); tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator("Services").setContent(R.id.sViewCpu)); tabHost.addTab(tabHost.newTabSpec("tab6").setIndicator("Tasks").setContent(R.id.sViewMem)); //tabHost.addTab(tabHost.newTabSpec("tab7") // .setIndicator("Vending") // .setContent(R.id.sViewDisk)); AppsText = (TextView) findViewById(R.id.TextViewApps); ProcessText = (TextView) findViewById(R.id.TextViewProcess); ServiceText = (TextView) findViewById(R.id.TextViewCpu); TaskText = (TextView) findViewById(R.id.TextViewMem); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(tabWidth, tabHeight); for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) tabHost.getTabWidget().getChildAt(i).setLayoutParams(lp); properList = (ListView) findViewById(R.id.PropertyList); Properties.properListItem = new ArrayList<HashMap<String, Object>>(); properListItemAdapter = new SimpleAdapter(this, Properties.properListItem, R.layout.property_list, new String[] { "ItemTitle", "ItemText" }, new int[] { R.id.ItemTitle, R.id.ItemText }); properList.setAdapter(properListItemAdapter); properList.setOnItemClickListener(mpropertyCL); //will support app list later //appList = (ListView)findViewById(R.id.AppList); //Properties.appListItem = new ArrayList<HashMap<String, Object>>(); //SimpleAdapter appListItemAdapter = new SimpleAdapter(this, Properties.appListItem, // R.layout.app_list, // new String[] {"ItemTitle", "ItemText"}, // new int[] {R.id.ItemTitle, R.id.ItemText} // ); //appList.setAdapter(appListItemAdapter); serverWeb = (WebView) findViewById(R.id.ViewServer); WebSettings webSettings = serverWeb.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setUserAgentString("sys.info.trial" + versionCode); webSettings.setTextSize(WebSettings.TextSize.SMALLER); serverWeb.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return false;//this will not launch browser when redirect. } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } }); PackageManager pm = getPackageManager(); try { PackageInfo pi = pm.getPackageInfo("sys.info.trial", 0); version = "v" + pi.versionName; versionCode = pi.versionCode; List<PackageInfo> apps = getPackageManager().getInstalledPackages(0); nApk = Integer.toString(apps.size()); apklist = ""; for (PackageInfo app : apps) { apklist += app.packageName + "\t(" + app.versionName + ")\n"; } } catch (NameNotFoundException e) { e.printStackTrace(); } showDialog(0); initPropList(); //refresh(); PageTask task = new PageTask(); task.execute(""); }
From source file:at.aec.solutions.checkmkagent.AgentService.java
private void writeHeader(PrintWriter _out) { // Process ps = Runtime.getRuntime().exec("ps"); // //from ww w .ja va 2s. com // BufferedReader is = new BufferedReader(new InputStreamReader(ps.getInputStream())); // String line; // while ((line = is.readLine()) != null) // { // System.out.println(line); // } PackageManager m = getPackageManager(); String s = getPackageName(); try { PackageInfo p = m.getPackageInfo(s, 0); s = p.applicationInfo.dataDir; } catch (NameNotFoundException e) { Log.w("yourtag", "Error Package name not found ", e); } _out.write("<<<check_mk>>>" + NEWLINE); _out.write("Version: 1.2.0p2" + NEWLINE); _out.write("AgentOS: android" + NEWLINE); _out.write("PluginsDirectory: " + s + "/plugins" + NEWLINE); _out.write("LocalDirectory: " + s + "/local" + NEWLINE); _out.write("AgentDirectory: " + s + NEWLINE); _out.write("OnlyFrom: " + NEWLINE); }
From source file:com.inrista.loggliest.Loggly.java
private Loggly(Context context, String token, String logglyTag, String logglyUrl, int uploadIntervalSecs, int uploadIntervalLogCount, int idleSecs, boolean appendDefaultInfo, HashMap<String, String> stickyInfo, int maxSizeOnDisk) { mContext = context;//from w w w . ja v a 2 s.c o m mToken = token; mLogglyTag = logglyTag; mUploadIntervalSecs = uploadIntervalSecs; mUploadIntervalLogCount = uploadIntervalLogCount; mIdleSecs = idleSecs; mAppendDefaultInfo = appendDefaultInfo; mStickyInfo = stickyInfo; mMaxSizeOnDisk = maxSizeOnDisk; mRecentLogFile = recentLogFile(); mDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); PackageManager manager = context.getPackageManager(); try { PackageInfo info = manager.getPackageInfo(context.getPackageName(), 0); mAppVersionName = info.versionName; mAppVersionCode = info.versionCode; } catch (NameNotFoundException e) { } RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(logglyUrl).build(); mBulkLogService = restAdapter.create(IBulkLog.class); start(); }
From source file:com.dafeng.upgradeapp.util.AutoUpdateApk.java
private boolean haveInternetPermissions() { Set<String> required_perms = new HashSet<String>(); required_perms.add("android.permission.INTERNET"); required_perms.add("android.permission.ACCESS_WIFI_STATE"); required_perms.add("android.permission.ACCESS_NETWORK_STATE"); PackageManager pm = context.getPackageManager(); String packageName = context.getPackageName(); int flags = PackageManager.GET_PERMISSIONS; PackageInfo packageInfo = null;/*from www . j av a 2s . c o m*/ try { packageInfo = pm.getPackageInfo(packageName, flags); versionCode = packageInfo.versionCode; } catch (NameNotFoundException e) { // e.printStackTrace(); Log_e(TAG, e.getMessage()); } if (packageInfo.requestedPermissions != null) { for (String p : packageInfo.requestedPermissions) { // Log_v(TAG, "permission: " + p.toString()); required_perms.remove(p); } if (required_perms.size() == 0) { return true; // permissions are in order } // something is missing for (String p : required_perms) { Log_e(TAG, "required permission missing: " + p); } } Log_e(TAG, "INTERNET/WIFI access required, but no permissions are found in Manifest.xml"); return false; }
From source file:com.shafiq.mytwittle.App.java
@Override public void onCreate() { Log.d("mytwittle url fetch", "*** New run"); Log.d("AsyncTaskEx", "*** New run"); Log.d("StatusCache", "*** New run"); super.onCreate(); java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST); java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug"); try {/* w w w . j ava 2 s . c o m*/ PackageManager packageManager = getPackageManager(); PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), 0); mAppVersionNumber = packageInfo.versionCode; mAppVersionName = packageInfo.versionName; List<ApplicationInfo> apps = packageManager.getInstalledApplications(PackageManager.GET_META_DATA); for (ApplicationInfo app : apps) { if (app.packageName != null && app.packageName.equalsIgnoreCase("com.shafiq.actionlauncher.pro")) { // mActionLauncherInstalled = true; break; } } } catch (NameNotFoundException e) { e.printStackTrace(); } mPreferences = PreferenceManager.getDefaultSharedPreferences(this); mPreferences.edit().putInt(SHARED_PREFERENCES_KEY_VERSION, Constant.SHARED_PREFERENCES_VERSION); mAccounts = new ArrayList<AccountDescriptor>(); updateTwitterAccountCount(); SocialNetConstant.Type socialNetType = SocialNetConstant.Type.Twitter; AccountDescriptor currentAccountDescriptor = getCurrentAccount(); if (currentAccountDescriptor != null) { socialNetType = currentAccountDescriptor.getSocialNetType(); if (socialNetType == null) { socialNetType = SocialNetConstant.Type.Twitter; } TwitterManager.initModule(socialNetType, socialNetType == SocialNetConstant.Type.Twitter ? Constant.TWITTER_CONSUMER_KEY : Constant.APPDOTNET_CONSUMER_KEY, socialNetType == SocialNetConstant.Type.Twitter ? Constant.TWITTER_CONSUMER_SECRET : Constant.TWITTER_CONSUMER_SECRET, currentAccountDescriptor.getOAuthToken(), currentAccountDescriptor.getOAuthSecret(), currentAccountDescriptor.getAccountKey(), mConnectionStatusCallbacks); } else { TwitterManager.initModule(SocialNetConstant.Type.Twitter, Constant.TWITTER_CONSUMER_KEY, Constant.TWITTER_CONSUMER_SECRET, null, null, null, mConnectionStatusCallbacks); } setLaneDefinitions(socialNetType); AppSettings.initModule(this); NotificationHelper.initModule(); }
From source file:com.ccxt.whl.DemoApplication.java
public String getVersionName() { try {//w ww. j a v a 2 s .com PackageManager manager = this.getPackageManager(); PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0); String version = info.versionName; return version; } catch (Exception e) { e.printStackTrace(); } return "0"; }
From source file:com.jrummyapps.android.safetynet.SafetyNetHelper.java
@SuppressLint("PackageManagerGetSignatures") private List<String> getApkCertificateDigests() { List<String> apkCertificateDigests = new ArrayList<>(); PackageManager pm = context.getPackageManager(); PackageInfo packageInfo;/*from w w w.j a va 2 s .c om*/ try { packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException wtf) { return apkCertificateDigests; } Signature[] signatures = packageInfo.signatures; for (Signature signature : signatures) { try { MessageDigest md = MessageDigest.getInstance(SHA_256); md.update(signature.toByteArray()); byte[] digest = md.digest(); apkCertificateDigests.add(Base64.encodeToString(digest, Base64.NO_WRAP)); } catch (NoSuchAlgorithmException ignored) { } } return apkCertificateDigests; }
From source file:com.ccxt.whl.DemoApplication.java
public int getVersionCode()//??(?) { try {/*www .ja v a 2 s. c om*/ PackageManager manager = this.getPackageManager(); PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0); return info.versionCode; } catch (Exception e) { return 0; } /* try { PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(), 0); return pi.versionCode; } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); return 0; } */ }