Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的android程序无法重放_Java_Android_Html_Android Layout_Samsung Mobile - Fatal编程技术网

Java 我的android程序无法重放

Java 我的android程序无法重放,java,android,html,android-layout,samsung-mobile,Java,Android,Html,Android Layout,Samsung Mobile,嗯,我已经使这个程序,它接收短信和自动重播,但它接收,但不重播 这是我的Reciver class.java import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.widget.Toast

嗯,我已经使这个程序,它接收短信和自动重播,但它接收,但不重播 这是我的Reciver class.java

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class Reciving  extends BroadcastReceiver{
static String from;
static String body;

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method s
      //---get the SMS message passed in---
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";            
    if (bundle != null)
    {
        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
         from =   str +=  "SMS from " + msgs[i].getOriginatingAddress();              
            str += " :";
       body =  str += msgs[i].getMessageBody().toString();
            str += "\n";

        }
        //---display the new SMS message---
        Toast.makeText(context, str, Toast.LENGTH_LONG).show();
       // ret = str;
        SendGlass obj = new SendGlass();
        //   int tos =  Integer.valueOf(body);
         //  obj.Decision(from, tos);

        if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED"))
        {
        Main_Activity obj = new Main_Activity();

       obj.sms(from, body1);

        }
    else{

        }    

    }
}
}
My menifest.xml

   <manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="dom.example.dbfinal"
  android:versionCode="1"
   android:versionName="1.0" >

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


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Screen1"
        android:label="@string/title_activity_screen1" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

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

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".Reciving" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" > 
           </action>     
        </intent-filter>
    </receiver>
</application>


有谁能告诉我当短信接收但不重播时显示toast的问题吗?

从不执行
Main_Activity obj=new Main_Activity()活动只能由操作系统处理,创建一个实用程序类

onreceive
不能保证在应用程序UI线程上。请尝试:

尝试使用显式设置活套的处理程序:

final SmsManager smsManager = SmsManager.getDefault();
Handler h = new Handler(Looper.getMainLooper());
    h.post(new Runnable()
    {

        @Override
        public void run()
        {
            // Check that Your number is formatted correclty and that your body is LESS than 140 chars!
            smsManager.sendTextMessage("4412345123456", null, "", null, null);
        }
    });
final SmsManager smsManager = SmsManager.getDefault();
Handler h = new Handler(Looper.getMainLooper());
    h.post(new Runnable()
    {

        @Override
        public void run()
        {
            // Check that Your number is formatted correclty and that your body is LESS than 140 chars!
            smsManager.sendTextMessage("4412345123456", null, "", null, null);
        }
    });