i want display FriendPickerFragment in other fragment but i get empty list please help i cant find any info about thay
this is layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/friend_picker_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
and this is code of fragment
public class HomeFragment extends Fragment {
public static final Uri FRIEND_PICKER = Uri.parse("picker://friend");
private FriendPickerFragment friendPickerFragment;
private static final String TAG = "MainFragment";
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View rootView = inflater.inflate(R.layout.home_fragment, container,
false);
FragmentManager manager = getActivity().getSupportFragmentManager();
Fragment fragmentToShow = null;
friendPickerFragment = new FriendPickerFragment();
friendPickerFragment
.setOnErrorListener(new PickerFragment.OnErrorListener() {
#Override
public void onError(PickerFragment<?> fragment,
FacebookException error) {
Toast.makeText(getActivity(), error.getMessage(),
Toast.LENGTH_SHORT).show();
}
});
friendPickerFragment
.setOnDoneButtonClickedListener(new PickerFragment.OnDoneButtonClickedListener() {
#Override
public void onDoneButtonClicked(PickerFragment<?> fragment) {
Toast.makeText(getActivity(), "Done",
Toast.LENGTH_SHORT).show();
}
});
fragmentToShow = friendPickerFragment;
manager.beginTransaction()
.replace(R.id.friend_picker_fragment, fragmentToShow).commit();
return rootView;
}
#Override
public void onStart() {
super.onStart();
try {
friendPickerFragment.loadData(false);
} catch (Exception ex) {
}
}
}
Facebook has released their new sdk recently to enhance the level of security purpose. The following are the few requirement to use facebook sdk in your app.
check this points first!!
The app should send for the submission and needs to get approval from facebook team to use facebook integration in your own app for listing friends details, accessing locations and to access other special permissions The approval formalities are similar like store listing app in the google play.
The application must be listed in the google play or you could able to integrate it as a test user(i.e like beta testing in google play).
The application should have a proper package name, launching activity, domain name, website url and email.
The app id registered must match with a app name and hash key must be generated for a user developing with different machines
The sample screenshots of the application, description, and app logo needs to be added
Once after the successful approval from the team it will show a active symbol near your app name.
Hope this help!!!
Related
After I successfully launching the following intent:
startActivity(new Intent(Intent.ACTION_VIEW, SOME_URL));
The browser boots up fine and loads the link, but when I try to return to my app the response is sluggish. When the app eventually launches I am met with a black screen, and finally an "Application Not Responding" dialog.
No errors in logcat, no obvious memory issues, nothing to indicate what I did wrong.
The activity that launches the intent is a pretty simple activity, with one fragment:
public class LinkActivity extends AppCompatActivity {
#BindView(R.id.toolbar) Toolbar mToolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_link);
ButterKnife.bind(this);
setSupportActionbar(mToolbar);
setupActionBar();
if(savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, LinkFragment.newInstance()).commit();
}
}
private void setupActionBar() {
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
}
}
And the fragment uses a combination of RxJava, RetroFit and Dagger ‡ to load a list of links:
public class LinkFragment extends Fragment {
#Inject RestService mRestService;
#BindView(R.id.recycler) RecyclerView mRecyclerView;
public static LinkFragment newInstance() {
return new LinkFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_link, container, false);
Injector.getContextComponent().inject(this);
ButterKnife.bind(this, view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext());
mRecyclerView.addItemDecoration(new DividerDecoration(getContext());
mRecyclerView.setAdapter(new LinkAdapter(new ArrayList<>()));
mRestService.getLinks()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onNext, this::onError);
return view;
}
private void onNext(Response<Link> response) [
LinkAdapter adapter = new LinkAdapter(response.data());
adapter.setOnItemClickListener(this::onItemSelected);
mRecyclerView.swapAdapter(adapter, false);
}
private void onError(Throwable throwable) {
Timber.w(throwable, "Failed to obtain links");
}
private void onItemSelected(int position, View view, Link link) {
startActivity(new Intent(Intent.ACTION_VIEW, link.getUri());
}
}
After finding two similar questions with similar answers (How to spot app freeze causes when app is returning from pause state?, Android App freezes after implementing Google Firebase) suggesting that adding Google Play Services might be the culprit, I started to investigate.
Both answers suggested that I remove the following dependency:
compile 'com.android.gms:play-services:9.0.2'
But my application uses that dependency, as well as the following play services dependencies:
compile 'com.google.android.gms:play-services-wearable:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile 'com.google.android.gms:play-services-location:9.0.2'
compile 'com.google.android.gms:play-services-analytics:9.0.2'
Previously, I had been using classes from both the core play services library and the wearable play services library in both my mobile module and my wear module. But I noticed that I had removed the need for the wear module in my mobile module, so I removed it from the mobile module (while keeping it in the wear module). Somehow, this fixed the issue.
I have no clue why, so if anyone has any thoughts, please share.
I've a class MainActivity in which I'm implementing tabs+swipe navigation.
I'm creating different java files for the different fragnents. But the problem is I won't be able to access the values of the variables in MainActivity class.
Right now I've put the fragment class inside the MainActivity class and the app is working fine. How to accomplish the same result if want to create separate java file for separate fragments. This is my fagment class for now :
public static class fragmentLeft extends Fragment{
public fragmentLeft(){}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_left,
container, false);
View.OnClickListener mStartListener = new OnClickListener() {
public void onClick(View v) {
//mChronometer.start();
if (v.getId() == R.id.sign_in_button && !mPlusClient.isConnected()) {
Toast.makeText(getActivity(), "sadf", Toast.LENGTH_LONG).show();
if (mConnectionResult == null) {
mConnectionProgressDialog.show();
} else {
try {
mConnectionResult.startResolutionForResult(getActivity(), REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
// Try connecting again.
Toast.makeText(getActivity(),(CharSequence) e, Toast.LENGTH_LONG).show();
mConnectionResult = null;
mPlusClient.connect();
}
}
}
}
};
rootView.findViewById(R.id.sign_in_button).setOnClickListener(mStartListener);
return rootView;
}
}
These are the variables which are present in the MainActivity class that I want to access from the fragment class :
private static ProgressDialog mConnectionProgressDialog;
private static PlusClient mPlusClient;
private static ConnectionResult mConnectionResult;
Your question is very broad and it is not clear to me exactly what you are looking for. However, what you are seeking to do is relatively straightforward. Take a look at this example (which relates to Google Play Game Services and is rather more complex than what you are seeking to achieve):
Google Play Game Services Multi-Player Device Orietation change kicks user out of room
There are various ways of accessing variables in different fragments and the "recommended" way is probably to implement a listener interface. I often use a simpler approach based on calling a method in a fragment from the activity like this :
myFrag fragment = (myFrag) getSupportFragmentManager().findFragmentByTag("myFrag");
fragment.someMethod();
Another simple approach is to use shared preferences to access the variables directly.
I am searching for a long time and i was not successful yet .
Is there any method to specify the privacy setting while logging into the facebook itself through native login , so that whatever activities i do on facebook through app , posts in facebook with the specified privacy settings .
i am following the below link http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/authenticate/ for setting up the facebook native login .
while searching i found some codes for ios , they have something like
FBSessionDefaultAudienceEveryone
FBSessionDefaultAudienceALL_FRIENDS
FBSessionDefaultAudienceSELF
for privacy settings . But is there anything for android ?
i have added my code ,
public class SplashFragment extends Fragment
{
LoginButton authButton;
//private static final List<String> PERMISSIONS = Arrays.asList("user_photos","email","user_status","friends_status","user_videos","user_checkins","friends_checkins","offline_access","user_actions.news","user_actions:parii_apps","user_events","friends_events");
//private static final List<String> PERMISSION = Arrays.asList("publish_actions","publish_stream","publish_checkins","manage_pages","create_event","rsvp_event");
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.splash, container, false);
authButton = (LoginButton) view.findViewById(R.id.fb_logIn_btn);
authButton.setDefaultAudience(SessionDefaultAudience.ONLY_ME);
Log.e(" setDefaultAudience ", " is "+authButton.getDefaultAudience());
return view;
}
}
this is not working for me
Any related answers are welcomed . Thanks in advance .
Yes.
Default audience only comes into play when you request for publish permissions, which you need to do through a session.requestForNewPublishPermissions() call with a NewPermissionsRequest object.
You can set a default audience on the NewPermissionsRequest object, see the javadocs here: https://developers.facebook.com/docs/reference/android/3.0/Session.NewPermissionsRequest
I've done the tutorials for the Facebook SDK for Android (Especially the "Show Friends"-tutorial).
How can I mark the selected users which i've selected before at the PickerActivity when i click on the "Show Friends"-button again?
I've looked at Facebook SDK's source code and it seems to me that PickerFragment does not give you possibility to reselect previously selected items. Since Facebook SDK is published under Apache License 2.0 and you have access to full source code I guess you could try to modify PickerFragment in such a way that it will have necessary methods.
You have to pass comma separated string with selected facebook user ids in the bundle to the FriendPickerFragment.
Bundle args = new Bundle();
args.putString("com.facebook.android.PickerFragment.Selection", "11111, 2222, 333, already selected facebook ids....");
friendPickerFragment = new FriendPickerFragment(args);
In PickerFragment's onActivityCreated() it will parse the selected ids shows as selected in list. You can see the following code in PickerFragment in FacebookSDK.
selectionStrategy.readSelectionFromBundle(savedInstanceState, SELECTION_BUNDLE_KEY);
Here is a solution which worked for me. I extend a standard FriendPickerFragment.
public class FriendPickerFragment2 extends FriendPickerFragment {
SelectionStrategy selectionStrategy;
String mPreSelectedIDs;
public FriendPickerFragment2(Bundle args)
{
super(args);
}
#Override
SelectionStrategy createSelectionStrategy() {
selectionStrategy = getMultiSelect() ? new MultiSelectionStrategy() : new SingleSelectionStrategy();
return selectionStrategy;
}
public void showInitialSelection()
{
Bundle bundle = new Bundle();
bundle.putString(this.MULTI_SELECT_BUNDLE_KEY, mPreSelectedIDs);
selectionStrategy.readSelectionFromBundle(bundle, this.MULTI_SELECT_BUNDLE_KEY);
adapter.notifyDataSetChanged();
}
public void setInitialSelection(String IDs)
{
mPreSelectedIDs = IDs;
}
}
I use FriendPickerFragment2 as a normal FriendPickerFragment. In OnCreate I do the following:
FragmentManager fm = getSupportFragmentManager();
if (savedInstanceState == null) {
final Bundle args = getIntent().getExtras();
friendPickerFragment = new FriendPickerFragment2(args);
friendPickerFragment.setInitialSelection(pickedUsersString());
fm.beginTransaction()
.add(R.id.friend_picker_fragment, friendPickerFragment)
.commit();
} else {
friendPickerFragment = (FriendPickerFragment2) fm.findFragmentById(R.id.friend_picker_fragment);
}
Here pickedUsersString is a coma separated string of IDs.
The last point is to add one row in the OnStart:
protected void onStart() {
super.onStart();
try {
friendPickerFragment.loadData(false);
friendPickerFragment.showInitialSelection();
} catch (Exception ex) {
onError(ex);
}
}
This solution worked for me.
Good news. In the current SDK version (3.6) the following feature was added:
Added setSelection methods on FriendPickerFragment to allow pre-selection of friends.
Added example use of setSelection API in Friend Picker Sample
FriendPickerFragment has this method:
/**
* Sets the list of friends for pre selection. These friends will be selected by default.
* #param userIds list of friends as ids
*/
public void setSelectionByIds(List<String> userIds) {
preSelectedFriendIds.addAll(userIds);
}
And this method:
public void setSelection(List<GraphUser> graphUsers) {
List<String> userIds = new ArrayList<String>();
for(GraphUser graphUser: graphUsers) {
userIds.add(graphUser.getId());
}
setSelectionByIds(userIds);
}
You should call one of these methods as soon as fragment instantiation:
friendPickerFragment = new FriendPickerFragment(args);
friendPickerFragment.setSelectionByIds(fbIDs);
I used PayPal SDK before in my regular apps. Here are the steps I take in a normal activity
a) on activity's onCreate I make a new thread to init the PayPal library
b) if the init goes well, I create a PayPal button and add it in one of my layouts
c) on PayPal button's onClick I start a new activity for result where the user makes the payment
d) on activity's onActivityResult I check if payment was successfully and save the info
This worked well so far but things get messy when I try to use the same approach on a fragment. My fragment has a layout with 2 EditTexts and a LinearLayout that will host the Paypal button
So far I did it like this:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
context = (MainActivity) getActivity();
View view = inflater.inflate(R.layout.fragment_layout, container, false);
libraryInitializationThread = new Thread() {
#Override
public void run() {
initLibrary();
// The library is initialized so let's create our CheckoutButton and update the UI.
if (PayPal.getInstance().isLibraryInitialized()) {
hRefresh.sendEmptyMessage(INITIALIZE_SUCCESS);
} else {
hRefresh.sendEmptyMessage(INITIALIZE_FAILURE);
}
}
};
libraryInitializationThread.start();
}
private void initLibrary() {
PayPal pp = PayPal.getInstance();
if (pp == null) {
pp = PayPal.initWithAppID(context, getString(R.string.paypal_sandbox_id), PayPal.ENV_SANDBOX);
pp.setLanguage("en_US"); // Sets the language for the library.
pp.setDynamicAmountCalculationEnabled(false);
}
}
So far, on pp = PayPal.initWithAppID I get this error:
java.lang.IllegalStateException: Fragment FragmentPayPal{415f43f8} not attached to Activity
Now my questions are:
where and how should I init the paypal library ?
from my fragment, can I start an activity for result and catch onActivityResult ?
Thank you.
Actually the approach I used in the end was, simply, init paypal library before adding the fragment, in my main hosting activity. In this way it works just fine.