Second exercise for Android: dial-up reminder

Source: Internet
Author: User

People who use touch-screen mobile phones all have this kind of mistake: When the dial is wrong, the wrong person is called out step by step. At this time, they are busy hanging up. So for the above scenario design, I made such a small exercise, that is to say, when you want to call, first pop up a dialog box, confirm to call XXX, click confirm to cancel the call.

First:

 

Because it is a self-taught contact, it is not complicated in terms of functions, but I have found such an app circulating on the market. Therefore, it is a great sense of accomplishment to do a useful exercise for others. The main code is as follows:

Package abortCall. test; import android. app. activity; import android. app. alertDialog; import android. content. dialogInterface; import android. content. sharedPreferences; import android. content. dialogInterface. onClickListener; import android. content. intent; import android.net. uri; import android. OS. bundle; public class AbortCallActivity extends Activity {/** Called when the activity is first created. */String Nums = ""; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); try {Bundle bundle = this. getIntent (). getExtras (); nums = bundle. getString ("num"); ShowDialog ();} catch (Exception ex) {}} private void ShowDialog () {AlertDialog. builder builder = new AlertDialog. builder (this); builder. setMessage ("are you sure you want to dial" + nums +? "); Builder. setTitle ("Reminder"); builder. setPositiveButton ("OK", new OnClickListener () {public void onClick (DialogInterface dialog, int which) {SharedPreferences settings = getSharedPreferences ("SETTING_INFO", 0); settings. edit (). putBoolean ("IsAllowed", true ). commit (); Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel:" + nums); startActivity (intent); Finish () ;}}); builder. setNegativeButton ("cancel", new OnClickListener () {public void onClick (DialogInterface dialog, int which) {Finish () ;}}); builder. create (). show ();} private void Finish () {this. finish (); System. exit (0 );}}

 

package abortCall.test;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;public class callReceiver extends BroadcastReceiver {private Context context;@Overridepublic void onReceive(Context context, Intent intent){String action = intent.getAction();String PhoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);this.context = context;SharedPreferences settings = context.getSharedPreferences("SETTING_INFO",0);boolean IsAllowed = settings.getBoolean("IsAllowed",false);if(!IsAllowed){setResultData(null);intent.setClass(context, AbortCallActivity.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("num", PhoneNum);context.startActivity(intent);}settings.edit().putBoolean("IsAllowed", false).commit();this.clearAbortBroadcast();}public void Allowed(){}}
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="abortCall.test"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk android:minSdkVersion="8" />    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>    <uses-permission android:name="android.permission.CALL_PHONE"/><application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name" >        <activity            android:name=".AbortCallActivity"            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="callReceiver">            <intent-filter android:priority="-1" >                <action android:name="android.intent.action.NEW_OUTGOING_CALL"/>            </intent-filter>        </receiver>    </application></manifest>

The main idea is to obtain the Broadcast event of android. permission. process_outgoing_cils when dialing on the mobile phone, block the dialing, and jump to the Activity. The pop-up dialog box is displayed for the Activity. After confirmation in the dialog box, dial again. Because the next dialing attempt will still be blocked, you can pass a parameter to the caller to tell him that the dialing attempt is permitted. It will not be blocked, because the parameter cannot be passed directly, so a SharedPreferences is used to save the passed value. This prevents further blocking.

Main knowledge points through this contact:

1. How to register and use a BroadCastReceiver.

2. How to enable BroadCastReceiver for an Activity: intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK );

3. BroadcastReceiver cannot directly start a Dialog

4. How to use a Dialog

5. How to pass a parameter when the system does not support explicit parameter transfer and use SharedPreferres to pass the parameter, so as to flexibly apply and adapt it.

6. How to block dialing and broadcasting a number.

7. The system jumps from a simple page to some comparison system interfaces, and the system can be controlled.

Attaches source code http://download.csdn.net/detail/aofengdaxia/4058274

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.