Android - App crashing without any definite interval of time - android

I am using Facebook SDK in my app but my app crashes after i click on the login button.
But the time is not fixed.
Sometimes it crashes after i have logged in, sometimes at the instant i click on login button, sometimes in between when i am filling out the details for login.
Also can anybody tell me why the shared preferences are not working.
MainActivity.this
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
Facebook fb;
ImageView login;
SharedPreferences sp;
String APP_ID = "123456";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fb = new Facebook(APP_ID);
sp = getPreferences(MODE_PRIVATE);
String access_token = sp.getString("access_token", null);
long expires = sp.getLong("expires", 0);
if (access_token != null) {
fb.setAccessToken(access_token);
}
if (expires != 0) {
fb.setAccessExpires(expires);
}
login = (ImageView) findViewById(R.id.imageView1);
login.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.imageView1) {
fbLogin();
}
}
private void fbLogin() {
if (fb.isSessionValid()) {
Intent i = new Intent(MainActivity.this, com.example.test.Register.class);
startActivity(i);
} else {
fb.authorize(MainActivity.this, new String[] { "email" },
new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
e.printStackTrace();
Toast.makeText(MainActivity.this, "fbError",Toast.LENGTH_SHORT).show();
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
e.printStackTrace();
Toast.makeText(MainActivity.this, "onError",Toast.LENGTH_SHORT).show();
}
#Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Editor editor = sp.edit();
editor.putString("access_token",fb.getAccessToken());
editor.putLong("access_expires",fb.getAccessExpires());
editor.commit();
Intent i = new Intent(MainActivity.this, com.example.test.Register.class);
startActivityForResult(i, RESULT_OK);
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onCancel",Toast.LENGTH_SHORT).show();
}
});
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
fb.authorizeCallback(requestCode, resultCode, data);
}
}
So please can anybody help me to identify :
Why the app is crashing at any time after i click on the the login button.
Why the shared preferences is not working.
Logcat
03-31 00:31:47.459: E/AndroidRuntime(5121): FATAL EXCEPTION: Timer-0
03-31 00:31:47.459: E/AndroidRuntime(5121): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
03-31 00:31:47.459: E/AndroidRuntime(5121): at com.facebook.AppEventsLogger.flushAndWait(AppEventsLogger.java:760)
03-31 00:31:47.459: E/AndroidRuntime(5121): at com.facebook.AppEventsLogger.access$1(AppEventsLogger.java:732)
03-31 00:31:47.459: E/AndroidRuntime(5121): at com.facebook.AppEventsLogger$2.run(AppEventsLogger.java:605)
03-31 00:31:47.459: E/AndroidRuntime(5121): at java.util.Timer$TimerImpl.run(Timer.java:284)
03-31 00:31:47.589: D/OpenGLRenderer(5121): Flushing caches (mode 0)
03-31 00:31:50.319: I/Process(5121): Sending signal. PID: 5121 SIG: 9

About the problem with your shared preferences:
It looks like you look up the wrong key here:
long expires = sp.getLong("expires", 0);
you should change it to:
long expires = sp.getLong("access_expires", 0);
because later you do actually save this in the shared preferences:
editor.putLong("access_expires",fb.getAccessExpires());
editor.commit();
Note: The other problem with the NoClassDefFoundError was solved with this related answer

Related

Can't login second time using asynchronous task

