来电屏幕修改

时间:2014-12-03 12:14:02

标签: android

我是Android开发的新手,并尝试创建一个应用程序,我可以在来电屏幕上显示来自通话记录的用户信息。我想在我用过烤面包但不可点击的屏幕上显示信息。我想要像按钮/图像一样可点击的东西。如果有人有任何想法,请建议。

类似于http://i.imgur.com/MFhVyqB.jpg

的内容

这是代码`

public class IncomingCall extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    try {
        TelephonyManager telMgr = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        PretextaPhoneListener phoneListener = new PretextaPhoneListener(
                context);
        telMgr.listen(phoneListener, phoneListener.LISTEN_CALL_STATE);
    } catch (Exception e) {
        Log.e("error on receive", ""+ e);
    }
}

private class PretextaPhoneListener extends PhoneStateListener {
    Context mContext = null;
    ActivityManager activityManager;
      Intent i1;
    public PretextaPhoneListener(Context context) {
         super();
        mContext = context;
         i1 = new Intent(context, TelephoneyWithoutToastActivity.class);
          i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    public void onCallStateChanged(int state, String incomingNumber) {
        // default implementation empty
        Log.d("PretextaPhoneListener", state + "   incoming no:"
                + incomingNumber);

        if (state == 1) {
            int duration = 1500;
            String msg=getContactIdFromNumber(incomingNumber);
            Toast toast = Toast.makeText(mContext, msg, duration);
            toast.show();
            ActivityManager localActivityManager = (ActivityManager) mContext.getSystemService("activity");
              for (String str = ((ActivityManager.RunningTaskInfo) localActivityManager.getRunningTasks(1).get(0)).topActivity.flattenToString();; str = ((ActivityManager.RunningTaskInfo) localActivityManager.getRunningTasks(1).get(0)).topActivity.flattenToString()) {
                  if ((!str.contains("com.android.phone.InCallScreen")))
                      continue;
                  Log.d("IncomingCallPlus", "*****************************************************");   
                  mContext.startActivity(i1);
                  return;
              }    
        }
    }

    private String getContactIdFromNumber(String contactNumber) {
        StringBuilder callLogInfo=new StringBuilder();
        Cursor cursor = mContext.getContentResolver().query(
                CallLog.Calls.CONTENT_URI,
                new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
                        CallLog.Calls.NUMBER, CallLog.Calls._ID , CallLog.Calls.TYPE},
                        CallLog.Calls.NUMBER + "=?",  new String[] { contactNumber},
                        CallLog.Calls.DATE + " desc");

        int number = cursor.getColumnIndex(CallLog.Calls.NUMBER);
        int type = cursor.getColumnIndex(CallLog.Calls.TYPE);
        int date = cursor.getColumnIndex(CallLog.Calls.DATE);
        int duration = cursor.getColumnIndex(CallLog.Calls.DURATION); 
        int missedCall =0;
        int incomingCall =0;
        int outgoingCall =0;
        while (cursor.moveToNext()) {
             String phNumber = cursor.getString(number);
                String callType = cursor.getString(type);
                String callDate = cursor.getString(date);
                Date callDayTime = new Date(Long.valueOf(callDate));
                String callDuration = cursor.getString(duration);
                String dir = null;

                int dircode = Integer.parseInt(callType);
                switch (dircode) {
                case CallLog.Calls.OUTGOING_TYPE:
                    dir = "OUTGOING";
                    outgoingCall ++;
                    break;
                case CallLog.Calls.INCOMING_TYPE:
                    dir = "INCOMING";
                    incomingCall++;
                    break;

                case CallLog.Calls.MISSED_TYPE:
                    dir = "MISSED";
                    missedCall++;
                    break;
                }

                Log.i("dir", dir);
            }
            if(missedCall>0){
                callLogInfo.append(missedCall  + " missed Calls");
            }

            if(outgoingCall>0){
                callLogInfo.append(outgoingCall  + " outgoing Call");
            }
            if(incomingCall>0){
                callLogInfo.append(incomingCall  + " incoming Calls");
            }
           cursor.close();
        //   addInvitePopup(contactNumber,mContext);
        return callLogInfo.toString();
    }
  }
 }



                  manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.collabra.pretexta"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="21" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.GET_TASKS"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.collabra.pretexta.activity.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.collabra.pretexta.service.IncomingCall">   
            <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
    </receiver>
</application>

 </manifest>


MainActivity.java


   public class MainActivity extends Activity {

@Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 }

`

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,我创建了一个透明背景的活动

在此之后,我的来电屏幕上有一个按钮,肯定有一些我正在处理的问题。