-1

i am new to android please help.
I tried using this code...

Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
startActivity(intent);

didn't work: it stopped abruptly.
i mentioned the necessary permissions

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Dec 21 '17 at 15:10
  • 2
    Welcome on StackOverflow! Please provide more details so that we can help you with your problem. See also [How to Ask](https://stackoverflow.com/help/how-to-ask). – Felix Haeberle Dec 21 '17 at 15:11

1 Answers1

0

Please try below code.

        new Handler().post(new Runnable() {
            @Override
            public void run() {
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_FROM_BACKGROUND);
context.startActivity(intent);
            }
        });

You will get context from service onStart() Method. InPlace of Context, can use getApplicationContext()

June7
  • 19,874
  • 8
  • 24
  • 34