Android Question Chat B4A

MarcoRome

Expert
Licensed User
Longtime User
i found this interesting code that Integrated live chat for mobile apps.
https://www.hipmob.com/

Screenshot 2015-10-11 18.53.33.png


This is code to integration Chat:
Copy the Hipmob library JAR file into your project's library folder (libs, if you're using the default project folder structure in Eclipse).
Add the Hipmob library JAR file into your project's build path.
Add the INTERNET, WRITE_EXTERNAL_STORAGE and RECORD_AUDIO permissions to the AndroidManifest.xml file. This will allow sending/receiving of text, picture and audio messages.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

Add the HipmobCore activity definition to the AndroidManifest.xml file.
<activity android:name="com.hipmob.android.HipmobCore" android:theme="@android:style/Theme.Light" />
Use an Intent to call the HipmobCore activity. You'll need the application ID from step 1: pass that as HIPMOB_KEY.

// create an intent
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);

// REQUIRED: set the appid to the key you're provided
i.putExtra(HipmobCore.KEY_APPID, "2f6524fbfe9d4ae482a3deadf5a0563a");

// REQUIRED: pass the host user identifier.
i.putExtra(HipmobCore.KEY_USERID, "<userid>");

// set the title
i.putExtra(HipmobCore.KEY_TITLE, "First app (devilapp): Chat");

// launch the chat window
startActivity(i);
</userid>

Screenshot 2015-10-11 18.49.15.png



In attachment library android-hipmob-2.9.8.jar


So i created new project in manifest i add this:
B4X:
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>
    <intent-filter>
    <action android:name="com.hipmob.android.HipmobCore"/>
    </intent-filter>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Light")
'End of default text.
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
AddPermission("android.permission.RECORD_AUDIO")


and in my code i add this:

#AdditionalJar: android-hipmob-2.9.8 'Copy this jat in library folder

B4X:
 Dim i As Intent
i.Initialize("com.hipmob.android.HipmobCore.class", "")
i.PutExtra("HipmobCore.KEY_APPID", "2f6524fbfe9d4ae482a3deadf5a0563a")
i.PutExtra("HipmobCore.KEY_USERID", "<userid>")
i.PutExtra("HipmobCore.KEY_TITLE", "First app (devilapp): Chat")
StartActivity(i)


And i have this error: ancroid.content.ActivityNotFoundException: No Activity found to handle intent ..... dat=com.hipmob.android.HipmodCore.class flg=0x200000 ( has extras)


Where i wrong ?
thank you
Marco
 

Attachments

  • android-hipmob-2.9.8.jar
    248.1 KB · Views: 261
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
Someone know as translate this in B4A:

This in Manifest
B4X:
Add the HipmobCore activity definition to the AndroidManifest.xml file.
<activity android:name="com.hipmob.android.HipmobCore" android:theme="@android:style/Theme.Light" />

and this intent:

B4X:
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
i.putExtra(HipmobCore.KEY_APPID, "2f6524fbfe9d4ae482a3deadf5a0563a");
i.putExtra(HipmobCore.KEY_USERID, "<userid>");
i.putExtra(HipmobCore.KEY_TITLE, "First app (devilapp): Chat");
startActivity(i);

Thank you
Marco
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Someone know as translate this in B4A:

This in Manifest
B4X:
Add the HipmobCore activity definition to the AndroidManifest.xml file.
<activity android:name="com.hipmob.android.HipmobCore" android:theme="@android:style/Theme.Light" />

and this intent:

B4X:
Intent i = new Intent(this, com.hipmob.android.HipmobCore.class);
i.putExtra(HipmobCore.KEY_APPID, "2f6524fbfe9d4ae482a3deadf5a0563a");
i.putExtra(HipmobCore.KEY_USERID, "<userid>");
i.putExtra(HipmobCore.KEY_TITLE, "First app (devilapp): Chat");
startActivity(i);

Thank you
Marco

Hi Erel.
Pls, can you help me translate this code in B4A ?
Thank you very much
Marco
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to use the constants values instead of the names.

If you don't find the values in the documentation then you can use JavaObject to get the value:
B4X:
Sub GetConstantValue(ClassName, FieldName) As Object
 Dim jo As JavaObject
return  jo.InitializeStatic(ClassName).GetField(FieldName)
End Sub

B4X:
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), ...)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
You need to use the constants values instead of the names.

If you don't find the values in the documentation then you can use JavaObject to get the value:
B4X:
Sub GetConstantValue(ClassName, FieldName) As Object
Dim jo As JavaObject
return  jo.InitializeStatic(ClassName).GetField(FieldName)
End Sub

B4X:
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), ...)

Thank you Erel for your response.
But anyway dont work. This is my code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Chat
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalJar: android-hipmob-2.9.8
#End Region
 
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
 
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
End Sub
 
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
 
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
Dim i As Intent
i.Initialize("com.hipmob.android.HipmobCore.class", "")
'i.Initialize(GetConstantValue("com.hipmob.android.HipmobCore", "com.hipmob.android.HipmobCore.class"), "")
'i.Initialize("com.hipmob.android.HipmobCore", "")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), "2f6524fbfe9d4ae482a3deadf5a0963a" )
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_USERID"), "<userid>")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_TITLE"), "First app (devilapp): Chat")
StartActivity(i)
 
End Sub
 
 
 
Sub GetConstantValue(ClassName, FieldName) As Object
Dim jo As JavaObject
Return  jo.InitializeStatic(ClassName).GetField(FieldName)
End Sub
 
Sub Activity_Resume
 
End Sub
 
Sub Activity_Pause (UserClosed As Boolean)
 
End Sub