I am trying to login with username and password. If username is correct then goes to another Activity otherwise stay in current Activity.
If I am login the first time it works successfully but second time gives some error.
error.....
04-21 07:41:13.915: E/AndroidRuntime(2125): java.lang.IllegalStateException: Cannot execute task: the task has already been executed (a task can be executed only once)
04-21 07:41:13.915: E/AndroidRuntime(2125): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:578)
04-21 07:41:13.915: E/AndroidRuntime(2125): at android.os.AsyncTask.execute(AsyncTask.java:534)
04-21 07:41:13.915: E/AndroidRuntime(2125): at com.bis.storyanimationapp.LoginActivity$1.onClick(LoginActivity.java:35)
code:
LoginActivity
//enter code here
package com.bis.storyanimationapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import com.bis.storyanimationapp.asynchtask.AsynchTask1;
import com.bis.storyanimationapp.view.LoginView;
import com.example.storyanimationapp.R;
public class LoginActivity extends Activity {
LoginView loginView;
AsynchTask1 objLoginAsycTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
loginView=new LoginView(this);
super.onCreate(savedInstanceState);
setContentView(loginView.getLayoutmain());
objLoginAsycTask=new AsynchTask1(LoginActivity.this,loginView);
loginView.getBtnLogin().setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
objLoginAsycTask.execute("");
//objLoginAsycTask.cancel(true);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
}
AsynchTask1
package com.bis.storyanimationapp.asynchtask;
import android.R.integer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.widget.Toast;
import com.bis.storyanimationapp.LoginActivity;
import com.bis.storyanimationapp.MainActivity;
import com.bis.storyanimationapp.view.LoginView;
public class AsynchTask1 extends AsyncTask<String,integer, String> {
Activity activity;
Context context;
private ProgressDialog signUpProcess;
LoginView view;
// private AsyncInterface asyInter;
public AsynchTask1(Activity activity,LoginView view){
this.activity=activity;
this.view=view;
context=activity.getApplicationContext();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
signUpProcess = ProgressDialog.show(this.activity, "Please Wait !!!",
"Submitting Data For Registration!!!", true, false);
Toast.makeText(context, "inpree ex.",10).show();
}
#Override
protected void onPostExecute(String result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
signUpProcess.dismiss();
Toast.makeText(context,"post",5).show();
myMethod(result);
}
private void myMethod(String result) {
// TODO Auto-generated method stub
if(view.getEdUserName().getText().toString().equals("abc")){
Intent i=new Intent(context,MainActivity.class);
activity.startActivity(i);
//this.activity.finish();
}else{
Toast.makeText(context,"invalid user name",5).show();
// Intent i=new Intent(context,LoginActivity.class);
// activity.startActivity(i);
//
}
}
#Override
protected String doInBackground(String... params) {
return view.getEdUserName().getText().toString();
//return null;
}
}
As #Raghunandan suggest , create a new instance of the asyntask every time:
public void onClick(View v) {
new AsynchTask1().execute("");
}
});
You try this codes :
loginView.getBtnLogin().setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
objLoginAsycTask=new AsynchTask1(LoginActivity.this,loginView);
objLoginAsycTask.execute((Void) null);
}
});
}
AsyncTask instances can only be used one time.
Instead, just call your task like new AsynchTask1().execute("");
From the AsyncTask API docs
Try to create a new instance of AsyncTask every time you log in.
#Override
public void onClick(View v) {
AsyncTask1 at = new AsyncTask1()
at.execute()
}

How to Get friend list from Facebook SDK 3.0 in my Activity

I am new in Facebook integration with android. I've logged in to Facebook in my android application.
So I am creating an app which needs to get the Facebook friends list (the names and the pictures). I Googled but not getting. How can I get the list of friends?
XML file, when button is clicked i want my all list of Facebook friends
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/login_button"/>
<ImageView
android:id="#+id/picturepic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"/>
<Button
android:id="#+id/btn_get_friend_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friends"
android:layout_marginTop="30dip"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
<Button
android:id="#+id/btn_show_access_tokens"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Access Tokens"
android:layout_marginTop="30dip"
android:layout_gravity="center_horizontal"
android:visibility="gone"/>
package com.example.simplelogin1;
import java.io.IOException;
import java.net.MalformedURLException;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener
{
ImageView pic,button;
Facebook fb;
Button btnShowAccessTokens,btnGetFriendList;
private AsyncFacebookRunner mAsyncRunner;
String FILENAME = "AndroidSSO_data";
private SharedPreferences mPrefs;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String APP_ID="";
fb=new Facebook(APP_ID);
btnGetFriendList=(Button) findViewById(R.id.btn_get_friend_list);
btnShowAccessTokens = (Button) findViewById(R.id.btn_show_access_tokens);
button=(ImageView) findViewById(R.id.login);
pic=(ImageView) findViewById(R.id.picturepic);
mAsyncRunner = new AsyncFacebookRunner(fb);
button.setOnClickListener(this);
btnGetFriendList.setOnClickListener(this);
btnShowAccessTokens.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
showAccessTokens();
}
});
updateButtonImage();
}
private void updateButtonImage()
{
// TODO Auto-generated method stub
if(fb.isSessionValid())
{
button.setImageResource(R.drawable.logout_button);
}
else
{
button.setImageResource(R.drawable.login_button);
}
}
#Override
public void onClick(View v)
{
// TODO Auto-generated method stub
if(fb.isSessionValid())
{
try
{
fb.logout(getApplicationContext());
updateButtonImage();
btnShowAccessTokens.setVisibility(View.INVISIBLE);
btnGetFriendList.setVisibility(View.INVISIBLE);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else
{
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null)
{
fb.setAccessToken(access_token);
// Making show access tokens button visible
btnShowAccessTokens.setVisibility(View.VISIBLE);
btnGetFriendList.setVisibility(View.VISIBLE);
Log.d("FB Sessions", "" + fb.isSessionValid());
}
if (expires != 0)
{
fb.setAccessExpires(expires);
}
{
fb.authorize(this,new String[] {"email","publish_stream"} , new DialogListener()
{
#Override
public void onFacebookError(FacebookError e)
{
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "fbError", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(DialogError e)
{
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_SHORT).show();
}
#Override
public void onComplete(Bundle values)
{
// TODO Auto-generated method stub
updateButtonImage();
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",fb.getAccessToken());
editor.putLong("access_expires",fb.getAccessExpires());
editor.commit();
btnShowAccessTokens.setVisibility(View.VISIBLE);
btnGetFriendList.setVisibility(View.VISIBLE);
}
#Override
public void onCancel()
{
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_SHORT).show();
}
});
}
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
fb.authorizeCallback(requestCode, resultCode, data);
}
public void showAccessTokens()
{
String access_token = fb.getAccessToken();
Toast.makeText(getApplicationContext(),"Access Token: " + access_token, Toast.LENGTH_LONG).show();
}
}
My main activity ,,where should i implement getting a friends from Facebook when i clicked button.
after success full login
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
String query="SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
Bundle bundal=new Bundle();
bundal.putString("method", "fql.query");
bundal.putString("query", query);
return bundal;
mAsyncRunner.request(bundal, new RequestListener() {
#Override
public void onComplete(final String response, Object state) {
// TODO Auto-generated method stub
//parse json and get all friends
}
});

