Android Manifest冲突导致sms权限无效

时间:2016-02-25 16:13:56

标签: android android-studio

我遇到这个问题,当在android清单中包含以下代码时发送短信时,短信权限不起作用。

   <activity android:name=".engine.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

如果我用这个替换这个代码:

 <activity
                android:name=".SendSmsActivity"
                android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

短信开始工作。我也尝试在冲突的代码下添加第二个代码:

 <activity android:name=".ui.SendSmsActivity">

        </activity>

但这也不起作用。任何帮助将不胜感激。我已经被困在这几天了。

Android Manifeset

  <?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android_auto">


        <uses-feature android:glEsVersion="0x00020000" android:required="true" />
        <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="com.google.android.providers.gsf.permission.READ_GSERVICES" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />


        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="22" />
        <uses-permission android:name="android.permission.SEND_SMS" />


        <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name"
            android:supportsRtl="true" android:theme="@style/AppTheme">



            <activity android:name=".engine.MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>


  <activity android:name=".ui.SendSmsActivity">

            </activity>


            <activity android:name=".ui.MapsActivity1">

            </activity>

            <meta-data android:name="com.google.android.gms.car.application" android:resource="@xml/automotive_app_desc" />
            <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyCMFYfJ6aOuxJk3W0vmhF6Nou3TP_qIU6c" />

            <meta-data android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
            <!--
         Main music service, provides media browsing and media playback services to
                 consumers through MediaBrowserService and MediaSession. Consumers connect to it through
                 MediaBrowser (for browsing) and MediaController (for playback control)
                -->
            <service android:name=".MyMusicService" android:exported="true">
                <intent-filter>
                    <action android:name="android.media.browse.MediaBrowserService" />
                </intent-filter>
            </service>
            <service android:name=".MyMessagingService" />

            <receiver android:name=".MessageReadReceiver">
                <intent-filter>
                    <action android:name="com.example.zachboone.myapplication.ACTION_MESSAGE_READ" />
                </intent-filter>
            </receiver>
            <receiver android:name=".MessageReplyReceiver">
                <intent-filter>
                    <action android:name="com.example.zachboone.myapplication.ACTION_MESSAGE_REPLY" />
                </intent-filter>
            </receiver>

        </application>




    </manifest>

SendSmsActivity.java

package aaa_android_auto.ui;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import android_auto.R;


public class SendSmsActivity extends Activity {

    Button buttonSend;
    EditText textPhoneNo;
    EditText textSMS;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sms);

        buttonSend = (Button) findViewById(R.id.buttonSend);
        textPhoneNo = (EditText) findViewById(R.id.editTextPhoneNo);
        textSMS = (EditText) findViewById(R.id.editTextSMS);

        buttonSend.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                String phoneNo = textPhoneNo.getText().toString();
                String sms = textSMS.getText().toString();

                try {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phoneNo, null, sms, null, null);
                    Toast.makeText(getApplicationContext(), "SMS Sent!",
                            Toast.LENGTH_LONG).show();
                } catch (Exception e) {
                    Toast.makeText(getApplicationContext(),
                            "SMS faild, please try again later!",
                            Toast.LENGTH_LONG).show();
                    e.printStackTrace();
                }

            }
        });
    }
}

0 个答案:

没有答案