0
我想知道我们如何通过AndroidManifest.xml中注册静态广播接收器安卓:如何声明静态广播接收机
我班的BroadcastReceiver类
public class YourBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle == null)
return;
String phoneNumber = null;
// Incoming call
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
if ((state != null)&&(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))) {
phoneNumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
// Here: do something with the number
}
// Outgoing call
else if (state == null) {
phoneNumber = bundle.getString(Intent.EXTRA_PHONE_NUMBER);
// Here: do something with the number
}
}
}
我AnrdoidMainfest.xml文件中我得到错误在该行<receiver android:name=".YourBroadcastReceiver">
<?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gfun.Andp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.gfun.Andp.main"
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=".YourBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"></action>
</intent-filter>
</receiver>
</application>
</manifest>
关于我的项目(类或接口预期),它有两个模块和第二个模块完全是Asynctask线程运行的主要活动,我想这个广播接收器为第二个模块。
正在使用过Android Studio 0.4.4 所以需要帮助
雅全名com.gfun.Andp.YourBroadcastReceiver我也试过,不工作相同的错误。我认为android工作室可能有不同的模式来注册广播接收器,我在互联网上搜索,但所有关于广播接收器的教程都在eclipse studio中 – user3315024