import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class CallPhonetReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String number=getResultData();
if("123456".equals(number)){
setResultData(null);
Intent intentMainActivity=new Intent(context,LostActivity.class);
intentMainActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentMainActivity);
}
}
}
清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.NewOutGoing"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
<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>
<activity android:name=".LostActivity" ></activity>
<receiver android:name=".CallPhonetReceiver">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
当初把receiver写错了,导致一直监听不了。。。R E C E I V E R
这样就可以了。先运行程序,然后拨打123456就可以跳到另一个activity了。