0

The function below is called in the service. When the condition is fulfill then the intent is calling to do something. I used mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); to execute the intent from the service but in android 10 the intent is not working.

Can anybody help me to solve this problem?

public void playAudio(){
  
    if(mp != null && !mp.isPlaying()){
        //dont want to pick up phone audio
        claps++;
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            public void run() {
                //OverviewFragment.refresh(getApplicationContext());
                System.out.println("yay" + claps);
                Log.e("claps", String.valueOf(claps));
                //Toast.makeText(AnotherService.this, "In background thread", Toast.LENGTH_SHORT).show();

                Toast.makeText(AnotherService.this, ""+ claps, Toast.LENGTH_SHORT).show();
            }
        });

    }

    if(mp != null && !mp.isPlaying() && claps >= MainActivity.w){
       
          mp.start();


        Intent mainIntent = new Intent(AnotherService.this, StopAlarmActivity.class);
        mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(mainIntent);
        claps = 0;
    }
    //modifyText();

}
Hakan Dilek
  • 2,178
  • 2
  • 23
  • 35
Syed Rafaqat Hussain
  • 1,009
  • 1
  • 9
  • 33

1 Answers1

0

pleace check link this : https://www.py4u.net/discuss/619814

Not sure if it's right to do it this way, but I did not have enough time (app is only for company internal use).

I used permissions:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

and then every user has to go to setting -> permissions of the app and then check box in advanced settings for function "show the app over others"

Sorry for my English or not exactly the right solution, but it worked, so good hotfix for me.

On Pixel 4 it will be looking like this:

 fun createNewDocument() {
        val newDocumentIntent = newDocumentIntent()
       // if (useMultipleTasks) {
            newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
            newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
            newDocumentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
       // }
        startActivity(newDocumentIntent)
    }




private fun newDocumentIntent(): Intent =
        Intent(this, DetailActivity::class.java).apply {
            addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
                    android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS)
            putExtra(Conproperties().project_id,project_id)
            putExtra(Conproperties().notidatetime,notidatetimeConvet)

            val s = SimpleDateFormat("d/MM/yyyy HH:mm:ss Z",Locale.ENGLISH)
            val cal = Calendar.getInstance()
            var alertdatetime = s.format(cal.time)

            putExtra(Conproperties().alertdatetime,alertdatetime)

        }

enter image description here

I do not have enough reputation to comment solution https://stackoverflow.com/a/59067224/8995217 so I try to leave my answer on it for MIUI rom

It seems need to grand some permissions for app running on Xiaomi phones. Go to phone settings -> Apps -> Manage apps then find your app.

On app info page go to other permissions and enable the following options

Show on Lock screen Display pop-up windows while running in the background Permanent notification It works for Xiaomi Redmi Note 8T

cr : https://www.py4u.net/discuss/619814

Pong Petrung
  • 1,437
  • 17
  • 14