App Kill specific app by package name, clear its cache and Run the app again - android

I'm getting crazy while trying to make an app that will
kill specific other app
clear the killed app cache
restart the killed app again
for Android TV 10
lets call this app "the killer app"
i'm testing this app in android x86 emulator inside the android studio
i successed to kill the app but the app won't run even i enabled permissions for the killer app
thats the code i wrote:
package com.deliadsolutions.cachekillerstarter
import android.app.ActivityManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.FragmentActivity
/**
* Loads [MainFragment].
*/
class MainActivity : FragmentActivity()
{
final var hotpackagename= "il.net.hot.hot"
fun startNewActivity(context: Context, packageName: String)
{
var intent = context.packageManager.getLaunchIntentForPackage(packageName)
if (intent == null) {
// Bring user to the market or let them choose an app?
intent = Intent(Intent.ACTION_VIEW)
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
// Toast.makeText(this, .cacheDir.path.toString(), Toast.LENGTH_SHORT).show()
val am = getSystemService(ACTIVITY_SERVICE) as ActivityManager
am.killBackgroundProcesses(hotpackagename)
this.cacheDir.deleteRecursively()
// var intent = this.packageManager.getLaunchIntentForPackage(hotpackagename)
// this.startActivity(intent)
//val launchIntent = packageManager.getLaunchIntentForPackage(hotpackagename)
//startActivity(launchIntent)`
val ctx: Context = this // or you can replace **'this'** with your **ActivityName.this**
try {
val i = ctx.packageManager.getLaunchIntentForPackage(hotpackagename)
ctx.startActivity(i)
} catch (e: Exception)
{
// TODO Anerated catch block
}
val intent = Intent(Intent.ACTION_MAIN, null)
intent.addCategory(Intent.CATEGORY_LAUNCHER)
val cn = ComponentName()
intent.component = cn
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
this.finishAffinity()
}
}
none of these app run methods starting the app
this is my AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.Cachekillerstarter" >
<activity
android:name=".MainActivity"
android:banner="#drawable/app_icon_your_company"
android:exported="true"
android:icon="#drawable/app_icon_your_company"
android:label="#string/title_activity_main"
android:logo="#drawable/app_icon_your_company"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DetailsActivity"
android:exported="false" />
<activity
android:name=".PlaybackActivity"
android:exported="false" />
<activity
android:name=".BrowseErrorActivity"
android:exported="false" />
</application>
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
</manifest>

Related

Bluetooth.ACTION_FOUND behaving weirdly

I am using broadcast receiver to scan for available devices. it was working at first, but then something happened and it started to find too many devices(there are only 3 bt device in room but it finds more than 10 sometimes) and only find their mac addresses(bluetoothDevice.name comes as null). I can't figure out why it's behaving like this
This is my MainActivity:
class MainActivity : AppCompatActivity() {
private var bluetoothAdapter: BluetoothAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val receiver = MyBroadcast()
val bluetoothManager: BluetoothManager = getSystemService(BluetoothManager::class.java)
bluetoothAdapter = bluetoothManager.adapter
// request permission
if (ActivityCompat.checkSelfPermission(
this,
Manifest.permission.BLUETOOTH_CONNECT
) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this,
arrayOf(
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_ADMIN
), 1
)
}
val button = findViewById<Button>(R.id.button_b)
button.setOnClickListener {
Log.i("TAG,", "clicked")
bluetoothAdapter?.startDiscovery()
IntentFilter(BluetoothDevice.ACTION_FOUND).also {
registerReceiver(receiver, it)
}
}
}
}
This is the broadcast receiver:
class MyBroadcast:BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
when(intent?.action) {
BluetoothDevice.ACTION_FOUND -> {
// Discovery has found a device. Get the BluetoothDevice
// object and its info from the Intent.
val device: BluetoothDevice =
intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE)!!
Log.i("here", device.toString())
}
}
}
}
And this is the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/Theme.Broadcast"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
It turns out there a lot of unnamed Bluetooth devices around which are nameless and you can't connect them either. So I had to check with if(device.name!= null && device.address != null) to get the names devices

Screen not turning on when alarm manager is fired in physical devices

