Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] java – App Suddenly Exits When Tried to Call given number

Posted on November 14, 2022

Solution 1 :

So finally i got the fix for it..thanks to “David Wasser” as i didnt looked at logcat initially. through his suggetion i looked at logcat & found an error of runtime call permission which i didn’t added in code , and this hint also given by “vikas kumar” thanks to him..
now the changes. following are the changes i made in mainactivity : –

  if (ContextCompat.checkSelfPermission(getApplicationContext(), CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
            startActivity(callIntent);
        } else {
            requestPermissions(new String[]{CALL_PHONE}, 1);
        }

this asks for runtime permission for telephony & when granted it will directly place a call.

Why This changes needed ?
Because from Android 6.0 Above there were api changes & also permission related changes.
& i followed older example of calling app tutorial.

Problem :

I Tried to Create Caller app using intent, in android studio ide code is error free but when it is run on live device & put in the number in EditText & Call button is pressed app suddenly exits.. im unable to find what causes this app behaviour and why call is not getting placed..How do i make it work ?

MainActivity.java

    public class MainActivity extends AppCompatActivity {
 EditText txt_phn;
 Button btn_call;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        txt_phn=(EditText)findViewById(R.id.txt_phn);
        btn_call=(Button)findViewById(R.id.btn_call);
        btn_call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {

                mck();
            }
        });


    }
    private void mck()
    {


        
        String number = "tel:" + txt_phn.getText().toString().trim();

        Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));

        try {
            startActivity(callIntent);
            finish();
            Log.i("Finished making a call", "");
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(this, "Call faild, please try again later.", Toast.LENGTH_SHORT).show();
        }


    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
   
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
}
Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns_android="http://schemas.android.com/apk/res/android"
    package="com.example.caller">
    <uses-permission android_name="android.permission.CALL_PHONE"/>




    <application
        android_allowBackup="true"
        android_icon="@mipmap/ic_launcher"
        android_label="@string/app_name"
        android_roundIcon="@mipmap/ic_launcher_round"
        android_supportsRtl="true"
        android_theme="@style/AppTheme">
        <activity android_name=".MainActivity">
            <intent-filter>
                <action android_name="android.intent.action.MAIN" />

                <category android_name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns_android="http://schemas.android.com/apk/res/android"
    xmlns_app="http://schemas.android.com/apk/res-auto"
    xmlns_tools="http://schemas.android.com/tools"
    android_layout_width="match_parent"
    android_layout_height="match_parent"
    tools_context=".MainActivity">

    <EditText
        android_id="@+id/txt_phn"
        android_layout_width="379dp"
        android_layout_height="70dp"
        android_layout_marginTop="148dp"
        android_ems="10"
        android_hint="Please Enter Phone Number To Call"
        android_inputType="text"
        app_layout_constraintTop_toTopOf="parent"
        tools_layout_editor_absoluteX="16dp" />

    <Button
        android_id="@+id/btn_call"
        android_layout_width="wrap_content"
        android_layout_height="wrap_content"
        android_layout_marginBottom="360dp"
        android_text="Call"
        app_layout_constraintBottom_toBottomOf="parent"
        app_layout_constraintEnd_toEndOf="parent"
        app_layout_constraintHorizontal_bias="0.5"
        app_layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2020-08-10 20:04:47.337 23806-23806/com.example.caller E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.caller, PID: 23806
    java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{70113a3 23806:com.example.caller/u0a425} (pid=23806, uid=10425) with revoked permission android.permission.CALL_PHONE
        at android.os.Parcel.createException(Parcel.java:2071)
        at android.os.Parcel.readException(Parcel.java:2039)
        at android.os.Parcel.readException(Parcel.java:1987)
        at android.app.IActivityTaskManager$Stub$Proxy.startActivity(IActivityTaskManager.java:3851)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1714)
        at android.app.Activity.startActivityForResult(Activity.java:5210)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
        at android.app.Activity.startActivityForResult(Activity.java:5168)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
        at android.app.Activity.startActivity(Activity.java:5539)
        at android.app.Activity.startActivity(Activity.java:5507)
        at com.example.caller.MainActivity.mck(MainActivity.java:49)
        at com.example.caller.MainActivity.access$000(MainActivity.java:19)
        at com.example.caller.MainActivity$1.onClick(MainActivity.java:33)
        at android.view.View.performClick(View.java:7260)
        at android.view.View.performClickInternal(View.java:7237)
        at android.view.View.access$3600(View.java:802)
        at android.view.View$PerformClick.run(View.java:27915)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:915)
     Caused by: android.os.RemoteException: Remote stack trace:
        at com.android.server.wm.ActivityStackSupervisor.checkStartAnyActivityPermission(ActivityStackSupervisor.java:1058)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:762)
        at com.android.server.wm.ActivityStarter.startActivity(ActivityStarter.java:585)
        at com.android.server.wm.ActivityStarter.startActivityMayWait(ActivityStarter.java:1298)
        at com.android.server.wm.ActivityStarter.execute(ActivityStarter.java:516)

Comments

Comment posted by David Wasser

If the app “suddenly exits”, that means that it crashed. If it crashes, there will be exception logs and stack trace in the logcat. Please look there. If you can’t figure it out, post the relevant parts of the logcat here in your question.

READ  [ANSWERED] Accessing external storage in Android API 29
Powered by Inline Related Posts

Comment posted by vikas kumar

it seems you need to get the permission for android.permission.CALL_PHONE. add it and will work

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress