我在Android Studio中创建了一个项目,当我打电话给别人显示日志时,但它不起作用。 的 BroadcastReceiver.java
package com.example.callphone.call;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
/**
* Created by 鱼呀鱼呀鱼籽酱 on 2016/4/23.
*/
public class OnCallReceiver extends BroadcastReceiver {
private static final String TAG = "OnCallReceiver" ;
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "aaa");
}
}
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callphone.call">
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.example.callphone.call.OnCallReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
</application>
</manifest>
当我拨打号码时,我无法看到登录logcat。
但我在Eclipse中键入相同的代码,它可以工作。 Eclipse中有代码:
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callphone"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.callphone.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.callphone.callPhoneReceiver">
<intent-filter>
<action android:name="android.intent.action.NEW_OUTGOING_CALL"/>
</intent-filter>
</receiver>
</application>
</manifest>
callPhoneReceiver
package com.example.callphone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class callPhoneReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
System.out.println("aaa");
}
}
在Eclipse中使用此代码是有效的。 为什么? 我是中国人。我的英语很差,希望你能理解我说的话...... QAQ