0

アプリ内からAndroidシェルへの呼び出しを追加する作業をしています。私はシェルスクリプトまたは基本的なシェルコマンドを非常にうまく呼び出すことができましたが、今私は電子メールを送信しようとしています(主に私ができるかどうかを知るために)そして奇妙なエラーに遭遇しています:

11-06 16:14:43.449: D/AndroidRuntime(28655): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
11-06 16:14:43.449: D/AndroidRuntime(28655): CheckJNI is OFF
11-06 16:14:43.629: D/AndroidRuntime(28655): Calling main entry com.android.commands.am.Am
11-06 16:14:43.639: D/AndroidRuntime(28655): Shutting down VM
11-06 16:14:43.639: I/ActivityManager(204): START {act=android.intent.action.SENDTO typ="text/plain" flg=0x10000000 pkg=Goes (has extras)} from pid 28655
11-06 16:14:43.649: D/dalvikvm(28655): GC_CONCURRENT freed 104K, 81% free 495K/2560K, paused 0ms+1ms
11-06 16:14:43.649: D/dalvikvm(28655): Debugger has detached; object registry had 1 entries
11-06 16:14:43.649: I/AndroidRuntime(28655): NOTE: attach of thread 'Binder Thread #2' failed

私のシェルによって実行されるコードはこれです:

am start -a android.intent.action.SENDTO -t "text/plain" --es android.intent.extra.EMAIL "myaddress@example.com" --es android.intent.extra.TEXT "Message Goes here" --es android.intent.extra.SUBJECT "this is the subject"

何が問題になっていますか、どうすれば修正できますか?使用する必要のある別のツール(以外am)はありますか?

4

3 に答える 3

1

adbシェルを使用している場合は、これを試してください。

am start -a android.intent.action.SENDTO -d sms:xxx --es sms_body "xxx" --ez exit_on_sent true
input keyevent 66

Android 4.0(ICS)を実行しているDroidXを試してみました。SMSを送信して終了します。これが役に立ったら教えてください。

よろしく、

于 2012-11-07T00:24:28.560 に答える
1

このコードを試してメールを送信してください。adbにはサードパーティの権限がないため、このコードを実際のデバイスで実行します

パッケージcom.rmn.emailSending;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EmailSendingActivity extends Activity {
    Button send;
    EditText address, subject, emailtext;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        send = (Button) findViewById(R.id.emailsendbutton);
        address = (EditText) findViewById(R.id.emailaddress);
        subject = (EditText) findViewById(R.id.emailsubject);
        emailtext = (EditText) findViewById(R.id.emailtext);

        send.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                emailIntent.setType("message/rfc822");
                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { address.getText().toString() });
                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject.getText().toString());
                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,emailtext.getText().toString());
                EmailSendingActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail in"));

            }
        });
    }
}
于 2012-11-07T06:53:35.347 に答える
1

amこれを何度も試みた結果、デバイス上からアクティビティを開始することはできないと私は信じるようになりました。ただし、アクティビティを開始するために使用できるブロードキャストを送信することはできます。たとえば、カメラアプリを起動するには、次のコマンドを使用できます。

am broadcast -a android.intent.action.CAMERA_BUTTON
于 2012-11-07T22:00:25.563 に答える