Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

I published my application on Play Store but it is not available for tablets. I checked the functionality of the application on Google play store and after some research found that my application has some Telephony features which I believe is the guilty party. Here is my manifest file.

<uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.SEND_SMS" />

    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />

    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name=".permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

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

    <!-- This app has permission to register and receive data message. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- Keeps the device on vibrating mode when a message is received. -->
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar" >

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="" />
            </intent-filter>
        </receiver>

        <service android:name=".GCMIntentService" />

        <activity
            android:name=".Splash"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
        </activity>

           <activity
            android:name=".SelectedArticlePush"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".ActusScreen"
            android:screenOrientation="portrait">
        </activity>

          <activity
            android:name=".MentionLegale"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".SelectedArticle"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateAlwaysHidden|adjustPan">>
        </activity>

        <activity
            android:name=".ReglementScreen"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".SelectedReglementation"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".FavoriteScreen"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".AlertScreen"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".ClubScreen"
            android:screenOrientation="portrait">
        </activity>

         <activity
            android:name="ClubMi"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".DisplayWeb"
            android:screenOrientation="portrait">
        </activity>

         <activity
            android:name=".Contact"
            android:screenOrientation="portrait">
        </activity>

         <activity
            android:name=".tab.TabClubMi"
            android:screenOrientation="portrait">
        </activity>

        <activity
            android:name=".SMS"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.Transparent" >
        </activity>

    </application>

     <supports-screens 
          android:largeScreens="true" 
          android:normalScreens="true" 
          android:smallScreens="true" 
          android:resizeable="true" 
          android:anyDensity="true" />

I believe <uses-permission android:name="android.permission.SEND_SMS" /> activates the Telephony functionality. However I need this permission to send sms. Can any one tell me if there is an alternate way to by pass this if running in a Tablet.

like image 317
yakusha Avatar asked Apr 16 '13 11:04

yakusha


2 Answers

Add a uses-feature block to your Manifest:

<uses-feature
    android:name="android.hardware.telephony"
    android:required="false" >
</uses-feature>

The above tells the device that this feature is used in your application. The android:required="false" however, ensures that this is not a stringent requirement and will install the application regardless of the device supporting the android.hardware.telephony feature.

This however, creates a new problem. Worry not. A solution follows. :-)

What happens when a device which does not support the android.hardware.telephony feature tries to use the function any way? In your case, sending out an SMS. A simple solution is, to check if the device has the capability to use the Telephony features.

TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE)  {
    // SHOW A DIALOG, A TOAST OR A NOTIFICATION TO TELL THE USER THAT THE FEATURE IS MISSING
} else {
    // RUN THE CODE TO SEND OUT THE SMS
}

And I think this is a workaround in case the device it is being run on is a CDMA device.

String strTM = ((TelephonyManager) getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE)).getLine1Number();
if (strTM == null)  {
    // SHOW A DIALOG, A TOAST OR A NOTIFICATION TO TELL THE USER THAT THE FEATURE IS MISSING
} else {
    // RUN THE CODE TO SEND OUT THE SMS
}

Either of the code blocks above, need the READ_PHONE_STATE permission:

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

There is one more way of checking (using PackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) if the device has the said features. I have personally never gotten around to test it, but the OP indicates it works. https://stackoverflow.com/a/6568243/450534

like image 189
Siddharth Lele Avatar answered Sep 22 '22 17:09

Siddharth Lele


You forgot to add the xlargeScreens to your Manifest.

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:xlargeScreens="true" />

EDIT: the <uses-permissions> tag does not enforce any hardware or capabilities on the device, just the <uses-feature> tag enforces capabilities, when required is set to true.

like image 32
Ovidiu Latcu Avatar answered Sep 19 '22 17:09

Ovidiu Latcu