Android Question Xiaomi readmi intent not work

kkkpe

Active Member
Licensed User
Longtime User
on xiaomi android version 13 and sdk 33 the call of another app via intent does not work. In the ion_event event it returns null. can you tell me the correct code? and what permissions to ask? thanks
 

kkkpe

Active Member
Licensed User
Longtime User
You need to download the ziwi app from the internet
the following code works on Samsung devices.

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
    Dim ion As Object
    Dim pm As PackageManager
    Dim dt As DynamicToast
    
End Sub

Sub Globals
    Dim versionepackage As String
    Private btn_irda As Button
    Dim rp As RuntimePermissions
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("lay_ziwi")
    
End Sub

Sub Activity_Resume
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub btn_irda_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    Dim i As Intent
    Dim jo As JavaObject
    Dim ctx As JavaObject
    ctx = jo.InitializeContext
    
    i.Initialize(i.ACTION_MAIN,"")
    i.SetComponent("sv.ziwi/sv.ziwi.ExternalCall")
    
    i.PutExtra("ACTION", "GetEVA_Stitch")
    i.PutExtra("KEY", "" )
    i.PutExtra("BOUDRATE", 96)
    i.PutExtra("IRDA_SECURITY", 0000)
    Log("SECURITYIRDA:")
    'Log(securityirda)
    i.PutExtra("IRDA_PASSWORD",0000)
    'Log("PASSWORD: " & password)
    i.PutExtra("CALLER_ID",jo.RunMethod("getApplicationName",Array(ctx)))
    'i.PutExtra("RESETEVACOUNTER",True)
    StartActivityForResult(i)

End Sub



Sub StartActivityForResult(i As Intent)
    Dim jo As JavaObject = GetBA
    ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
    jo.RunMethod("startActivityForResult", Array As Object(ion,i))
End Sub

Sub ion_Event (MethodName As String, Args() As Object) As Object
    Log(MethodName)
    Log(Args)
    Dim risp As String
    If Args(0) = 0 Then 'resultCode = RESULT_OK
        Dim i As Intent = Args(1)
        If(i.IsInitialized = False) Then
            Log("non è un INTENT")
            Return Null
        End If
        risp = i.GetExtra("ZIWIRESPONSE")
        Log("RISPOSTA: ")
        
    Else
        Dim i As Intent = Args(1)
    End If
    Return Null
End Sub



Sub GetContext As JavaObject
    Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
    Dim jo As JavaObject
    Dim cls As String = Me
    cls = cls.SubString("class ".Length)
    jo.InitializeStatic(cls)
    Return jo.GetFieldJO("processBA")
End Sub



#if java
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;


        public  String getApplicationName(Context context) {
            ApplicationInfo applicationInfo = context.getApplicationInfo();
            int stringId = applicationInfo.labelRes;
            return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
        }
        
        
    
#End If
 
Upvote 0

kkkpe

Active Member
Licensed User
Longtime User
the project is the code I posted
I add the manifest file I used

B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddManifestText( <queries>
 <package android:name="sv.ziwi" />
 <package android:name="sv.ziwi.external" />
 </queries>
)
 
Upvote 0

walt61

Active Member
Licensed User
Longtime User
Nope, the attached is an demo project, produced with "export as zip" from the IDE. Anyway I'm afraid I won't be able to help as
1) that ziwi app asks for just about every permission possible and I'm not going to allow it
2) I don't know what's supposed/you're expecting to happen

All I can say is that the ziwi app is launched but I presume you're expecting some data back from it. Also, everything is in Italian; perhaps it's better to ask the question in the Italian forum. Sorry, good luck!
 

Attachments

  • test.zip
    9.6 KB · Views: 41
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…