我在清单文件中声明了一个活动和一个广播接收器,但是,我的onReceive()
活动中的代码作为一个单独的公共类。当我尝试从 adb 命令行触发广播时,出现classnotfound
错误。
我的问题是,是否必须broadcastreceiver
在单独的文件中将其作为单独的类?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityAsDialogActivity.this.requestWindowFeature(Window.FEATURE_NO_TITLE);
:
:
}
public class TestEmail extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(MYINTENT)){
Log.d("Manju ==>","ActivityAsDialogActivity, Got the intent"+MYINTENT);
Toast.makeText(context, "Don't panik but your time is up!!!!.",
Toast.LENGTH_LONG).show();
}//end of if statment
}//end of onReceiver
}//end of Broadcast
}//end of class ActivityAsDialogActivity
下面是清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mot.activityasdialog"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".ActivityAsDialogActivity"
android:excludeFromRecents="true"
android:theme="@style/EmptyActivity"
android:configChanges="keyboardHidden|orientation|screenSize|uiMode">
<!-- android:theme="@android:style/Theme.Holo.Dialog"
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="com.mot.activityasdialog.ActivityAsDialogActivity.TestEmail" android:enabled="true">
<intent-filter>
<action android:name="com.mot.MANJU"></action>
</intent-filter>
</receiver>
</application>
</manifest>