I'm working on an android application and i need alarm manager to fire events at certain times , the code works fine and the notification fires in time but only in one scenario is not working when the screen is off , the device is not waking up and wait for notification to fire up , actually this works in emulators ( i guess because there is no such power saving mode like in some physical devices ) , I've looked up most topics and could not find any solution , any help would be appreciated Thank you .
Firing Alarm Manager
fun fireAlarmManager(context: Context , time : MutableList<Long>){
val intent = Intent(context, AlarmReceiver::class.java)
for (i in 0 until time.size){
if(time[i] > deviceTimeInMillis()){
list.add(time[i])
val pendingIntent = PendingIntent.getBroadcast(context,time[i].toInt(),intent,PendingIntent.FLAG_IMMUTABLE)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,time[i],pendingIntent)
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP,time[i],pendingIntent)
}
}
}
setDataFromSharedPreferences(list)
}
Broadcast receiver
class AlarmReceiver : BroadcastReceiver() {
override fun onReceive(context : Context?, intent : Intent?) {
wakeUp(context)
val serviceIntent = Intent(context,OnClearFromRecentServices::class.java)
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
context!!.startForegroundService(serviceIntent)
} else {
context!!.startService(serviceIntent)
}
}
private fun wakeUp(context: Context?) {
val pm = context!!.getSystemService(Context.POWER_SERVICE) as PowerManager
val wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK or PowerManager.FULL_WAKE_LOCK or PowerManager.ACQUIRE_CAUSES_WAKEUP, "app::tag")
wakeLock.acquire(60000)
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
val keyguardLock = keyguardManager.newKeyguardLock("TAG")
keyguardLock.disableKeyguard()
}
}
Alarm Service
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
fireNotification(this)
return START_STICKY
}
Manifest File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.kotlin.quranapp">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID"/>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".koin.BaseApplication"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.QuranApp"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="false"
android:launchMode="singleInstance"
android:screenOrientation="portrait" />
<activity
android:name=".views.SplashActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".alarm.AlarmReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
<receiver
android:name=".alarm.PlayerReceiver"
android:exported="false" />
<service android:name=".alarm.services.OnClearFromRecentServices" />
</application>
</manifest>

PayPal callback does not trigger after login to the PayPal account

I'm stuck with the next issue.
I integrated PayPal sdk into my android app.
implementation 'com.paypal.checkout:android-sdk:0.6.1'
My app has an underscore in the package name so I have to use ‘App links’. I tested it in the test-app, all works fine like on the first screenschoot.
But in the main app when I successfully log in to a paypal account and redirect back to the app, the callback does not trigger.
I also figured out if I press on close button, callback yes triggers.
Also when I returns to the app I receive Intent like this:
app.mobile.main.app.name://paypalpay?code=C21AALAqib-oCkJXmgsoDPPbpAiYza7KJgVoA_01gzzYtawIsgofw0PmCpr186xkz1OY6tSQ....
Please write if you have any suggestions.
Thanks and have a nice day.
Here snippets of Manifest file and PayPalFragment.
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="app.mobile.main_app.name">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature android:name="android.hardware.camera" />
<application
android:name=".MyApplication"
android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:requestLegacyExternalStorage="true"
android:roundIcon="#mipmap/logo"
android:supportsRtl="true"
android:theme="#style/MaterialTheme"
android:usesCleartextTraffic="true"
tools:replace="android:allowBackup">
<activity
android:name=".Ux.Activities.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="paypalpay"
android:scheme="app.mobile.main.app.name" />
</intent-filter>
</activity>
</application>
</manifest>
PayPalFragment.kt
class PayPalFragment : Fragment() {
override fun onAttach(context: Context) {
super.onAttach(context)
PayPalCheckout.registerCallbacks(
onApprove = OnApprove { approval ->
approval.orderActions.capture { captureOrderResult ->
Log.i("tester", "OnApprove called.")
}
},
onCancel = OnCancel {
Log.i("tester", "OnCancel called.")
},
onError = OnError { errorInfo ->
Log.i("tester", "onError called.")
},
onShippingChange = OnShippingChange { shippingChangeData, shippingChangeActions ->
Log.i("tester", "onShippingChange called.")
}
)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val fragView = inflater.inflate(R.layout.fragment_pay_pal, container, false)
val payPalButton = fragView.findViewById<Button>(R.id.paypal_button)
payPalButton.setOnClickListener {
PayPalCheckout.startCheckout(
CreateOrder { createOrderActions ->
val order = Order(
intent = OrderIntent.CAPTURE,
appContext = AppContext(
userAction = UserAction.PAY_NOW
),
purchaseUnitList = listOf(
PurchaseUnit(
amount = Amount(
currencyCode = CurrencyCode.USD,
value = "10.00"
)
)
)
)
createOrderActions.create(order)
}
)
}
return fragView
}
}
So solution is to add default PayPal activity to AndroidManifest.xml
You just copy the code below and change YOUR-CUSTOM-SCHEME to what you declared in ReturnUrl in the PayPal developer account.
No need to create this activity, it comes with the PayPal SDK.
It will redirect you back into your app and trigger a PayPal payment sheet.
After the user has completed or canceled the payment, the corresponding callback will be called.
<activity
android:name="com.paypal.openid.RedirectUriReceiverActivity"
android:excludeFromRecents="true"
android:theme="#style/PYPLAppTheme">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="paypalpay"
android:scheme="YOUR-CUSTOM-SCHEME" />
</intent-filter>
</activity>

