0

I have an android app that uses the permission "CALL_PHONE". This simple app would just contain a button that would use the call intent to call a specific number. I would like to install this app on both tablets and phone but when it is installed on the tablet, I would like the button to be disabled during runtime so errors wouldn't show when the user tries to call using the tablet without a call function.

At the moment, I am using the setEnabled() and setClickable() method in my MainActivity.java and setting it to false when the user clicks on the button the first time. My question is whether the button can be disabled and the text changed during runtime or when the app is first opened (in a tablet) so the user wouldn't have to click the button first for it to show that the "call" button should be disabled and unclickable?

Rathakrishnan Ramasamy
  • 1,612
  • 2
  • 25
  • 46
SamIAm
  • 2,241
  • 6
  • 32
  • 51

3 Answers3

2

Refer to this

That will help you in identifying that your application is running on tablet. Now as for disabling your button, I would suggest something like this:

onCreate()
{
     setContentView(R.layout.main);
     boolean isTablet = checkDevice();
     callBtn = (Button) findViewById(R.id.call);
     if (isTablet)
     {
        callBtn.setEnabled(false);
        callBtn.setText("Not allowed to make a call");
     }

     callBtn.setOnClickListener( new onClickListener(){
           //Make a call
     });

}

public boolean isTablet()
{

    //Code for identifying. Return true if application is running on tablet
    //return false otherwise

}

So you won't have to wait for user's click on Call button to disable it in tablet. Hope that helps.

Community
  • 1
  • 1
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • Brilliant. I was looking for something like this but I couldn't wrap my head around it earlier. The link to checking whether the user is using a tablet or not is useful. I'm going to try using telephony service instead of size to check if it has calling capabilities. – SamIAm Dec 28 '12 at 09:03
1

Use button.setEnabled(false); to make visible but user cant click and
button.setVisibility(View.GONE); to make button invisible.and button.setText("YOUR_NEW_TEXT"); to change the button text runtime

And this is not depend on the size of the screen.

Is this you wanted?? OR be more specific with your queston.

Narendra Pal
  • 6,474
  • 13
  • 49
  • 85
0

... the text changed during runtime?

You can use the setText(); method.

About the other part of your question, you need first to define "What is a tablet?". Is it a 7", 8", 10" screen? Is it a mdpi, hdpi, xhdpi screen? Is it a device which is able to do phone calls? What is a tablet for you or your project? Depending on your answer, you can filter your code (or xml in folders) to make them work the way you want.

gian1200
  • 3,670
  • 2
  • 30
  • 59