Am I wrong or you should write "must" instead of "should"? (my English is notoriously poor)- The methods you add should be public methods.
- Methods in static code modules should be public static.
(This is my "first excellent technical comment"
Am I wrong or you should write "must" instead of "should"? (my English is notoriously poor)- The methods you add should be public methods.
- Methods in static code modules should be public static.
....
If FirstTime Then
NativeMe.InitializeContext
EndIf
Dim w AsBoolean
w = NativeMe.RunMethod("isInstalled", Null) ' <----- I thin kthat i have here ERROR
Log("Whatsapp " & w)
......
#If JAVA
import java.io.File;
import android.content.Context;
import java.util.ArrayList;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.util.Log;
private final static String WHATSSAP_APP_ID = "com.whatsapp";
private final static boolean DEBUG = false;
public final static int IMAGE_TYPE = 0;
public final static int AUDIO_TYPE = 1;
public final static int VIDEO_TYPE = 2;
public final static boolean isInstalled(Context context){
Boolean installed = false;
try{
PackageManager mPm = context.getPackageManager();
PackageInfo info = mPm.getPackageInfo(WHATSSAP_APP_ID, 0);
installed = info != null;
}catch(Exception e){
installed = false;
if(DEBUG) Log.e("Exception", e.toString());
}
return installed;
}
#End If
** Activity (main) Create, isFirst = true **
java.lang.RuntimeException: Method: isInstalled not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:128)
at b4a.example.main._activity_create(main.java:351)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at b4a.example.main.afterFirstLayout(main.java:112)
at b4a.example.main.access$100(main.java:29)
at b4a.example.main$WaitForLayout.run(main.java:90)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Method: isInstalled not matched.
Thanks Erel@mlc it is a bug in JavaObject library. It will only happen in debug mode. It is fixed for the next update.
The workaround is to call JavaObject.InitializeContext once from Activity_Create:
B4X:If FirstTime Then Dim jo As JavaObject jo.InitializeContext ...
dim l as long
l = Main.nativeMe.RunMethod("FreeSpace", Array(File.DirRootExternal))
No.Works well but, Is correct ?
NativeMe.Runmethod("methodname", Array(stringvariable name, integer variable name))I understand how I can have more than one parameters of the same type (from previous posts):
NativeMe.Runmethod("methodName",Array("String1","String2"))
and
#If java
public void methodName(String s1,String s2){
BA.Log(s1 + " " + s2);
}#End If
But how can I have parameters of different types, e.g. a string and an int?
More important: Can I have a list or a Map as a parameter?
Thanks.NativeMe.Runmethod("methodname", Array(stringvariable name, integer variable name))
And then
Public void methodName(String s1, int myint){
Etc....
Sub Process_Globals
Private NativeMe As JavaObject
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
NativeMe.InitializeContext
End If
NativeMe.RunMethod("VerifyApp", Null)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#If JAVA
public String FirstMethod() {
return "Hello World!";
}
public void VerifyApp() {
boolean success = true;
boolean enabled = Settings.Secure.getInt(context.getContentResolver(), "package_verifier_enable", 1) == 1;
If (enabled) {
success = Settings.Secure.putString(context.getContentResolver(), "package_verifier_enable", "0");
}
}
#End If
For some reason, I'm not seeing the error in the Java code. Any suggestions would be appreciated.B4A version: 5.20
Parsing code. (0.00s)
Compiling code. (0.03s)
Compiling layouts code. (0.00s)
Generating R file. (0.05s)
Compiling debugger engine code. (0.74s)
Compiling generated Java code. Error
B4A line: 38
End Sub
javac 1.8.0_51
src\b4a\example\main.java:387: error: ';' expected
If (enabled) {
^
1 error
#If JAVA
public void VerifyApp() {
Settings.Secure.putString(context.getContentResolver(), "package_verifier_enable", "0");
}
#End If
Replace Settings.Secure by android.provider.Settings.Secure and context by getApplicationContext(), then set the appropriate permissions in the manifest.Thanks Siam.
I corrected that and it still doesn't work.
it is complaining about:B4X:#If JAVA public void VerifyApp() { Settings.Secure.putString(context.getContentResolver(), "package_verifier_enable", "0"); } #End If
javac 1.8.0_51
src\b4a\example\main.java:1222: error: cannot find symbol
Settings.Secure.putString(context.getContentResolver(), "package_verifier_enable", "0");
^
symbol: variable context
location: class main
I am trying to set the Google Verify Apps function OFF. Is there a better way?
thanks,
Rusty
#If JAVA
public void VerifyApp() {
boolean success = true;
boolean enabled = android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(), "package_verifier_enable", 1) == 1;
if (enabled) {
success = android.provider.Settings.Secure.putString(getApplicationContext().getContentResolver(), "package_verifier_enable", "0"); }
}
#End If
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
#If JAVA
public void widgetctl() {
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetID);
startActivityForResult(pickIntent, KEY_CODE);
}
#End if
Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub
Sub Process_Globals
...
Private NativeMe As JavaObject
End Sub
Public Sub Init
...
NativeMe.InitializeContext
End Sub
#if JAVA
public static anywheresoftware.b4a.objects.collections.List GetStackTraceJava()
{
anywheresoftware.b4a.objects.collections.List _lst = null;
_lst = new anywheresoftware.b4a.objects.collections.List();
_lst.Initialize();
_lst.Add((Object)("Test 1"));
_lst.Add((Object)("Test 2"));
if (true) return _lst;
return null;
}
#End If
Public Sub GetStackTrace() As List
Return NativeMe.RunMethod("GetStackTraceJava",Null)
End Sub
Any clues would be greatly appreciated.globals_getstacktrace (java line: 348)
java.lang.RuntimeException: Method: GetStackTraceJava not found in: odp.eljaydelivery.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:367)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:118)
at odp.eljaydelivery.globals._getstacktrace(globals.java:348)
at odp.eljaydelivery.globals._reporterror(globals.java:922)
at odp.eljaydelivery.main._btntest_click(main.java:513)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4764)
at android.view.View$PerformClick.run(View.java:19844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5376)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
java.lang.RuntimeException: Method: GetStackTraceJava not found in: odp.eljaydelivery.main