小编Jaa*_*ack的帖子

通过textview打开默认短信应用

我想通过一个打开默认的短信应用程序TextView.我对如何做到这一点有一个粗略的想法,但我不是100%肯定.我已经查阅了多个关于此的教程和问题,并且没有对它进行简单的覆盖.

这主要是Java我遇到麻烦的事情的一面.我已经设置了我希望代码进入的类,并设置了XML textview来响应Onclicks.

感谢Java中的代码看起来有些麻烦.

更新了代码,在"context","text","phoneNumber"和"smsOnClicklistener"上收到错误.我得到的错误是无法解决变量:

package com.youtube.iamjackpot;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.TextView;

public class InfomenuActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_infomenu);

    TextView textView3 = (TextView) findViewById(R.id.textView3);
    smsOnClickListener = new View.OnClickListener() {

        public void onClick(View v) {
            Intent smsIntent = new Intent(
                    android.content.Intent.ACTION_VIEW);
            smsIntent.setType("vnd.android-dir/mms-sms");
            smsIntent.putExtra("address", phoneNumber);
            smsIntent.putExtra("sms_body", text);
            context.startActivity(Intent.createChooser(smsIntent,"SMS:"));
        }

    };

}
}
Run Code Online (Sandbox Code Playgroud)

eclipse sms android

1
推荐指数
1
解决办法
3403
查看次数

标签 统计

android ×1

eclipse ×1

sms ×1