This is my Manifest:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddActivityText(Main, <intent-filter>
   <action android:name="com.hipmob.android.HipmobCore" />
</intent-filter>)  
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
AddPermission("android.permission.RECORD_AUDIO")

In attachment project.

Where i wrong ?
Thank you again for your support.
Marco
 

Attachments

  • ChatB4A.zip
    8.6 KB · Views: 258
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
Erel dont work also so, i try:

B4X:
i.Initialize("com.hipmob.android.HipmobCore", "")
'i.Initialize(GetConstantValue("com.hipmob.android.HipmobCore", "com.hipmob.android.HipmobCore.class"), "")
'i.Initialize("com.hipmob.android.HipmobCore", "")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), "2f6524fbfe9d4ae482a3deadf5a0963a" )
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_USERID"), "<userid>")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_TITLE"), "First app (devilapp): Chat")
i.SetComponent("/.com.hipmob.android.HipmobCore")
StartActivity(i)

B4X:
i.Initialize("", "")
'i.Initialize(GetConstantValue("com.hipmob.android.HipmobCore", "com.hipmob.android.HipmobCore.class"), "")
'i.Initialize("com.hipmob.android.HipmobCore", "")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), "2f6524fbfe9d4ae482a3deadf5a0963a" )
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_USERID"), "<userid>")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_TITLE"), "First app (devilapp): Chat")
i.SetComponent("/.com.hipmob.android.HipmobCore")
StartActivity(i)

But the result is:
android.content.ActivityNot Found Exception: Unable to find explicit activity class /.com.hipmod.android.Hipmobcore

Another idea ?
Thank you
Marco
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
in manifest i add this
And you think this is enough? When i look at the example project from them i see A LOT more to add in the manifest!?

As far as i can see it must be something like
<activity android:name="com.hipmob.android.experience.knowledgebase.KnowledgeBaseOptionsActivity" />
<activity android:name="com.hipmob.android.experience.knowledgebase.KnowledgeBaseSearchOnlyActivity" />
<activity android:name="com.hipmob.android.experience.knowledgebase.KnowledgeBaseSearchChatAlwaysActivity" />
<activity android:name="com.hipmob.android.experience.knowledgebase.KnowledgeBaseSearchChatIfOperatorAvailableActivity" />
<activity android:name="com.hipmob.android.experience.chat.LiveChatOptionsActivity" />
<activity android:name="com.hipmob.android.experience.chat.DefaultLiveChatActivity" />
<activity android:name="com.hipmob.android.experience.chat.CustomMessageLayoutLiveChatActivity" />
<activity android:name="com.hipmob.android.experience.chat.HipmobCustomMessageLayoutLiveChatActivity" />
<activity android:name="com.hipmob.android.experience.articleview.ArticleViewOptionsActivity" />
<activity android:name="com.hipmob.android.experience.articleview.ArticleViewOnlyActivity" />
<activity
android:name="com.hipmob.android.HipmobCore" />
<activity
android:name="com.hipmob.android.experience.chat.CustomHipmobCore"
android:label="@string/app_name" />
<activity
android:name="com.hipmob.android.HipmobHelpDeskArticleViewActivity"
android:label="@string/app_name" />
<activity
android:name="com.hipmob.android.HipmobHelpDeskSearchActivity"
android:label="@string/app_name" />
<receiver
android:name="com.hipmob.android.HipmobPlayPushReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.hipmob.android.experience" />
</intent-filter>
</receiver>
<service android:name="com.hipmob.android.HipmobPlayPushService" />

<meta-data
android:name="com.google.android.gms.version"
android:value="@Integer/google_play_services_version" />
<meta-data
android:name="hipmob_push_sender_ids"
android:resource="@string/sender_ids" />
<meta-data
android:name="hipmob_notification_target"
android:resource="@string/notification_target" />
<meta-data
android:name="hipmob_notification_text"
android:resource="@string/notification_message_multiple" />
<meta-data
android:name="hipmob_notification_text_single"
android:resource="@string/notification_message_single" />
</application>
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
After a "few" time i comeback for resolve this.

Implement this "seem very simple":

Screenshot 2016-05-15 19.00.26.png


So i insert in my code this steps.

Manifest.xml

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddActivityText(Main, <intent-filter>
   <action android:name="com.hipmob.android.HipmobCore" />
</intent-filter>) 
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.
AddPermission("android.permission.INTERNET")
AddPermission("android.permission.WRITE_EXTERNAL_STORAGE")
AddPermission("android.permission.RECORD_AUDIO")

In my code Main this:

B4X:
#Region  Project Attributes
    #ApplicationLabel: First app (marcoamici)
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
    #AdditionalJar: android-hipmob-2.9.8
#End Region

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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
Dim i As Intent
i.Initialize("com.hipmob.android.HipmobCore.class", "")
'i.SetComponent(Application.PackageName & "/com.hipmob.android.HipmobCore")
'i.SetComponent("com.hipmob.android/.HipmobCore.class")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_APPID"), "f994a48f7a544911b27c596451dfd2e6" )
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_USERID"), "<userid>")
i.PutExtra(GetConstantValue("com.hipmob.android.HipmobCore", "KEY_TITLE"), "First app (devilapp): Chat")
StartActivity(i)

End Sub



Sub GetConstantValue(ClassName, FieldName) As Object
Dim jo As JavaObject
Return  jo.InitializeStatic(ClassName).GetField(FieldName)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Now i receive this error:

Screenshot 2016-05-15 19.01.11.png


Also if in jar i have this:

Screenshot 2016-05-15 19.07.55.png


In attachment Project and Jar
Any idea ???
Thank you
Regards
Marco
 

Attachments

  • HipModeDemoChat.zip
    8.3 KB · Views: 225
  • android-hipmob-2.9.8.jar
    248.2 KB · Views: 238
Upvote 0
Top