Google+ API Activity to Fragment

I'm having trouble with converting my code to fragment
this is my code when my app is still an activity
package com.ronnielp.loginsample2;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.Scopes;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.model.people.Person;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class SignIn extends Activity implements OnClickListener,
ConnectionCallbacks, OnConnectionFailedListener{
private static final int REQUEST_CODE_RESOLVE_ERR = 40;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;
private TextView txtUser;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlusClient =new PlusClient.Builder(this, this, this)
.setScopes(Scopes.PLUS_LOGIN)
.setVisibleActivities("http://schemas.google.com/AddActivity")
.build();
findViewById(R.id.sign_in_button).setOnClickListener(this);
txtUser = (TextView) findViewById(R.id.txtUser);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
mPlusClient.connect();
}
#Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
mPlusClient.disconnect();
}
#Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
mConnectionResult = result;
}
#Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
Person user = mPlusClient.getCurrentPerson();
String acc = mPlusClient.getAccountName();
txtUser.setText(acc);
}
#Override
public void onDisconnected() {
// TODO Auto-generated method stub
}
#Override
public void onClick(View view) {
// TODO Auto-generated method stub
if (view.getId() == R.id.sign_in_button && !mPlusClient.isConnected() && mConnectionResult !=null){
try{
mConnectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e){
mConnectionResult = null;
mPlusClient.connect();
}
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == REQUEST_CODE_RESOLVE_ERR && resultCode == RESULT_OK){
mConnectionResult = null;
mPlusClient.connect();
}
}
}
and when i convert it to fragment my code doesnt work anymore
please help me I'm still a newbie in Android programming
Number of thing may have gone wrong. One issue would be accessing your the childFragmentManager. The manager will not pass the result to the fragment, you have to do that manually in your base Class.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Fragment fragment = (Fragment) getChildFragmentManager().findFragmentByTag(childTag);
if(fragment != null){
fragment.onActivityResult(requestCode, resultCode, intent);
}
}

SharedPreferences ToggleButton not saving

*I've been going nuts with this problem the last few days.I'm trying to use SharedPreferences to allow my users to save the selected option of the in-game audio via the ToggleButton but everytime when I run my app and hit my "Done" button to go back to the main_activity screen and then click on settings again it never saves.I've done some research on this by googling,my book and this site but by many methods I've tried the result is the same.
I'm new to android development let alone app development so as much as I learned these past few weeks this has been a major roadblock for me and I apologize if this question has been covered already on this site but I'm at a real loss on what I'm doing wrong here.
Here is my code from my settings activity.
package com.fullfrontalgames.numberfighter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
public class Settings extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Button Notifications = (Button) findViewById(R.id.Notifications);
Button Done = (Button) findViewById(R.id.done);
Button AccountSettings = (Button) findViewById(R.id.AccountSettings);
final ToggleButton AT = (ToggleButton) findViewById(R.id.AudioToggle);
AT.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
{
if ((AT.isChecked()))
{
SharedPreferences appPrefs =
getSharedPreferences("com.fullfrontalgames.numberfighter.Settings_preferences",
MODE_PRIVATE);
SharedPreferences.Editor editor = appPrefs.edit();
editor.putBoolean("atpref", AT.isChecked()); //value to store
editor.commit();
}
}
}
});
SharedPreferences appPrefs =
getSharedPreferences("com.fullfrontalgames.numberfighter.Settings_preferences",
MODE_PRIVATE);
boolean atpref = appPrefs.getBoolean("atpref", true); //default is true
AT.setChecked(atpref);
Done.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent Intent = new Intent(Settings.this,activity_main.class);
Intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(Intent);
}
});
Notifications.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fullfrontalgames.numberfighter.Notifications"));
}
});
AccountSettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fullfrontalgames.numberfighter.AccountSettings"));
}
});
}
public void onToggleClicked(View view) {
// Is the toggle on?
boolean on = ((ToggleButton) view).isChecked();
if (on) {
view.setSoundEffectsEnabled(true);
} else {
view.setSoundEffectsEnabled(false);
}
}
}
If you are trying to save the ToggleButton's state when it is false, simply remove the if-statement in your OnClickListener:
if ((AT.isChecked()))

