我正在尝试根据我自己的 URI 接收一个简单的自定义意图。
这是我的清单:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.intenttest.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="com.example.intenttest.TestReceive"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="testo" />
</intent-filter>
</receiver>
</application>
我的接收器非常简单:
public class TestReceive extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
Log.d("", "YAY!!!!!");
Toast.makeText(context, "TEST!!!", Toast.LENGTH_LONG).show();
}
}
当我尝试浏览 testo://blahblah 或通过 URI Launer 发出此意图时,我的接收器没有被触发。
这是模拟从不同应用程序触发意图的代码:
String url = "testo://test/test";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
sendBroadcast( i );
但是当我将<intent-filer>
块移动到<activity>
清单中的标签时,该活动被触发。
我怎样才能让我的接收者收到意图?