有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SMS消息传递未发送

我一直在关注一段视频,所有内容都在编辑中,但当我点击send时,祝酒词从未出现,信息也从未出现在我的手机上。我还在Android清单中添加了发送短信权限。有什么建议吗

SendSmsActivity.java





package 安卓_auto.engine;

        import 安卓.app.Activity;
        import 安卓.net.Uri;
        import 安卓.os.Bundle;
        import 安卓.telephony.SmsManager;
        import 安卓.view.View;
        import 安卓.widget.Button;
        import 安卓.widget.EditText;
        import 安卓.widget.Toast;

        import com.google.安卓.gms.appindexing.Action;
        import com.google.安卓.gms.appindexing.AppIndex;
        import com.google.安卓.gms.common.api.GoogleApiClient;

        import 安卓_auto.R;

public class SendSmsActivity extends Activity {

    Button sendSMSBtn;
    EditText toPhoneNumberET;
    EditText smsMessageET;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sms_activity);
        sendSMSBtn = (Button) findViewById(R.id.sendSMSBtn);
        toPhoneNumberET = (EditText) findViewById(R.id.toPhoneNumberET);
        smsMessageET = (EditText) findViewById(R.id.smsMessageET);
        sendSMSBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                sendSMS();
            }
        });
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
    }

    protected void sendSMS() {
        String toPhoneNumber = toPhoneNumberET.getText().toString();
        String smsMessage = smsMessageET.getText().toString();
        try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(toPhoneNumber, null, smsMessage, null, null);
            Toast.makeText(getApplicationContext(), "SMS sent.",
                    Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(),
                    "Sending SMS failed.",
                    Toast.LENGTH_LONG).show();
            e.printStackTrace();
        }
    }

    @Override
    public void onStart() {
        super.onStart();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        client.connect();
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "SendSms Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("安卓-app://cen4910.ucf.edu.aaa_安卓_auto.engine/http/host/path")
        );
        AppIndex.AppIndexApi.start(client, viewAction);
    }

    @Override
    public void onStop() {
        super.onStop();

        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.
        Action viewAction = Action.newAction(
                Action.TYPE_VIEW, // TODO: choose an action type.
                "SendSms Page", // TODO: Define a title for the content shown.
                // TODO: If you have web page content that matches this app activity's content,
                // make sure this auto-generated web page URL is correct.
                // Otherwise, set the URL to null.
                Uri.parse("http://host/path"),
                // TODO: Make sure this auto-generated app deep link URI is correct.
                Uri.parse("安卓-app://cen4910.ucf.edu.aaa_安卓_auto.engine/http/host/path")
        );
        AppIndex.AppIndexApi.end(client, viewAction);
        client.disconnect();
    }
}

sms_活动。xml

  <LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="fill_parent"
    安卓:layout_height="fill_parent"
    安卓:orientation="vertical" >

    <TextView
        安卓:id="@+id/toPhoneNumberTV"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="Phone Number" />

    <EditText
        安卓:id="@+id/toPhoneNumberET"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:inputType="phone"/>

    <TextView
        安卓:id="@+id/smsMessageTV"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:text="SMS Message" />

    <EditText
        安卓:id="@+id/smsMessageET"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:inputType="textMultiLine"/>

    <Button 安卓:id="@+id/sendSMSBtn"
        安卓:layout_width="fill_parent"
        安卓:layout_height="wrap_content"
        安卓:text="Send SMS"/>

</LinearLayout>

安卓清单

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

    <uses-permission 安卓:name="ANDROID.PERMISSION.SEND_SMS"/>


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


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

                <category 安卓:name="安卓.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <meta-data
            安卓:name="com.google.安卓.gms.car.application"
            安卓:resource="@xml/automotive_app_desc" />
        <!--
 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
            安卓:name=".MyMusicService"
            安卓:exported="true">
            <intent-filter>
                <action 安卓:name="安卓.media.browse.MediaBrowserService" />
            </intent-filter>
        </service>

        <service 安卓:name=".MyMessagingService"></service>

        <receiver 安卓:name=".MessageReadReceiver">
            <intent-filter>
                <action 安卓:name="com.example.myapplication.ACTION_MESSAGE_READ" />
            </intent-filter>
        </receiver>
        <receiver 安卓:name=".MessageReplyReceiver">
            <intent-filter>
                <action 安卓:name="com.example.myapplication.ACTION_MESSAGE_REPLY" />
            </intent-filter>
        </receiver>
        <!-- ATTENTION: This was auto-generated to add Google Play services to your project for
             App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information. -->
        <meta-data
            安卓:name="com.google.安卓.gms.version"
            安卓:value="@integer/google_play_services_version" />
    </application>

</manifest>

共 (1) 个答案

  1. # 1 楼答案

    我在你的舱单上看不到你的发送活动正常吗