• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Incoming call Screen

I am new to android development and trying to create a app where i can show user info from call log on the incoming call screen. I want to display information on the screen i have used toast but that is not clickable. i want something which is clickable like button/image. Please suggest if anybody has any idea.

something similar to http://i.imgur.com/MFhVyqB.jpg

Here is code`

publicclassIncomingCallextendsBroadcastReceiver{

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

privateclassPretextaPhoneListenerextendsPhoneStateListener{Context mContext =null;ActivityManager activityManager;Intent i1;publicPretextaPhoneListener(Context context){super();
mContext = context;
i1 =newIntent(context,TelephoneyWithoutToastActivity.class);
i1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);}

publicvoid onCallStateChanged(int state,String incomingNumber){// default implementation emptyLog.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;}}}

privateString getContactIdFromNumber(String contactNumber){StringBuilder callLogInfo=newStringBuilder();Cursor cursor = mContext.getContentResolver().query(CallLog.Calls.CONTENT_URI,newString[]{CallLog.Calls.DATE,CallLog.Calls.DURATION,CallLog.Calls.NUMBER,CallLog.Calls._ID ,CallLog.Calls.TYPE},CallLog.Calls.NUMBER +"=?",newString[]{ 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 =newDate(Long.valueOf(callDate));String callDuration = cursor.getString(duration);String dir =null;

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

caseCallLog.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


publicclassMainActivityextendsActivity{

@Overrideprotectedvoid onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);}

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

@Overridepublicboolean 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){returntrue;}returnsuper.onOptionsItemSelected(item);}}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones