简体   繁体   中英

How to Pass data to phone app dialer from recyclerview holder data is parse from firebase

I get data from firebase database to manipulate.

viewHolder.imageButton.setOnClickListener to open phone app and show phone number from model.getPhone(); and show it in phone dialer to give preference user wather to call or not. app crash when I click imageButton and i'm not able to get crash log in android studio.

 @Override
            protected void populateViewHolder(MovieViewHolder viewHolder, final Movie model, final int position) {
                if (tvNoMovies.getVisibility() == View.VISIBLE) {
                    tvNoMovies.setVisibility(View.GONE);
                }
                viewHolder.tvMovieName.setText(model.getMovieName());
                viewHolder.address.setText(model.getAddress());
                viewHolder.phone.setText(model.getPhone());
                viewHolder.lit.setText(model.getLit());
                viewHolder.lon.setText(model.getLon());
                Picasso.with(MainActivity.this).load(model.getMoviePoster()).into(viewHolder.ivMoviePoster);
                viewHolder.ivMoviePoster.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
                        intent.putExtra("latitude", model.getLit());
                        intent.putExtra("longitude", model.getLon());
                        intent.putExtra("name", model.getMovieName());


                        startActivity(intent);

                    }
                });
                viewHolder.tvMovieName.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
                        intent.putExtra("latitude", model.getLit());
                        intent.putExtra("longitude", model.getLon());
                        intent.putExtra("name", model.getMovieName());


                        startActivity(intent);

                    }
                });
                viewHolder.imageButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    String mobileNo = model.getPhone();
                    String uri = "tel:" + mobileNo.trim();
                    Intent intent = new Intent(Intent.ACTION_CALL);
                    intent.setData(Uri.parse(uri));
                    startActivity(intent);
                    }
                });



// all your stuff

            }

Are you sure you have permission to make calls?

You need the CALL_PHONE permission. Make sure you have this in your AndroidManifest.xml:

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

My other guess is mobileNo is null when you are trying to call mobileNo.trim() .

The only way to know for sure is to see the log. You may need to change the logcat view setting on Android Studio to 'Verbose.'

Alternatively you can use adb logcat to view the log in a terminal. Watch the log while you replicate the force close and you should be able to find the exception causing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM