List of usage examples for android.content.pm PackageManager GET_SIGNATURES
int GET_SIGNATURES
To view the source code for android.content.pm PackageManager GET_SIGNATURES.
Click Source Link
From source file:selfie.time.HelloFacebookSampleActivity.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); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }//w w w.j a v a 2 s. c o m context = this; setContentView(R.layout.main); try { PackageInfo info = context.getPackageManager().getPackageInfo("selfie.time", PackageManager.GET_SIGNATURES); //Your package name here for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } final Typeface mFont = Typeface.createFromAsset(getAssets(), "bg.otf"); final ViewGroup mContainer = (ViewGroup) findViewById(android.R.id.content).getRootView(); Util.setAppFont(mContainer, mFont, false); et = (EditText) findViewById(R.id.editText1); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() { @Override public void onUserInfoFetched(GraphUser user) { HelloFacebookSampleActivity.this.user = user; updateUI(); handlePendingAction(); } }); profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture); greeting = (TextView) findViewById(R.id.greeting); postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Session session = Session.getActiveSession(); if (session != null) onClickPostStatusUpdate(); else Util.showInfoDialog(context, "Please login with Facebook first."); } }); postPhotoButton = (Button) findViewById(R.id.postPhotoButton); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPostPhoto(); } }); pickFriendsButton = (Button) findViewById(R.id.pickFriendsButton); pickFriendsButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { onClickPickFriends(); } }); postSelfieButton = (Button) findViewById(R.id.postSelfieButton); postSelfieButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Session session = Session.getActiveSession(); if (!Util.isNetworkAvailable(context)) Util.showWifiDialog(context); else if (et.getText().toString().length() == 0) Util.showInfoDialog(context, "Please enter text to share with this selfie."); else if (session == null || !session.isOpened()) Util.showInfoDialog(context, "Please login with Facebook first."); else initCapturePhoto(REQUEST_IMAGE_CAPTURE); } }); controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container); final FragmentManager fm = getSupportFragmentManager(); Fragment fragment = fm.findFragmentById(R.id.fragment_container); if (fragment != null) { // If we're being re-created and have a fragment, we need to a) hide the main UI controls and // b) hook up its listeners again. controlsContainer.setVisibility(View.GONE); if (fragment instanceof FriendPickerFragment) { setFriendPickerListeners((FriendPickerFragment) fragment); } else if (fragment instanceof PlacePickerFragment) { setPlacePickerListeners((PlacePickerFragment) fragment); } } // Listen for changes in the back stack so we know if a fragment got popped off because the user // clicked the back button. fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { @Override public void onBackStackChanged() { if (fm.getBackStackEntryCount() == 0) { // We need to re-show our UI. controlsContainer.setVisibility(View.VISIBLE); } } }); // Can we present the share dialog for regular links? canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); // Can we present the share dialog for photos? canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.PHOTOS); }
From source file:com.prad.yahooweather.YahooWeatherActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); if (savedInstanceState != null) { String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY); pendingAction = PendingAction.valueOf(name); }/* www . j av a 2 s . c o m*/ setContentView(R.layout.weather_layout); mImageView = (ImageView) findViewById(R.id.feed_image); // Add code to print out the key hash try { PackageInfo info = getPackageManager().getPackageInfo("com.prad.yahooweather", PackageManager.GET_SIGNATURES); // 9Q4TYYAtIO1mNDFa+Y57Ausm5lE= // Yahoo Weather // App ID: 612655528781332 // App Secret: c6ae83d7cf1aeba1c01045bd37f1db31 for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (Exception e) { } View f = (View) findViewById(R.id.resultTable); f.setVisibility(View.GONE); searchText = (EditText) findViewById(R.id.searchText); searchButton = (Button) findViewById(R.id.search_button); radioGroup = (RadioGroup) findViewById(R.id.searchTypeRadioGroup); mImageView.setLongClickable(true); mImageView.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { // TODO Auto-generated method stub Session session = Session.getActiveSession(); if (session != null) { session.closeAndClearTokenInformation(); } else { Session session2 = Session.openActiveSession(YahooWeatherActivity.this, false, null); if (session2 != null) session2.closeAndClearTokenInformation(); } return true; } }); searchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String searchType = ""; boolean isValidInput = false; hideKeyboard(); String searchString = searchText.getText().toString(); if (searchString == null || "".equals(searchString)) { Toast.makeText(YahooWeatherActivity.this, "Text field is empty. Please enter zip or city name.", Toast.LENGTH_SHORT).show(); } else { if (checkIfValidZip(searchString)) { searchType = "zip"; isValidInput = true; } else { if (checkIfValidCity(searchString)) { searchType = "city"; isValidInput = true; } } } if (isValidInput) { new GetJSON().execute(searchString, searchType, getTempTyep()); } } }); postStatusUpdateButton = (TextView) findViewById(R.id.current_weather); postStatusUpdateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { pendingAction = PendingAction.CURRENT_WEATHER; showFacebookshareDialog("Post Current Weather"); } }); postPhotoButton = (TextView) findViewById(R.id.weather_forecast); postPhotoButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { pendingAction = PendingAction.WEATHER_FORECAST; showFacebookshareDialog("Post Weather Forecast"); } }); canPresentShareDialog = FacebookDialog.canPresentShareDialog(this, FacebookDialog.ShareDialogFeature.SHARE_DIALOG); canPresentShareDialog = true; }
From source file:com.easy.facebook.android.facebook.FBLoginManager.java
private boolean validateAppSignatureForIntent(Activity activity, Intent intent) { ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, 0); if (resolveInfo == null) { return false; }//from ww w .java 2s . co m String packageName = resolveInfo.activityInfo.packageName; PackageInfo packageInfo; try { packageInfo = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (NameNotFoundException e) { return false; } for (Signature signature : packageInfo.signatures) { if (signature.toCharsString().equals(FB_APP_SIGNATURE)) { return true; } } return false; }
From source file:com.becapps.easydownloader.utils.Utils.java
public static int getSigHash(SettingsFragment sf) { try {// w ww .j a v a 2s . c o m Signature[] sigs = sf.getActivity().getPackageManager() .getPackageInfo(sf.getActivity().getPackageName(), PackageManager.GET_SIGNATURES).signatures; for (Signature sig : sigs) { currentHashCode = sig.hashCode(); logger("d", "getSigHash: App signature " + currentHashCode, DEBUG_TAG); } } catch (NameNotFoundException e) { Log.e(DEBUG_TAG, "getSigHash: App signature not found; " + e.getMessage()); } return currentHashCode; }
From source file:library.artaris.cn.library.utils.SystemUtils.java
/** * ???//from w ww.j ava2 s . co m * @param context * @param pkgName * @return */ public static String getSign(Context context, String pkgName) { try { PackageInfo pis = context.getPackageManager().getPackageInfo(pkgName, PackageManager.GET_SIGNATURES); return hexdigest(pis.signatures[0].toByteArray()); } catch (NameNotFoundException e) { throw new RuntimeException(SystemUtils.class.getName() + "the " + pkgName + "'s application not found"); } }
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Returns if the user has a valid copy of X Pass installed. *///from ww w .j a v a 2s . c o m private static boolean hasUnlockKeyInstalled(Context context) { try { // Get our signing key PackageManager manager = context.getPackageManager(); PackageInfo appInfoSeriesGuide = manager.getPackageInfo( context.getApplicationContext().getPackageName(), PackageManager.GET_SIGNATURES); // Try to find the X signing key PackageInfo appInfoSeriesGuideX = manager.getPackageInfo("com.battlelancer.seriesguide.x", PackageManager.GET_SIGNATURES); final String ourKey = appInfoSeriesGuide.signatures[0].toCharsString(); final String xKey = appInfoSeriesGuideX.signatures[0].toCharsString(); return ourKey.equals(xKey); } catch (NameNotFoundException e) { // Expected exception that occurs if the package is not present. } return false; }
From source file:com.skubit.android.billing.BillingServiceBinder.java
private PackageInfo getPackageInfo(String packageName) { try {//from w w w.j a v a 2s . c om return mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); } catch (PackageManager.NameNotFoundException localNameNotFoundException) { } return null; }
From source file:kr.co.sangcomz.facebooklogin.HelloFacebookSampleActivity.java
public static void showHashKey(Context context) { try {/*from www . jav a2s .co m*/ PackageInfo info = context.getPackageManager().getPackageInfo("kr.co.sangcomz.facebooklogin", PackageManager.GET_SIGNATURES); //Your package name here for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (PackageManager.NameNotFoundException e) { } catch (NoSuchAlgorithmException e) { } }
From source file:com.vinexs.tool.Utility.java
public static String getKeyHash(Context context) { String keyHash = ""; try {//w w w . j av a 2 s . c om PackageInfo info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT); } } catch (Exception e) { Log.e("Data Encryption", "Fail to get key hash.", e); } return keyHash; }
From source file:com.appdupe.flamer.LoginUsingFacebook.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity);/*from ww w.jav a 2 s .c om*/ /** * This code is required only once, to get the KeyHash, which will be * used in facebook while signing the app. The KeyHash will be displayed * in LogCat. Once the Keyhash has been generated, use it for signing * app, and then comment the code. Replace the package name with your * package name. */ try { PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : info.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT)); } } catch (NameNotFoundException e) { Log.e(TAG, "Exception(NameNotFoundException) : " + e); } catch (NoSuchAlgorithmException e) { Log.e(TAG, "Exception(NoSuchAlgorithmException) : " + e); } res = getResources(); initdata(); context = getApplicationContext(); imagelist = new ArrayList<GellaryData>(); mAdapterForGalery = new HomeAdapter(this, imagelist); galleryforsuprvisore.setAdapter(mAdapterForGalery); getTemplateFromResource(); galleryforsuprvisore.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { // logDebug("onItemSelected "); // try // { System.out.println("Item Selected Position=======>>>" + pos); System.out.println("Item Selected Position=======>>> count" + count); for (int i = 0; i < count; i++) { page_text[i].setTextColor(android.graphics.Color.GRAY); } page_text[pos].setTextColor(android.graphics.Color.BLUE); // } catch (Exception e) // //{ // logError("onItemSelected Exception "+e); // } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS); Session session = Session.getActiveSession(); // logDebug("onCreate session "+session); if (session == null) { // logDebug("onCreate savedInstanceState "+savedInstanceState); if (savedInstanceState != null) { session = Session.restoreSession(this, null, statusCallback, savedInstanceState); // logDebug("onCreate savedInstanceState restore session "+session); } if (session == null) { session = new Session(this); // logDebug("onCreate savedInstanceState create session "+session); } Session.setActiveSession(session); logDebug("onCreate savedInstanceState state session " + session.getState()); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { // session.openForRead(new // Session.OpenRequest(this).setPermissions(Arrays.asList("user_birthday", // "email","user_relationships","user_photos")).setCallback(statusCallback)); } } animeBottomTOUp = AnimationUtils.loadAnimation(this, R.anim.helpscreen_in_to_out); gellarybottom = AnimationUtils.loadAnimation(this, R.anim.helpscreen_in_to_out); gellarybottom.setFillAfter(true); gellarybottom.setAnimationListener(new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } }); updateView(); cd = new ConnectionDetector(getApplicationContext()); if (cd.isConnectingToInternet()) { if (checkPlayServices()) { regid = getRegistrationId(this); if (regid.isEmpty()) { registerInBackground(); } else { logDebug("reg id saved : " + regid); } } else { return; } // LocationManager locationManager = (LocationManager) // getSystemService(LOCATION_SERVICE); // if // (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) // { // newLocationFinder = new LocationFinder(); // newLocationFinder.getLocation(LoginUsingFacebook.this, // mLocationResult); // } else { // showGPSDisabledAlertToUser(); // // } } else { AlertDialogManager.internetConnetionErrorAlertDialog(LoginUsingFacebook.this); } }