smsInterceptor in the background? - basic4android

Is it possible to use the smsInterceptor in the background? I'm trying to use services for that but it won't work, it won't toast message the sms for me on the MessageReceived event.
'Service module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim smsint As SmsInterceptor
End Sub
Sub Service_Create
smsint.Initialize("smsint")
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 30 * DateTime.TicksPerSecond, True)
End Sub
Sub Service_Destroy
End Sub
Sub MessageReceived (From As String, Body As String)
ToastMessageShow(From & " - " & Body, True)
End Sub
This is probably wrong tho, I haven't figured out how to do it. Read the services module thread but didn't get me anywhere :/

You will need to call Service.StartForeground to prevent Android from killing your service.
Another option is to modify the manifest file and add an intent filter for the SMS. In that case Android will start your service automatically when an SMS arrives.

Related

Create a Resolution Independent Form in ms access

I have designed my form in 1280*1024 resulotion. They lookvery nice on my Monitor, but If I see on another Monitors, they look very chaotic . Is there a way that I solve this problem?
It's not so easy. This is where MVC comes in very handy and you can distinguish between different components. You can have different views for different devices. Unfortunately VBA does not support that and you would have to implement your own framework to handle different screen resolutions.
The easiest way to avoid having to re-implement the design of your userform is to actually DESIGN it in your head before writing a single line of code. Think of the different resolutions(devices) your software is going to support, what the language you are using is supporting and what are your choices. Generally, think it over. In VBA I normally just go for the default size to avoid the headache of fitting someone's else screen.
You would have to redesign the entire UserForm. Not visually, but programmatically set both width, and height of the userform and make controls dependable on the current resolution. I do not recommend doing it this way but still this could be a solution.
You can achieve that by accessing the current resolution and modifying your Userform_Initialize() event.
So example, if the current resolution is 1024x768, you set the width and height to currentWidth-100px and currentHeight-100px.
If you open a new workbook and create an empty userform. Go to its code behind and add
Private Sub UserForm_Initialize()
Me.Width = GetCurrent(0) - 600
Me.Height = GetCurrent(1) - 800
End Sub
Then insert a module and add
Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Sub A()
UserForm1.Show
Unload UserForm1
End Sub
Function GetCurrent(x As Long) As Long
GetCurrent = GetSystemMetrics(x)
End Function
This will display a different size userform depending on the current resolution.
you can (but I wouldn't recommend it) use that technique. Note: depending on how many controls you have this may be the best approach but if you have lots of controls on the userform I would look for an alternative.
Alternatively, you can use the below code which checks the current screen resolution, warns the users and asks if the user wants to change his resolution.
The below code comes from here and the original author is DRJ
You stick the first part in the Workbook code behind
Option Explicit
Private Sub Workbook_Open()
Call VerifyScreenResolution
End Sub
and the below part in a module
Option Explicit
Private Declare Function GetSystemMetrics Lib "user32.dll" (ByVal nIndex As Long) As Long
Const SM_CXSCREEN = 0
Const SM_CYSCREEN = 1
Sub VerifyScreenResolution(Optional Dummy As Integer)
Dim x As Long
Dim y As Long
Dim MyMessage As String
Dim MyResponse As VbMsgBoxResult
x = GetSystemMetrics(SM_CXSCREEN)
y = GetSystemMetrics(SM_CYSCREEN)
If x = 1024 And y = 768 Then
Else
MyMessage = "Your current screen resolution is " & x & " X " & y & vbCrLf & "This program " & _
"was designed to run with a screen resolution of 1024 X 768 and may not function properly " & _
"with your current settings." & vbCrLf & "Would you like to change your screen resolution?"
MyResponse = MsgBox(MyMessage, vbExclamation + vbYesNo, "Screen Resolution")
End If
If MyResponse = vbYes Then
Call Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,3")
End If
End Sub
update.
your initialize event is here

Crystal Reports Exception: The maximum report processing jobs limit configured by your system administrator has been reached

I'm facing a very buggy issue, in ASP.NET application after viewing the same report many times simultaneously I got this exception:
The maximum report processing jobs limit configured by your system
administrator has been reached.
Wait I know there are tons of solutions out there but all of them are not working with me.
I put ReportDocument.Close(); ReportDocument.Dispose(); in CrystalReportViewer_Unload event, and still throw the exception.
Private Sub CrystalReportViewer1_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Unload
reportFile.Close()
reportFile.Dispose()
GC.Collect()
End Sub
I edit the PrintJobLimit registry in HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\InprocServer and HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\Server to -1 even to 9999, and still throw the exception.
Here is the code snippet where I call my report:
Table_Infos = New TableLogOnInfos()
Table_Info = New TableLogOnInfo()
Con_Info = New ConnectionInfo()
With Con_Info
.ServerName = ConfigurationManager.AppSettings("server_name")
.DatabaseName = ConfigurationManager.AppSettings("DB")
.UserID = user_name
.Password = pass_word
.Type = ConnectionInfoType.SQL
.IntegratedSecurity = False
End With
Table_Info.ConnectionInfo = Con_Info
If Session("recpt_lang") = "Arabic" Then
reportFile.Load(Server.MapPath("/Reports/") & "collectrecpt_new_ar.rpt")
ElseIf Session("recpt_lang") = "English" Then
reportFile.Load(Server.MapPath("/Reports/") & "collectrecpt_new.rpt")
End If
For Each mytable In reportFile.Database.Tables
mytable.ApplyLogOnInfo(Table_Info)
Next
CrystalReportViewer1.ReportSource = reportFile
CrystalReportViewer1.SelectionFormula = Session("SelectionForumla")
CrystalReportViewer1 = Nothing
You have to Dispose your report instance after all.
If you Dispose the report after showing it, you will never see the error "The maximum report processing jobs limit configured by your system administrator has been reached" again.
Dim report1 As rptBill = clsBill.GetReport(billNumber)
rpt.Print()
'Cleanup the report after that!
rpt.Close()
rpt.Dispose()
I would recommend moving your close/dispose/gc.collect code outside of that unload process. In other words:
Load report
Assign to Viewer Control
Show Report in Viewer Control
Close Viewer Control and Unload (completely)
Then close/dispose/gc.collect outside of any viewer control code
My guess is the viewer control is not completely closed when the report is being cleaned up.
Crystal is a very memory intensive process and very finicky.
Crystal Report document implements IDisposable interface. So all you have to do is to enclose the report's instance with using statement. It will be automatically closed and disposed once the using statement is completed. You can write something like that:
using(var report = GetInvoiceReport())
{
// your logic here
}
or (depends on your context):
using(var report = new ReportDocument())
{
// your logic here
}
Greetings I am too late to have answer on it,
all reply are working and i have seen but in case still you are facing same problem and error then please once go in to TEMP folder under "windows" directory and delete all instances of crystal report.
I am saying this because all above option will work but you are still in the maximum reach so first of all delete all instance then apply all the above suggestion.
thanks
Make sure you are using PUSH model to display your reports. Next you have to make one change in your Server's registry: Follow the path:
"HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\InprocServer"
and you will see an item " PrintJobLimit" and you will see that its default value is 75. that means the server can only handle 75 reports at a time.
Dont worry about that and just modify the value to -1
Make sure IIS user have sufficient permission to delete files present in "c:/windows/temp" folder.
I face the same issue once I provide write permission to that folder then it solved my issue.Also make sure dispose that object after generating the file
I was working on local report server. I have hosted my web application in other pc. When I got such error I just did IISRESET and working fine now.
Try this, this could help you.
You have to Dispose your report instance after all. If you Dispose the report after showing it, you will never see the error:
The maximum report processing jobs limit configured by your system administrator has been reached
Code:
Dim report1 As rptBill = clsBill.GetReport(billNumber)
rpt.Print()
'Cleanup the report after that!
rpt.Close()
rpt.Dispose()
In my case, the report had 4 subreports...
What solved for me was changing the value of "PrintJobLimit", from 75 to 500, in the following Regedit paths:
\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\InprocServer
\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\Server
I know this thread is older, but if you configure the app pool setting "Recycling..." to recycle at, say, 180 minutes instead of 1740 minutes (the default), this might free up the needed resources.
Use These methods when unload the page
ReportDocument crystalReport;
protected void Page_Unload(object sender, EventArgs e)
{
if (crystalReport != null)
{
crystalReport.Close();
crystalReport.Dispose();
}
}
OR
protected void Page_Unload(object sender, EventArgs e)
{
if (crystalReport != null)
{
crystalReport.Close();
crystalReport.Clone();
crystalReport.Dispose();
crystalReport = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
I ended up using GC.WaitForPendingFinalizers in addition to the GC.Collect, close and dispose. I believe my web page was perhaps unloading and stopping thread processing prematurely before the garbage was properly processed (really?)
This is on Server 2012, SQL 2012, CR 13.0.2000.0
Here's my code:
#Region "Cleanup"
Private Sub crCleanup(Optional blnForce As Boolean = False)
Try
' Crystal(code Is Not managed, i.e.it) 's COM interop => you have to manually
' release any objects instantiated. Make sure you set the ref to nothing and
' also call the dispose method if it has one.
' under some conditions, we don't want to destroy the ReportDocument (e.g. report page-to-page navigation)
If blnForce OrElse Me.blnPageHasFatalError OrElse (Not Me.CrystalUseCache) Then ' do not release when using cache! (unless forced)
If Not crReportDocument Is Nothing Then Me.crReportDocument.Close()
If Not crReportDocument Is Nothing Then Me.crReportDocument.Dispose()
If Not thisWebAppUser Is Nothing Then Me.thisWebAppUser.Dispose()
Me.thisWebAppUser.ClearReportCache() ' we are using HttpContext.Current.Cache.Item instead of sessions to save CR document
End If
' the rest of the items, we'll always want to clean up
If Not crParameterFieldDefinitions Is Nothing Then crParameterFieldDefinitions.Dispose()
If Not crParameterFieldDefinition Is Nothing Then crParameterFieldDefinition.Dispose()
crParameterFields = Nothing
crParameterField = Nothing
crParameterFieldName = Nothing
crParameterValues = Nothing
crParameterDiscreteValue = Nothing
crParameterDefaultValue = Nothing
crParameterRangeValue = Nothing
'
If Not crSections Is Nothing Then crSections.Dispose()
If Not crSection Is Nothing Then crSection.Dispose()
If Not crReportObjects Is Nothing Then crReportObjects.Dispose()
If Not crReportObject Is Nothing Then crReportObject.Dispose()
If Not crSubreportObject Is Nothing Then crSubreportObject.Dispose()
If Not crDatabase Is Nothing Then crDatabase.Dispose()
If Not crTables Is Nothing Then crTables.Dispose()
If Not crTable Is Nothing Then crTable.Dispose()
crLogOnInfo = Nothing
crConnInfo = Nothing
crDiskFileDestinationOptions = Nothing
ConnParam = Nothing
If Not subRepDoc Is Nothing Then subRepDoc.Dispose()
Catch ex As Exception
Me.thisWebAppUser.SendSysAdminMessage("Failed CR cleanup", ex.ToString)
End Try
' yes, use of the GC.Collect (and even more the GC.WaitForPendingFinalizers) is highly controversial
'
' the reality is that rendering crystal reports is rather slow compared to most web operations
' so it is expected that waiting for GC will have relatively little performance impact
' and will in fact, help tremendously with memory management.
'
' try setting these values to 1 and confirm for yourself by instantiating multiple crDocuments in different browsers if you don't believe it:
'
' HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\InprocServer
' HKEY_LOCAL_MACHINE\SOFTWARE\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Report Application Server\Server
'
' or google this error: The maximum report processing jobs limit configured by your system administrator has been reached
'
' I believe the problem is that on very fast servers, the page unloads and stops processing code to properly cleanup the Crystal Report objects
'
' This is done in 3 places:
' Report Viewer (Page_Unload and CrystalReportViewer1_Unload) rendering a report will of course always using a processing job
' Report Parameter Selector (Page_Unload) loading a crDocument without rendering a report still counts towards CR processing job limit.
' Custom Control crReportParameterSelectionTable (Public Overrides Sub dispose())
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
'***********************************************************************************************************************************
'
'***********************************************************************************************************************************
Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload
'If Me.IsCallback Then Exit Sub ' the menutree causes callbacks, but we are not interested
crCleanup()
' response object not available here, so cannot redirect (such as in the case of XLS opeing in a separate window)
' if for some crazy reason there is STILL a crReportDocument, set it to nothing
' If Not crReportDocument Is Nothing Then Me.crReportDocument = Nothing
' Me.CrystalReportViewer1 = Nothing
End Sub
Private Sub CrystalReportViewer1_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Unload
'If Me.IsCallback Then Exit Sub ' the menutree causes callbacks, but we are not interested
crCleanup()
End Sub
End Region

Some beginner questions

I guess I'll start by saying I am very new to B4A, and to programming in general. I have some very basic java and html exp. but that's it. I do not have any basic4ppc or really any IDE experience. Been using B4A for a few days now and can't get over the hump. Here are my noob questions:
Does having many activities (20-30+) slow down the app? Is there a downside to having a lot of activities?
I can't figure out how to scroll in the designer. I am trying to make a screen that has 25 buttons down in 1 column. However I can't scroll down to add more buttons below. I am able to add buttons programmically and in the fashion that I want (using a for loop), but is it normal to create views at runtime like this?
How do you ensure your app looks the same across all devices? Tablets? I have a scroll view that fits perfect in the emulator, but on my phone (droid x), the bottom of the scroll view is not stretched to the bottom of the phone. I use the code: scvScreen1.Initialize(100%y). Is that not right?
I have a Email screen in which is comprised of an edittext and a Send button, so that the users can send me questions from the app. However the Send button gives me this error on the 'URI =' line: "LastException java.lang.NumberFormatException: mailto:" here is the code:
Sub btnSendEmail_Click
Dim Uri As String
Uri="mailto:me#gmail.com?subject=Test Email&body=" + edtHelpEmail.Text
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW,Uri
StartActivity(Intent1)
End Sub
Or is there another way to open the device's default email program?
Regarding last question, how do I copy error messages to clipboard?? I selected the red error message on the bottom right of the IDE and tried ctrl-c, but didn't work.
In B4A, what is a good method of storing persistent data? All I really need to store are some strings. Nothing fancy. These strings are to be stored locally. AI made this easy by using TinyDB.
When using the designer, how do you ensure your views are centered on all devices? For instance, I have a screen that has several rows made up of: (label, edittext, label). And I want each row to be center aligned. Do I do this programmically? I'm thinking I would have to append each row of (label, edittext, label) to a panel, then in the code center the panel. Is this correct?
That's all I got for now, but I'm sure there will be plenty more questions later.
1) The whole idea of android is to small components i.e. Apps working together, so no need to worry about opening lots of activities. Memory is very well managed behind the scenes in Android.
2) Sure. That sounds fine to me. Use the Layout designer as much as you can and then add the dynamic stuff later. It's all about striking a balance between the size of your code and the number of activities.
3) In the Designer there's an option called 'Send to UI Cloud'. This compares your app over multiple screen sizes. You can also scale your design and programmatically resize specific controls within your app in the Activity_Create Lifecycle
4) What you're doing is almost correct. I corrected your code:
Sub MailTo(StrAddress As String, StrSubject As String, StrBody As String)
Dim StrMethod As String = "Sub MailTo(StrAddress As String, StrSubject As String, StrBody As String)"
Try
Dim StrUri As String
StrUri = "mailto:" & StrAddress & "?subject=" & StrSubject & "&body=" & StrBody
Dim Intent As Intent
Intent.Initialize(Intent.ACTION_VIEW, StrUri)
StartActivity(Intent)
Catch
If BlnLoudExceptions Then CdException.Show(StrClass, StrMethod, LastException)
End Try
End Sub
I tend to have a code module called CdIntent.bas for these functions as it both keeps the project organised and makes it easier to implement the same functionality across projects.
Then to call you would use
CdIntent.MailTo("me#yes.no", "Subject!", "Body!")
5) I have a file called CdException.bas
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 Show(StrClass As String, StrMethod As String, Ex As Exception)
LogColor("Exception: " & Ex.Message & " - Class: " & StrClass & " - Method: " & StrMethod, Colors.Magenta)
End Sub
and then wrap functions in the following way:
Sub FunctionName(...Parameters...) as Int
Dim StrMethod As String = "Sub Sleep(LngMilliseconds As Long)"
Dim IntResult As Int = 0
Try
[code here inc. IntResult = ???]
Catch
If BlnLoudExceptions Then CdException.Show(StrClass, StrMethod, LastException)
End Try
Return IntResult
End Sub
BlnLoudExceptions is a global boolean that you'd declare in
Process_Globals that you can switch on an off exception logs.
StrClass is a global String that you'd declare in Process_Globals
that contains the name of the class e.g. "CdIntent.bas"
The exceptions then appear in magenta in the log screen along with the method name and class in which they occurred allowing you to home in on them.
6) I have a table in an SQLLite database called TabletSettings, which has two TEXT colums called 'Name' and 'Value'. It works well and gets you into a (what I think is a) good habit of always having a database available to your app from the get-go.
7) I'll get back to you on this as I haven't done this before.
Until then, the following thread will help you in the B4A forum http://www.basic4ppc.com/android/forum/threads/convert-integer-to-dip.18800/
I agree with Jim's point but will attempt to answer 1.
I'm new to android myself but as I understand it activities on the whole are only running when active. Unless you are using the app to continuously do something there is only one activity at a time. The number of activities is likely to affect the ram available more than anything. Lastly it might be worth walking first rather than running so to speak but trying a single and then add multiple activities.
You could try adding a ListView or ScrollView where the items are the buttons, this seems to be the std way of doing things otherwise a tabbed view.

