Android Facebook Login "LoginActivity could not be started"
Solution 1
I was able to solve this by removing LoginActivity from my AndroidManifest.xml
<!--Remove this-->
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
and adding
<!--Add this-->
<activity android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
Solution 2
So I had the same issue and fixed it by... setting up my app properly on the Facebook developers page.
Basically my app was missing:
- (Google Play) package name
- class name
- a key hash
Once I fill these in, the error was gone.
Solution 3
Hash Key of the under-developing app and facebook a/c will ask hash key both should be same.
public void getHashkey(){
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(),
PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e1) {
Log.e("Name not found", e1.toString());
} catch (NoSuchAlgorithmException e) {
Log.e("No such an algorithm", e.toString());
} catch (Exception e) {
Log.e("Exception", e.toString());
}
}
call this in your onCreate() of Activity and copy that hash key (which will end with = sign) from log and just register into facebook a/c and u are done.
Antoine Draune
Updated on July 22, 2022Comments
-
Antoine Draune almost 2 years
I have installed and configure everything for link The Facebook SDK to my Android App.
- Facebook SDK is in my project
- I added my APP ID in the Facebook APP ID
- My Android Key Hash is correct and linked on the board of Facebook Dev
- I have the Activity "com.facebook.FacebookActivity" in my Manifest
- I have the Activity "com.facebook.LoginActivity" in my Manifest
- I have the meta-data facebook_app_id set in my Manifest and correct
The Facebook widget Login set
<com.facebook.login.widget.LoginButton android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="30dp" android:layout_marginBottom="30dp" />
My Fragment Class
public class FragmentSetting extends android.support.v4.app.Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); SingletonUserData.setCallbackManager(CallbackManager.Factory.create()); } @Override public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle args) { if (!SingletonUserData.isLogged()) { view = inflater.inflate(R.layout.fragment_logme, container, false); TextView facebook = (TextView) view.findViewById(R.id.LogByFacebook); loginButton = (LoginButton) view.findViewById(R.id.login_button); loginButton.setReadPermissions(Arrays.asList("public_profile", "user_friends", "email")); loginButton.setFragment(this); loginButton.registerCallback(SingletonUserData.getCallbackManager(), new FacebookCallback<LoginResult>() {...});
and
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); SingletonUserData.getCallbackManager().onActivityResult(requestCode, resultCode, data); }
After several hours, I can't find the error. Is it because of the Fragment? I tried in my MainActivityToFragment but I have always the same backtrace, which is:
Log in attempt failed: LoginActivity could not be started at com.facebook.login.LoginManager.startLogin(LoginManager.java:382) at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:250) at com.facebook.login.widget.LoginButton$LoginClickListener.onClick(LoginButton.java:689) at com.facebook.FacebookButtonBase$1.onClick(FacebookButtonBase.java:310)