private void appInviteFacebook() { String appLinkUrl, previewImageUrl; Context context = ActivityMain.this; //appLinkUrl = "https://play.google.com/store/apps/details?id=" + context.getPackageName(); appLinkUrl = context.getString(R.string.facebook_app_url); previewImageUrl = "http://protoolapps.com/static/media/uploads/protoolapps.com/playstore-icon.png"; if (AppInviteDialog.canShow()) { AppInviteContent content = new AppInviteContent.Builder() .setApplinkUrl(appLinkUrl) .setPreviewImageUrl(previewImageUrl) .build(); AppInviteDialog.show(this, content); } }
@Override public void presentChannelInterface(InviteChannel inviteChannel, InvitePackage invitePackage, final InviteCallback callback) { if (isConnected()) { AppInviteContent.Builder contentBuilder = new AppInviteContent.Builder(); contentBuilder.setApplinkUrl(invitePackage.getReferralUrl()); if (invitePackage.getImageUrl() != null && invitePackage.getImage() != null) { contentBuilder.setPreviewImageUrl(invitePackage.getImageUrl()); } AppInviteContent sharedContent = contentBuilder.build(); AppInviteDialog appInviteDialog = new AppInviteDialog(_activity); appInviteDialog.registerCallback(_callbackManager, new FacebookCallback<AppInviteDialog.Result>() { @Override public void onSuccess(AppInviteDialog.Result result) { callback.onComplete(); } @Override public void onCancel() { callback.onCancel(); } @Override public void onError(FacebookException facebookException) { callback.onError(facebookException); } } ); appInviteDialog.show(sharedContent); } else { onError("Can't reach Facebook. No internet connection.", callback); } }
@Override protected void onCreate(Bundle savedInstanceState) { sharedPreferences = getSharedPreferences("MOVEALARM_PREFERENCE", Context.MODE_PRIVATE); super.onCreate(savedInstanceState); usermanagemnent = UserManagement.instance(); if(UserManagement.instance().wantLogout){ LoginManager.getInstance().logOut(); UserManagement.instance().userlogout(); } FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); setContentView(R.layout.activity_login); if (FriendManagement.wantmorefriend) { FriendManagement.wantmorefriend = false; String appLinkUrl, previewImageUrl; appLinkUrl = "https://fb.me/888833747879377"; previewImageUrl = "blob:https%3A//drive.google.com/a0c8eb9e-ba93-4ab1-a39d-4e0520e29df0"; if (AppInviteDialog.canShow()) { AppInviteContent content = new AppInviteContent.Builder() .setApplinkUrl(appLinkUrl) .setPreviewImageUrl(previewImageUrl) .build(); AppInviteDialog.show(this, content); } finish(); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } progressBar = (ProgressBar)findViewById(R.id.progressbar); guest = (ImageView)findViewById(R.id.guest); fake = (ImageView)findViewById(R.id.fake); progressBar.setVisibility(View.GONE); loginButton = (LoginButton) findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList("user_birthday, public_profile, email, user_friends, read_custom_friendlists")); loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { user_id = loginResult.getAccessToken().getUserId(); Log.i("USER ID", user_id); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString("facebook_id", user_id); editor.commit(); if (loginResult.getAccessToken() != null) { Set<String> deniedPermissions = loginResult.getRecentlyDeniedPermissions(); } progressBar.setVisibility(View.VISIBLE); guest.setClickable(false); loginButton.setClickable(false); fake.setBackgroundColor(Color.parseColor("#70000000")); setUserInfo(); } @Override public void onCancel() { Log.i("TAG2", "cancel"); info.setText("Login attempt cancelled."); } @Override public void onError(FacebookException e) { Log.i("TAG2", "error"); info.setText("Login attempt failed."); } }); }
@Override public boolean isAvailableForDevice(InviteChannel inviteChannel) { return AppInviteDialog.canShow(); }
@Override public void inviteFriends(String appLinkUrl, String previewImageUrl, final Callback cb) { if (AndroidNativeUtil.getActivity() == null) { throw new RuntimeException("Cannot invite friends while running in the background."); } if (AppInviteDialog.canShow()) { AppInviteContent content = new AppInviteContent.Builder() .setApplinkUrl(appLinkUrl) .setPreviewImageUrl(previewImageUrl) .build(); final CodenameOneActivity activity = (CodenameOneActivity) AndroidNativeUtil.getActivity(); if(cb == null){ AppInviteDialog.show(activity, content); }else{ AppInviteDialog appInviteDialog = new AppInviteDialog(activity); final CallbackManager mCallbackManager = CallbackManager.Factory.create(); activity.setIntentResultListener(new IntentResultListener() { @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { mCallbackManager.onActivityResult(requestCode, resultCode, data); activity.restoreIntentResultListener(); } }); appInviteDialog.registerCallback(mCallbackManager, new FacebookCallback<AppInviteDialog.Result>() { @Override public void onSuccess(AppInviteDialog.Result result) { Display.getInstance().callSerially(new Runnable() { @Override public void run() { cb.onSucess(null); } }); } @Override public void onCancel() { Display.getInstance().callSerially(new Runnable() { @Override public void run() { cb.onError(null, null, -1, "User Cancelled"); } }); } @Override public void onError(final FacebookException e) { Display.getInstance().callSerially(new Runnable() { @Override public void run() { cb.onError(null, e, 0, e.getMessage()); } }); } }); appInviteDialog.show(content); } } }