Stop httputils service in basic4android

I am using basic4android and I made an application that uses httputils services. Sometimes a remote error occurs (possible server overload or limited internet connection) and the application exits with the error message box. The activity closes but httputils service is still running. While I reopen the activity new error occurs, because of the unfinished job of httputils. Everything is OK only if I choose to stop the activity in the second error.
Is there any way to determine if the httputils service is running by a previous instance of my app? Or better, a way to try to stop this service either its running or not.
HttpUtils errors should not cause your program to exit. You should check IsSuccess to make sure that the call succeeded or not.
You can stop the service from running by calling StopService(HttpUtilsService).
Public Sub StationTransfer_Click
Dim job As HttpJob
job.Initialize("MyJob", Me)
Dim URL As String="https://www.yourserver.com/myjob.asmx/GetData?parameter1=abc"
job.Download(URL)
ProgressDialogShow2("Getting data From Server...", True)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "MyJob"
HandleMyJob(Job)
End Select
Job.Release
End Sub
Sub HandleMyJob(Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error downloading Data", True)
ProgressDialogHide
Return
End If
....
end Sub
if there is an httpjob error you catch it in the handler function by looking at the status. if the status is not success than you catch it and display a message.

How do I check if a user is authenticated with NickServ using POE::Component::IRC::State in Perl?

I'm trying to test whether a user is registered on FreeNode. nick_info() doesn't seem to return information about this, so I want to use $irc->yield(whois => $nick); and then grab the irc_whois event's reply. The problem is that I want to wait until this event is fired, so I created a global variable $whois_result and wrote a sub like this:
sub whois {
my $nick = $_[0];
$whois_result = 0;
$irc->yield(whois => $nick);
while($whois_result == 0) { }
return $whois_result;
}
with the irc_whois handler looking like:
sub on_whois {
$whois_result = $_[ARG0];
print "DEBUG: irc_whois fired.\n";
}
Unfortunately, the event can't fire while the loop is running so this hangs. I'm sure there's a better way to do this, but I'm not familiar enough with this kind of programming to know. Any help would be greatly appreciated.
On the sub for states in POE... You have to yield or call it in another state.
Also, when you have data from the IRC command, yield to another state to process it.
_start
- Start up a timer, etc.
timer
- yield on_whois
on_whois
- run who is
- Set data
- yield to the next timer
_stop
- Kill the timer
- flush the data
I run a bot on Freenode and resolved the issue by asking Nickserv the command:
ACC [nick] *
Nickserv will then reply with a notice in the format:
[nickname] -> [registerd nickservname] ACC [level]
Where level 3 means that the user is identified to nickserv.
The following applies to FreeNode at least (or any server supporting the identify-msg feature).
If you are reacting to a message (irc_msg, irc_public, or irc_ctcp_action) from a user, you can tell whether he has identified to NickServ by looking at the third argument ($_[ARG3]) provided to the event handler. It will be true if the user has identified, false otherwise.