Android:放送優先度、sendOrderedBroadcast、メール電話放送、abortBroadcast、ResultData
4889 ワード
ブロードキャスト優先度は、送信順序ブロードキャストメソッドを使用して有効になります.
XMLファイルのブロードキャスト優先度の設定:
電話の呼び出し放送を受信し、自動的に番号の接頭辞を追加して呼び出す.メール受信者の最高優先度を設定し、メールをブロックします.
XML権限および優先度の設定:
電話発信放送受信:
メール受信者:
本文は“空は痕跡がありませんが私は飛んだことがあります”のブログから出て、転載して作者と連絡してください!
findViewById(R.id.button1).setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setAction("com.example.aex56");
intent.putExtra("key", "value");
sendOrderedBroadcast(intent, null);//
}
});
XMLファイルのブロードキャスト優先度の設定:
<receiver
android:name="com.example.aex56_ordered_broadcast.MyReceiver1"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="2500">
<action android:name="com.example.aex56" />
</intent-filter>
</receiver>
<receiver
android:name="com.example.aex56_ordered_broadcast.MyReceiver2"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="3000">
<action android:name="com.example.aex56" />
</intent-filter>
</receiver>
電話の呼び出し放送を受信し、自動的に番号の接頭辞を追加して呼び出す.メール受信者の最高優先度を設定し、メールをブロックします.
XML権限および優先度の設定:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.aex58_ordered_tel"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver
android:name="com.example.aex58_ordered_tel.MyTelReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
<receiver
android:name="com.example.aex58_ordered_tel.MySmsReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter android:priority="9999999999999999999999999999999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
電話発信放送受信:
public class MyTelReceiver extends BroadcastReceiver
{
//
/*1.
* uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"
*
*2.
* <intent-filter >
* <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
* </intent-filter>
*
* :
* android.intent.action.BOOT_COMPLETED
*/
@Override
public void onReceive(Context context, Intent intent)
{
String telnum = getResultData();//
telnum = "0592" + telnum;
setResultData(telnum);//
}
}
メール受信者:
public class MySmsReceiver extends BroadcastReceiver
{
/*
*
* 1.
* uses-permission android:name="android.permission.RECEIVE_SMS"
*
* 2. ,
* <intent-filter android:priority="99999999999999999999999999">
* <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
* </intent-filter>
*
* 3. onReceive
* abortBroadcast();
*/
@Override
public void onReceive(Context context, Intent intent)
{
Log.e("msg", "mmm");
abortBroadcast();//
}
}
本文は“空は痕跡がありませんが私は飛んだことがあります”のブログから出て、転載して作者と連絡してください!