清单文件中的Receiver提供错误类或预期的接口

时间:2016-07-09 14:11:05

标签: java android manifest

清单文件中有一个错误,当我尝试输入收件人时,它表示预期的类或接口

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uzairaslam.silenter" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS_" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

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


    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>
<receiver android:name="AlarmReceiver"/>

未添加的接收器类是

公共类AlarmReceiver扩展了BroadcastReceiver {

SQLiteDatabase db;
String d ;
String deviceard;
String roomard ;
boolean status ;
public AlarmReceiver() {

}


@Override
public void onReceive(Context context, Intent intent) {



    d= intent.getStringExtra("DeviceId");
    deviceard = intent.getStringExtra("Device_Ard_Id");
    roomard = intent.getStringExtra("Room_Ard_id");
    status = Boolean.parseBoolean(intent.getStringExtra("Device_Status"));

    if(status)
        Send_sms("y"+roomard+":"+deviceard+":oz" ,context);
    else
        Send_sms("y"+roomard+":"+deviceard+":fz" ,context);

    Toast.makeText(context,"Mateen",Toast.LENGTH_LONG).show();


}

public void Send_sms(String msg,Context c)
{
    Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
    if (alarmUri == null) {
        alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    }
    Ringtone ringtone = RingtoneManager.getRingtone(c, alarmUri);
    ringtone.play();


}

}

1 个答案:

答案 0 :(得分:0)

<receiver android:name="AlarmReceiver"/>

此行应与应用程序标记一起使用,并提供完全限定的Receiver名称。如下所示

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


    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name="<receiver package>.AlarmReceiver"/>

</application>