Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.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.lang.RuntimeException:无法实例化接收方:java.lang.ClassNotFoundException 我尝试在我的项目中使用电话管理器和广播接收器实现自动应答 它工作正常,但不幸的是,当我再次打开手机时,应用程序崩溃了。随信附上我的代码和清单文件。有人能帮我们解决吗_Java_Android - Fatal编程技术网

java.lang.RuntimeException:无法实例化接收方:java.lang.ClassNotFoundException 我尝试在我的项目中使用电话管理器和广播接收器实现自动应答 它工作正常,但不幸的是,当我再次打开手机时,应用程序崩溃了。随信附上我的代码和清单文件。有人能帮我们解决吗

java.lang.RuntimeException:无法实例化接收方:java.lang.ClassNotFoundException 我尝试在我的项目中使用电话管理器和广播接收器实现自动应答 它工作正常,但不幸的是,当我再次打开手机时,应用程序崩溃了。随信附上我的代码和清单文件。有人能帮我们解决吗,java,android,Java,Android,代码: AutoAnswerReceiver.java public class AutoAnswerReceiver extends BroadcastReceiver { SharedPreferences mPrefs; static String PREFS_NAMES = "AutoAnswer"; @Override public void onReceive(Context context, Intent intent) { mP

代码:

AutoAnswerReceiver.java

public class AutoAnswerReceiver extends BroadcastReceiver {

    SharedPreferences mPrefs;
    static String PREFS_NAMES = "AutoAnswer";
    @Override
    public void onReceive(Context context, Intent intent) {

        mPrefs = context.getSharedPreferences(PREFS_NAMES, 0);

        String AutoResult = mPrefs.getString("AutoAnswer", "FALSE");

        // Check phone state
        String phone_state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
        String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);

        if (phone_state.equals(TelephonyManager.EXTRA_STATE_RINGING) && AutoResult.equals("TRUE"))
        {
                context.startService(new Intent(context, AutoAnswerIntentService.class));

        }
        }

    **AutoAnswerIntentService**

public class AutoAnswerIntentService extends IntentService {

    public AutoAnswerIntentService() {
        super("AutoAnswerIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Context context = getBaseContext();


        // Let the phone ring for a set delay
        try {
            Thread.sleep(Integer.parseInt("5") * 1000);
        } catch (InterruptedException e) {
            // We don't really care
        }


        // Make sure the phone is still ringing
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getCallState() != TelephonyManager.CALL_STATE_RINGING) {
            return;
        }

        // Answer the phone
        try {
            answerPhoneAidl(context);
        }
        catch (Exception e) {
            e.printStackTrace();
            Log.d("AutoAnswer","Error trying to answer using telephony service.  Falling back to headset.");
            answerPhoneHeadsethook(context);
        }

        // Enable the speakerphone

            enableSpeakerPhone(context);

        return;
    }

    private void enableSpeakerPhone(Context context) {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setSpeakerphoneOn(true);
    }

    private void answerPhoneHeadsethook(Context context) {
        // Simulate a press of the headset button to pick up the call
        Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON);     
        buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK));
        context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED");

        // froyo and beyond trigger on buttonUp instead of buttonDown
        Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON);       
        buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK));
        context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED");
    }

    @SuppressWarnings("unchecked")
    private void answerPhoneAidl(Context context) throws Exception {
        // Set up communication with the telephony service (thanks to Tedd's Droid Tools!)
        TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        ITelephony telephonyService;
        telephonyService = (ITelephony)m.invoke(tm);

        // Silence the ringer and answer the call!
        telephonyService.silenceRinger();
        telephonyService.answerRingingCall();
    }
}
Manifestfile

<receiver android:name=".AutoAnswerReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.PHONE_STATE" />
    </intent-filter>
</receiver>
<receiver android:name=".AutoAnswerBootReceiver" android:enabled="true">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>
<service android:name="AutoAnswerIntentService" />

下面是类文件,它是:

创建一个名为
autoanswerbootceiver.java的文件

package com.example.autoanswer;  // Just change the package name to yours

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AutoAnswerBootReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
                AutoAnswerNotifier notifier = new AutoAnswerNotifier(context);
                notifier.updateNotification();
        }

}

这个
自动应答引导接收器在哪里
?错误是正确的。您没有名为AutoAnswerBootReceiver的类我理解这些错误…谢谢。。。。
package com.example.autoanswer;  // Just change the package name to yours

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class AutoAnswerBootReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
                AutoAnswerNotifier notifier = new AutoAnswerNotifier(context);
                notifier.updateNotification();
        }

}