Implementing Call recording in React Native

I am working on creating something to record call in my react native App.
For this I have used ReactNative Headless task to get the status of phone and react-native-audio-recorder-player for recording the call but at the end I am getting a file with no sound .
react-native-audio-recorder-player its working fine separetly when I am using this not on call but its saving a file with no sound during call.
Here is my index.js
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { AudioRecorder, AudioUtils } from 'react-native-audio'
import AudioRecorderPlayer from 'react-native-audio-recorder-player';
const audioRecorderPlayer = new AudioRecorderPlayer();
// const audioPath = AudioUtils.DocumentDirectoryPath + '/record.aac'
const Rec = async (data) => {
console.log(data.state)
try{
if (data.state === 'extra_state_offhook') {
const result= await audioRecorderPlayer.startRecorder().then(result=>console.log("started")).catch(err=>console.log(err))
audioRecorderPlayer.addRecordBackListener((e) => {
console.log('Recording . . . ', e.current_position);
return;
});
console.log(result);
} else if (data.state === 'extra_state_idle') {
const result = await audioRecorderPlayer.stopRecorder();
audioRecorderPlayer.removeRecordBackListener()
console.log(result);
console.log('Stopped')
}
}catch(err ){
console.log(err)
}
}
AppRegistry.registerHeadlessTask('Rec', () => Rec)
AppRegistry.registerComponent(appName, () => App);
Here is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.cadric">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application android:requestLegacyExternalStorage="true" android:name=".MainApplication" android:label="#string/app_name" android:icon="#mipmap/ic_launcher" android:roundIcon="#mipmap/ic_launcher_round" android:allowBackup="false" android:usesCleartextTraffic="true" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:label="#string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.android.gms.auth.api.phone.SMS_RETRIEVED" />
</intent-filter>
</activity>
<service android:name="com.cadric.service.RecService" android:enabled="true" android:exported="true" />
<receiver android:name="com.cadric.receiver.RecReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.BIND_DEVICE_ADMIN">
<intent-filter android:priority="0">
<action android:name="android.intent.action.PHONE_STATE" />
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</application>
</manifest>
Here is my RecReciever.java file
package com.cadric.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import com.cadric.service.RecService;
import com.facebook.react.HeadlessJsTaskService;
public final class RecReceiver extends BroadcastReceiver {
public final void onReceive(Context context, Intent intent) {
Boolean incomingCall=false;
Intent recIntent = new Intent(context, RecService.class);
if (intent.getAction().equals("android.intent.action.PHONE_STATE")) {
recIntent.putExtra("action", "phone_state");
String phoneState = intent.getStringExtra("state");
if (phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String phoneNumber = intent.getStringExtra("incoming_number");
System.out.println(phoneNumber);
incomingCall = true;
recIntent.putExtra("state", "extra_state_ringing");
recIntent.putExtra("incoming_call", true);
recIntent.putExtra("number", phoneNumber);
} else if (phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
if (incomingCall) {
incomingCall = false;
}
recIntent.putExtra("state", "extra_state_offhook");
recIntent.putExtra("incoming_call", false);
} else if (phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
if (incomingCall) {
incomingCall = false;
}
recIntent.putExtra("state", "extra_state_idle");
recIntent.putExtra("incoming_call", false);
}
} else {
recIntent.putExtra("action", "new_outgoing_call");
}
context.startService(recIntent);
HeadlessJsTaskService.acquireWakeLockNow(context);
}
}
Here is my RecService.java file
package com.cadric.service;
import android.content.Intent;
import android.os.Bundle;
import com.facebook.react.HeadlessJsTaskService;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
import javax.annotation.Nullable;
public class RecService extends HeadlessJsTaskService {
#Nullable
protected HeadlessJsTaskConfig getTaskConfig(Intent intent) {
Bundle extras = intent.getExtras();
return new HeadlessJsTaskConfig(
"Rec",
extras != null ? Arguments.fromBundle(extras) : null,
5000);
}
}
Please help me I am stucked , invested more than 20 hours in that already.
Android has strict protection on call recording. see here
Voice call + ordinary app A voice call is active if the audio mode
returned by AudioManager.getMode() is MODE_IN_CALL or
MODE_IN_COMMUNICATION.
Android shares the input audio according to these rules:
The call always receives audio. The app can capture audio if it is an
accessibility service. The app can capture the voice call if it is a
privileged (pre-installed) app with permission CAPTURE_AUDIO_OUTPUT.
To capture the voice call's uplink (TX), downlink (RX), or both, the
app must specify the audio sources
MediaRecorder.AudioSource.VOICE_UPLINK or
MediaRecorder.AudioSource.VOICE_DOWNLINK, and/or the device
AudioDeviceInfo.TYPE_TELEPHONY.
try using accessibility service. I am also trying using Native Android Kotlin but am yet unseccessful

