我写了一个很简单的例子。可就是没有反应。找了半天也找不到哪里出了错误。希望大家帮忙看看。。旁观者清啊。。谢谢。MainActivity.javapublic class MainActivity extends Activity {
private static final String INTENAL_ACTION_1 = "su1.bluetooth.true";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(INTENAL_ACTION_1);
sendBroadcast(intent);
}
}
BroadcastRecTest.javapublic class BroadcastRecTest extends BroadcastReceiver{
private static final String INTENAL_ACTION_1="su1.bluetooth.true";
private static final String TAG = "BroadcastRecTest";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(INTENAL_ACTION_1)){
Log.d(TAG,"1231321323");
Toast.makeText(context, action, 0).show();
}
}}
AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.biz"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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>
<reciver android:name="BroadcastRecTest">
<intent-filter>
<action android:name="su1.bluetooth.true"/>
</intent-filter>
</reciver>
</application>
</manifest>
private static final String INTENAL_ACTION_1 = "su1.bluetooth.true";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = new Intent(INTENAL_ACTION_1);
sendBroadcast(intent);
}
}
BroadcastRecTest.javapublic class BroadcastRecTest extends BroadcastReceiver{
private static final String INTENAL_ACTION_1="su1.bluetooth.true";
private static final String TAG = "BroadcastRecTest";
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(INTENAL_ACTION_1)){
Log.d(TAG,"1231321323");
Toast.makeText(context, action, 0).show();
}
}}
AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.biz"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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>
<reciver android:name="BroadcastRecTest">
<intent-filter>
<action android:name="su1.bluetooth.true"/>
</intent-filter>
</reciver>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.biz"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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>
<reciver android:name="BroadcastRecTest">
<intent-filter>
<action android:name="su1.bluetooth.true"/>
</intent-filter>
</reciver>
</manifest>