Android Question cant auto run device miui

naifnas

Active Member
Licensed User
Hi all
my app cant auto run in device miui
another work..
i try add ini manifest this but cant
i think this device need permission for auto start
so how???

B4X:
<uses-permission
  android:name="android.permission.BOOT_COMPLETED"
   />


B4X:
AddApplicationText(
<service
android:name="android.intent.action.BOOT_COMPLETED"
android:enabled="true" />
)

AddReceiverText(Starter,
<intent-filter>
             <category android:name="android.intent.category.DEFAULT"></category>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
   <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>)
 

naifnas

Active Member
Licensed User
1. Remove all the above code.

2. Add a new service. The starter service should never be started from a receiver.

3. Set #StartAtBoot attribute to True.

Note that you need B4A v8+ if targetSdkVersion is set to 26+.
thanks sir Erel
I will try
 
Upvote 0

naifnas

Active Member
Licensed User
I already remove and add new service and change
B4X:
#Region  Service Attributes
    #StartAtBoot: True
    
#End Region
but not work..
I check in setting device permissions auto start
not allow my app
 

Attachments

  • Screenshot_٢٠١٨-٠٤-٠٥-١٦-٥٨-١٨.jpg
    Screenshot_٢٠١٨-٠٤-٠٥-١٦-٥٨-١٨.jpg
    318 KB · Views: 193
Upvote 0

naifnas

Active Member
Licensed User
thanks for reply
i make new project
very sample
but not work...

this main
B4X:
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#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.
Dim labael1 As Label
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")
    labael1.Initialize("labael1")
    Activity.AddView(labael1,0,0,20dip,20dip)
    labael1.Color=Colors.Red
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

this service

B4X:
#Region  Service Attributes
    #StartAtBoot: True
    #ExcludeFromLibrary: 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 Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.

End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

naifnas

Active Member
Licensed User
As I wrote above, you shouldn't use the starter service for this. Use a different service.
thanks for answer..
I already make new sample project
i use new service and do name "test"
i try but not work..
or I understand wrong????
 
Upvote 0

naifnas

Active Member
Licensed User
How do you see that it is not started? The service doesn't do anything.
sorry I add this
B4X:
Sub Service_Start (StartingIntent As Intent)
    StartActivity(Main)
End Sub

and i try another device work
but device miui not work
 
Upvote 0

naifnas

Active Member
Licensed User
It is possible that your device doesn't allow apps to start at boot.

Two things that you can try:
1. Monitor the logs and see whether the app was started.
2. Show a notification instead of starting the activity.
exactly...
but why another app (whatsap ) device miui agree allow ?
 
Upvote 0
Top