她就是我試圖完成:BroadcastReceiver with intent-filter for them?
- 當用戶試圖分享任何應用中的一些文字(例如分享鳴叫或鏈接),我的應用程序將出現在共享列表。
- 如果他選擇我的應用程序,將運行一些簡單的代碼(如顯示Toast),就是這樣。不需要界面或UI。
這是我如何做的:
AndroidManifest.xml中
<receiver
android:name=".MyBroadcastReceiver" >
<intent-filter
android:label="select my app">
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</receiver>
MyBroadcastReceiver.java
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
//Some simple code
Toast.makeText(arg0, "My Receiver is cool", Toast.LENGTH_LONG).show();
}
這沒有工作,我的應用程序沒有按不會顯示在共享列表中。
爲什麼我使用BroadcatReceivers
而不是Activities
?因爲我不想要任何用戶界面,我認爲這就是爲什麼我們有接收器(糾正我的PLZ)
我做對了嗎?
問題解決。謝謝 ! – iTurki