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

时间:2013-04-16 11:03:48

标签: android

我在Play商店发布了我的应用程序,但它不适用于平板电脑。我在Google Play商店检查了应用程序的功能,经过一些研究发现我的应用程序有一些Telephony功能,我认为这是有罪的一方。这是我的清单文件。

<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" />

我相信<uses-permission android:name="android.permission.SEND_SMS" />会激活电话功能。但是,我需要此权限才能发送短信。任何人都可以告诉我,如果在平板电脑上运行,是否有另一种方法可以通过。

2 个答案:

答案 0 :(得分:15)

为您的Manifest添加一个uses-feature块:

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

以上说明设备在您的应用程序中使用了此功能。但是,android:required="false"确保这不是一项严格的要求,无论支持android.hardware.telephony功能的设备如何,都会安装该应用程序。

但是,这会创建一个新的问题。不用担心。随后是解决方案。 : - )

当不支持android.hardware.telephony功能的设备试图以任何方式使用该功能时会发生什么?在您的情况下,发送短信。一个简单的解决方案是检查设备是否具有使用Telephony功能的能力。

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
}

我认为这是一种解决方法,以防它运行的设备是CDMA设备。

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
}

上述任何一个代码块都需要READ_PHONE_STATE权限:

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

如果设备具有上述功能,还有一种方法可以检查(使用PackageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY))。我个人从未到过测试它,但OP表明它有效。 https://stackoverflow.com/a/6568243/450534

答案 1 :(得分:2)

您忘了将xlargeScreens添加到Manifest

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

编辑: <uses-permissions>标记未强制设备上的任何硬件或功能,只有<uses-feature>标记强制执行功能,required设置为true