Java Question Try to make library for nextpeer

hanyelmehy

Active Member
Licensed User
Longtime User
i Try to make library for nextpeer.com
but still have many problems
Basic Integration Guide in this link
https://nextpeer.atlassian.net/wiki/display/NS/Android Basic Integration Guide
This is my lib code
B4X:
package b4a.nextpeer.lib;

import android.app.Application;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.nextpeer.android.Nextpeer;
import com.nextpeer.android.NextpeerListener;
import com.nextpeer.android.NextpeerSettings;
import com.nextpeer.android.NextpeerSettings.NextpeerRankingDisplayAlignment;
import com.nextpeer.android.NextpeerSettings.NextpeerRankingDisplayPosition;
import com.nextpeer.android.NextpeerSynchronizedEventFire;
import com.nextpeer.android.NextpeerTournamentCustomMessage;
import com.nextpeer.android.NextpeerTournamentEndData;
import com.nextpeer.android.NextpeerTournamentStartData;
import com.nextpeer.android.NextpeerActivity;

//import anywheresoftware.b4a.objects.ViewWrapper;
@Version(1.0f)
@ShortName("NextPeerLib")
@ActivityObject
@Events(values={"startgame","endgame"})
//@Events(values={"CloudDataRcv"})
@DependsOn(values={"nextpeer_dist","android-support-v4"})
@Author("ELMIHY")
//@Permissions(values={"android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.INTERNET"})

public class nextpeer extends NextpeerActivity{
//public class nextpeer extends Application{  
      
    private BA ba;
    private String eventName;
      
    private boolean mDoesDeviceSupportAccelerometer = true;
    private NextpeerTournamentStartData mStartData;
    //private Random mRandom = new Random();
      
    public void Initialize(BA ba,String GAME_KEY,String EventName)
    {
        // Place the in-game ranking on the top right corner of the game (vertical)
       NextpeerSettings settings = new NextpeerSettings();
       settings.inGameNotificationAlignment = NextpeerRankingDisplayAlignment.VERTICAL;
       settings.inGameNotificationPosition = NextpeerRankingDisplayPosition.TOP_RIGHT;  
       Nextpeer.initialize(ba.context, GAME_KEY, mNextpeerListener,settings);
       this.ba = ba;
       this.eventName = EventName.toLowerCase(BA.cul);
     }
  
    private NextpeerListener mNextpeerListener = new NextpeerListener() {
  
        public void onTournamentStart(NextpeerTournamentStartData startData) {
            ba.raiseEvent(this, eventName + "_startgame");
            mStartData = startData;
            //ba.raiseEventFromDifferentThread(this, null, 0, eventName + "_StartGame",true,new Object[] {mStartData.tournamentUuid});
        }
      
        public void onTournamentEnd(NextpeerTournamentEndData endData) {
            ba.raiseEvent(this, eventName + "_endgame");
        }
    };
  
     public void Nextpeerlaunch(){
         Nextpeer.launch();;
     }
     public void NextpeeronStart(){
         Nextpeer.onStart();
     }
     public void ForfeitForCurrentTournament(){
         Nextpeer.reportForfeitForCurrentTournament();
     }   
     public void ReportScore(int newScore)
        {
         Nextpeer.reportScoreForCurrentTournament(newScore);
      
         }
   
     public void ReportFinalScore(int finalScore)
        {
         Nextpeer.reportControlledTournamentOverWithScore(finalScore);
       
         }
   
   
  
}

for B4a Work
this is my manifest
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="13" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'SetApplicationAttribute(android:name, "nextpeer.example.test")
'End of default text.
'//////////////////////////////nextpeer////////////////////////////////////////////////////
AddManifestText(
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>)
AddApplicationText(<activity android:name="com.nextpeer.android.NextpeerActivity" android:screenOrientation="portrait"/>)
AddApplicationText(<service android:name="com.nextpeer.android.NextpeerPushService" />
        <receiver android:name="com.nextpeer.android.NextpeerBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>)

'//////////////////////////////nextpeer/////////////////////////////////////////////////////

and this is my B4A code
B4X:
#Region  Project Attributes
    #ApplicationLabel: nextpeer test
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: true
    #AdditionalRes: E:\Lib-Tools\nextpeer\nextpeer-android-sdk-v2.0.13\nextpeer\res, com.nextpeer.android
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
  
End Sub

Sub Globals
    Private Mynextpeer As NextPeerLib
    Private Game_key As String
    Private Game_UUID As String

    Private Button1 As Button
    Private Button2 As Button
    Private Button3 As Button
    Private Button4 As Button
    Private Button5 As Button
    Private Button6 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
    Activity.LoadLayout("Screen1")
    Game_key="1111111111111111111111"
    Game_UUID="11111111111111111111"

End Sub
Sub Activity_Resume
  
End Sub
Sub Activity_Pause (UserClosed As Boolean)
  
End Sub
Sub mynextpeer_endgame()
    Log("EndGame")
End Sub
Sub mynextpeer_startgame()
    Log("StartGame")
  
   
End Sub
Sub Button1_Click
    Mynextpeer.Initialize(Game_key,"mynextpeer")
    Log("Initialize")

End Sub
Sub Button2_Click
    Mynextpeer.NextpeeronStart
End Sub
Sub Button3_Click
    Mynextpeer.ReportFinalScore(100)
End Sub
Sub Button4_Click
   Mynextpeer.Nextpeerlaunch
  
End Sub
Sub Button5_Click
  
  
End Sub
Sub Button6_Click
  
End Sub

when call Mynextpeer.Initialize ,nothing from event fire
when try Mynextpeer.Nextpeerlaunch (just screen show that tell me i am offline)
other methods make errors
 

hanyelmehy

Active Member
Licensed User
Longtime User
Don't extend the class from NextpeerActivity or Application.

Use BA.Log to see whether the events in the library code are raised.
Thank you for your answer
i use (public class nextpeer{ ) only
also when check log : (events in the library code are not raised)
and all things still the same
 

DonManfred

Expert
Licensed User
Longtime User
You can create a job offer in the job-forum if you want
 
Top