Facebook SSO not working in android

I used the following code to Login through Facebook in my app. I need to do this with Facebook SSO. I have the correct app_id.
package com.fb.sso;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
import com.facebook.android.Util;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
public class FBSSOActivity extends Activity {
/** Called when the activity is first created. */
public static final String APP_ID = "my_app_id";
private static final String[] PERMISSIONS = new String[] {
"publish_stream", "read_stream", "offline_access" };
private TextView mText;
private Handler mHandler = new Handler();
private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;
byte[] raw;
private SharedPreferences mPrefs;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (APP_ID == null) {
Util.showAlert(this, "Warning",
"Facebook Applicaton ID must be set...");
}
// Initialize the content view
setContentView(R.layout.main);
// Initialize the Facebook session
mFacebook = new Facebook(APP_ID);
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
mFacebook.setAccessToken(access_token);
}
if (expires != 0) {
mFacebook.setAccessExpires(expires);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("FB Sample App", "onActivityResult(): " + requestCode);
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
private class LogoutRequestListener implements RequestListener {
#Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
Log.v("comes here>>.","sucess");
// Only the original owner thread can touch its views
FBSSOActivity.this.runOnUiThread(new Runnable() {
public void run() {
mText.setText("Thanks for using FB Sample App. Bye bye...");
}
});
// Dispatch on its own thread
mHandler.post(new Runnable() {
public void run() {
}
});
}
#Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
#Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
// TODO Auto-generated method stub
}
#Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
// TODO Auto-generated method stub
}
#Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
Log.v("facebook error","fb error");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem loginItem = menu.findItem(R.id.login);
if (mFacebook.isSessionValid()) {
loginItem.setTitle("Logout");
} else {
loginItem.setTitle("Login");
}
loginItem.setEnabled(true);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Login/logout toggle
case R.id.login:
if (!mFacebook.isSessionValid()) {
mFacebook.authorize(this, new DialogListener() {
#Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
Log.v("Entered ", "No ERRRRRRRRRRRR");
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
mFacebook.getAccessToken());
editor.putLong("access_expires",
mFacebook.getAccessExpires());
editor.commit();
Intent i=new Intent(FBSSOActivity.this,second.class);
startActivity(i);
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
}
});
}else{
mFacebook.setAccessToken(null);
mFacebook.setAccessExpires(0);
AsyncFacebookRunner asyncRunner = new AsyncFacebookRunner(mFacebook);
asyncRunner.logout(this.getBaseContext(), new LogoutRequestListener());
}
break;
default:
return false;
}
return true;
}
}
I logged in to preinstalled Facebook app in my device. And I got this screen only.
And in my Logcat this line appears.
09-28 15:18:24.652: E/ActivityThread(1201): Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
If I logged out from my preinstalled Facebook app, my application prompts me to login, asking the credentials. That time also, the empty screen appears.But in the preinstalled Facebook app, I can see my updates.( I get Logged in).
Update:
Right now I'm checking the app only. I have not published it to market. I got the key by referring this site http://sean.lyn.ch/2011/07/android-the-facebook-sdk-sso-and-you/. And I added it to the app, like this.
Update 2:
Now I got these lines in logcat:
09-29 12:00:12.552: I/ActivityManager(73): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) }
09-29 12:00:13.022: I/ActivityManager(73): Displayed activity com.facebook.katana/.ProxyAuth: 436 ms (total 436 ms)
09-29 12:00:15.032: W/InputManagerService(73): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy#434b2e88 (uid=10031 pid=2233)
09-29 12:00:15.032: W/IInputConnectionWrapper(2233): showStatusIcon on inactive InputConnection

Categories

Resources