Android Question InLine JavaCode

MarcoRome

Expert
Licensed User
Longtime User
Hi all i have this code:
B4X:
....
If FirstTime Then
NativeMe.InitializeContext
EndIf
Dim w AsBoolean
w = NativeMe.RunMethod("isInstalled", Null) ' <----- I think that 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
compile and when start app i have this error:
B4X:
** 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.
Any idea ?
Thanks
 

MarcoRome

Expert
Licensed User
Longtime User
Ok, also if i write:

B4X:
...
public boolean isInstalled(Context context){
....

i have anyway this error:

B4X:
java.lang.RuntimeException: Method: isInstalled not matched.

maybe is wrong this code:

B4X:
If FirstTime Then
NativeMe.InitializeContext
EndIf
Dim w AsBoolean
w = NativeMe.RunMethod("isInstalled", Null) ' <----- I think that i have here ERROR
Log("Whatsapp " & w)

in this case --> isInstalled(Context context) is correct call this method with parameter NULL ?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
There are easier ways to find out if whatsapp is installed. Use Packagemanager
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
There are easier ways to find out if whatsapp is installed. Use Packagemanager
Yes i know this Manfred. I'm conducting trials of this wonderful new opportunity to insert code jave directly.
In library we substitute Context context --> BA ba.
I would understand when i have "Context context" in code B4A is "Null" or what ??
Anyway thanks for your continuous support to the community.
Marco
 
Upvote 0
Top