我想注册我的应用程序以调用选项,以便每当用户从通话记录或联系人列表中调用时,它都会在选项列表中显示我的应用。它是这样的
我已经搜索了这个,发现我必须注册app以获得新的呼出意图和进程呼出权限。同时我必须生成视图以显示选项和点击事件我必须根据项目执行操作但是我没有得到适当的教程或代码,我可以参考这个来实现这个目标。如果有人知道这个帮助我,那就请。
答案 0 :(得分:4)
这是一个简单的代码,你可以查看这个....
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.WRITE_CALL_LOG" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.test.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
</application>
和java代码:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String tel = outgoingRecord();
Toast.makeText(this, tel, Toast.LENGTH_LONG).show();
TextView textView=(TextView)findViewById(R.id.tv);
textView.setText(tel);
}
public String outgoingRecord() {
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI, null, null, null,
android.provider.CallLog.Calls.DATE + " DESC");
startManagingCursor(c);
int numberColumn = c
.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
int dateColumn = c.getColumnIndex(android.provider.CallLog.Calls.DATE);
// type can be: Incoming, Outgoing or Missed
int typeColumn = c.getColumnIndex(android.provider.CallLog.Calls.TYPE);
int durationColumn = c
.getColumnIndex(android.provider.CallLog.Calls.DURATION);
// Will hold the calls, available to the cursor
ArrayList<String> callList = new ArrayList<String>();
try {
boolean moveToFirst = c.moveToFirst();
Log.e("MOVETOFIRST", "moveToFirst=" + moveToFirst);
}
catch (Exception e) {
Log.e("MOVETOFIRSTERROR", "MOVETOFIRST Error=" + e.toString());
}
String callerPhoneNumber = c.getString(numberColumn);
int callDate = c.getInt(dateColumn);
int callType = c.getInt(typeColumn);
int duration = c.getInt(durationColumn);
Log.d("CALLS", "callDate=" + callDate);
switch (callType) {
case android.provider.CallLog.Calls.INCOMING_TYPE:
Log.d("INCOMINGCALLLOG", "CallerPhoneNum=" + callerPhoneNumber
+ " " + "Duration=" + duration);
break;
case android.provider.CallLog.Calls.MISSED_TYPE:
break;
case android.provider.CallLog.Calls.OUTGOING_TYPE:
Log.d("OUTGOINGCALLLOG", "CallerPhoneNum=" + callerPhoneNumber
+ " " + "Duration=" + duration);
break;
}
return callerPhoneNumber;
}
}
输出是....