Sure - Its pretty much like I outlined. The only thing I needed to do were
the 2 facebook helper classes (C# & Java). The CustomWebView was on that
site I sent you and you'll know soon enough about the icon id when you come
to compile :)

The classes I wrote are as follows :- first the FacebookHelper.java


package com.Exterminator.Game;

import android.util.Log;
import java.io.IOException;
import java.net.MalformedURLException;
import android.util.*;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import com.facebook.android.*;
import com.facebook.android.Facebook.*;

public class FacebookHelper
{
        private Facebook _facebook = new Facebook("<<< --- YOUR FACEBOOK APP ID 
---
>>>");
        String FILENAME = "AndroidSSO_data";
    private SharedPreferences _prefs;
        private String _message;
        private boolean _submitted;             


        public void PostUpdate(Activity mainActivity, String message)
        {
                Log.i("EXTERMINATOR","PostUpdate to Facebook :"+message);

                try
                {
                        _submitted=false;
                        _message=message;

                        _prefs = 
mainActivity.getPreferences(android.app.Activity.MODE_PRIVATE);
                        String access_token = _prefs.getString("access_token", 
null);
                        long expires = _prefs.getLong("access_expires", 0);
                        if(access_token != null) {
                                _facebook.setAccessToken(access_token);
                        }
                        if(expires != 0) {
                                _facebook.setAccessExpires(expires);
                        }

                        /*
                         * Only call authorize if the access_token has expired.
                         */
                        if(!_facebook.isSessionValid()) {
                                Log.i("EXTERMINATOR","Need to Authorize");
                                _facebook.authorize(mainActivity, new 
String[]{"publish_stream"},
Facebook.FORCE_DIALOG_AUTH, new DialogListener() {
                                                @Override
                                                public void onComplete(Bundle 
values) 
                                                {         
                                                   
Log.i("EXTERMINATOR","Authorize onComplete");
                                                   SharedPreferences.Editor 
editor = _prefs.edit();
                                                   
editor.putString("access_token", _facebook.getAccessToken());
                                                   
editor.putLong("access_expires", _facebook.getAccessExpires());
                                                   editor.commit();      
                                                   updateStatus();
                                                }
                
                                                @Override 
                                                public void 
onFacebookError(FacebookError e) { 
                                                        Log.d("EXTERMINATOR", 
"FB ERROR. MSG: "+e.getMessage()+", CAUSE:
"+e.getCause()); 
                                                } 
                     
                                                @Override 
                                                public void onError(DialogError 
e) { 
                                                        
Log.e("EXTERMINATOR","AUTH ERROR. MSG: "+e.getMessage()+", CAUSE:
"+e.getCause()); 
                                                } 
                     
                                                @Override 
                                                public void onCancel() { 
                                                        Log.d("EXTERMINATOR", 
"AUTH CANCELLED"); 
                                                } 
                
                                        });
                                }                       
                        else
                        updateStatus();
                } catch (Exception e){
                        Log.e("EXTERMINATOR","EXCEPTION "+e.getMessage()); 
                }
        }

    private void updateStatus(){ 
                Log.i("EXTERMINATOR","update facebook status");
        try { 
            Bundle bundle = new Bundle(); 
            bundle.putString("message", _message);
            bundle.putString("link", "http://www.exterminator-game.com";); 
            bundle.putString("name", "Exterminator!"); 
            bundle.putString("description", "As the newly hired under-study
of 'Buzz Killer' -exterminator extraordinaire- your job is to rid the
beautiful country town of Mobile from the infestations that have ravaged the
neighbourhood lately.\nYou will be rewarded handsomely for your efforts, but
beware - Buzz has little patience for laggards!"); 
            bundle.putString("picture",
"http://www.exterminator-game.com/ExterminatorSmall.png";);  
            bundle.putString(Facebook.TOKEN, _facebook.getAccessToken()); 
            String response = _facebook.request("me/feed",bundle,"POST"); 
            Log.d("EXTERMINATOR", "UPDATE RESPONSE -"+response); 
        } catch (Exception e) { 
            Log.e("EXTERMINATOR","EXCEPTION "+e.getMessage()); 
                }        
                Log.i("EXTERMINATOR","end update facebook status");
                _submitted=true;
    } 

        public boolean Submitted()
        {
                return _submitted;
        }

    public void onActivityResult(int requestCode, int resultCode, Intent
data) {
       _facebook.authorizeCallback(requestCode, resultCode, data);            
    }
        
}


Then my C# class (Facebook.cs)


//      _____      _                      _             _             
//     | ____|_  _| |_ ___ _ __ _ __ ___ (_)_ __   __ _| |_ ___  _ __ 
//     |  _| \ \/ / __/ _ \ '__| '_ ` _ \| | '_ \ / _` | __/ _ \| '__|
//     | |___ >  <| ||  __/ |  | | | | | | | | | | (_| | || (_) | |   
//     |_____/_/\_\\__\___|_|  |_| |_| |_|_|_| |_|\__,_|\__\___/|_| 
// 
//              (C)2011 BitWallah.    All rights reserved.


using System;
using Android.App;
using Android.Content;
using Android.Runtime;

namespace Exterminator
{
    internal class Facebook : IDisposable
    {
        private static IntPtr _class_ref =
JNIEnv.FindClass("com/Exterminator/Game/FacebookHelper");
        private static IntPtr _methodIdCtor;
        private static IntPtr _methodPostUpdate;
        private static IntPtr _methodSubmitted;
        private static IntPtr _methodOnActivityResult;
        private IntPtr _instance;
        private Activity _activity;
        private bool _disposed = false;

        public Facebook(Activity activity)
        {
            _activity = activity;

            _methodIdCtor = JNIEnv.GetMethodID(_class_ref, "<init>", "()V");
            _methodPostUpdate = JNIEnv.GetMethodID(_class_ref, "PostUpdate",
"(Landroid/app/Activity;Ljava/lang/String;)V");
            _methodSubmitted = JNIEnv.GetMethodID(_class_ref, "Submitted",
"()Z");
            _methodOnActivityResult = JNIEnv.GetMethodID(_class_ref,
"onActivityResult", "(IILandroid/content/Intent;)V");            
            
            IntPtr newObject = JNIEnv.NewObject(_class_ref, _methodIdCtor);
            _instance = JNIEnv.NewGlobalRef(newObject);
        }

        ~Facebook()
        {
            Dispose(false);
        }

        public void PostUpdate(string message)
        {            
            IntPtr ptrMessage = JNIEnv.NewString(message);
            JValue[] parms = new JValue[] { new
JValue(JNIEnv.ToJniHandle(_activity)), new JValue(ptrMessage) };
            JNIEnv.CallVoidMethod(_instance, _methodPostUpdate, parms);         
   
        }

        public bool Submitted()
        {
            return JNIEnv.CallBooleanMethod(_instance, _methodSubmitted);
        }

        public void OnActivityResult(int requestCode, int resultCode, Intent
data)
        {
            JValue[] parms = new JValue[] { new JValue(requestCode), new
JValue(resultCode), new JValue(JNIEnv.ToJniHandle(data)) };
            JNIEnv.CallVoidMethod(_instance, _methodOnActivityResult,
parms);
        }

        protected virtual void Dispose(bool disposing)
        {            
            if (!this._disposed)
            {
                if (_instance != null)
                {
                    JNIEnv.DeleteGlobalRef(_instance);
                    _instance = IntPtr.Zero;                    
                }
                _disposed = true;
            }            
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
    }
}


The rest is from that SDK I sent.

Hope this helps!

Cheers
Warren



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Facebook-Connect-bindings-for-MonoDroid-tp5111515p5111675.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to