Autostart on BOOT_COMPLETED for flutter application based on Android example not working

There are quite a few examples of using BOOT_COMPLETED to start an application when the device boots..
I have attempted to use these example against my Flutter application. Having it start the App. This is for a simply signage app that shows images. Basically similar to a picture frame.
In the example code below, the application is compiling, however, when I reboot a simulator, for example, the code does not appear to have any effect.
My guess is that I am not calling the right code to actually start the application.. I am not a Android developer, so am having issues figuring what is exactly going on.
Manifest follows..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="au.net.digitall.cmplayer">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name="io.flutter.app.FlutterApplication"
android:label="cm_player"
android:icon="#mipmap/ic_launcher"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/cmTheme2"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver
android:enabled="true"
android:name=".StartCmPlayerServiceAtBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
Then the StartCmPlayerServiceAtBootReceiver class to start the APP..
package au.net.digitall.cmplayer;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class StartCmPlayerServiceAtBootReceiver extends BroadcastReceiver {
private static final String TAG = StartCmPlayerServiceAtBootReceiver.class.getSimpleName();
#Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "BOOT detected");
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent serviceIntent = new Intent(context, MainActivity.class);
context.startService(serviceIntent);
}
}
}
This all compiles and runs, but nothing happens on reboot.
Appreciate the help..
Thank to very much to Mike M.
His suggestion and pointing at the other android based discussion gave me enough info to archive autostart on boot. The code change to the above example follows..
In the StartCmPlayerServiceAtBootReceiver class,
Change to
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Intent mIntent = new Intent(context, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);
}
}
Thanks again, and I hope other flutter devs find this useful.
Create receiver class on kotlin path project_name/android/app/src/main/kotlin/com/example/app/
package com.example.app
import android.content.BroadcastReceiver
import android.content.Context;
import android.content.Intent;
class BootReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(i)
}
}
}
Add permission on your manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
Add receiver tag inside application tag on your manifest
<receiver
android:enabled="true"
android:exported="true"
android:name="com.example.app.BootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
Add code to open your app after booting was completed on your MainActivity.kt, you can find it on project_name/android/app/src/main/kotlin/com/example/app/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var REQUEST_OVERLAY_PERMISSIONS = 100
if (!Settings.canDrawOverlays(getApplicationContext())) {
val myIntent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
val uri: Uri = Uri.fromParts("package", getPackageName(), null)
myIntent.setData(uri)
startActivityForResult(myIntent, REQUEST_OVERLAY_PERMISSIONS)
return
}
}
don't forget to import this code below on your MainActivity.kt because you need Bundle and Settings package
import android.os.Bundle
import android.provider.Settings
Works on my flutter app, tested on android 11.

Categories

Resources