当前位置:操作系统 > 安卓/Android >>

Android第二个小练习:拨号提醒

使用触屏手机的人都有过这样的一种错误:在拨号的时候触错了人,一步小心就呼叫出去了,这个时候手忙脚乱的去挂断。那么针对上面的情景设计,我做了这么一个小的练习,就是说当要拨打电话的时候,首先弹出一个对话框,确认要拨打给电话XXX,点确认以后呼叫,点取消以后取消呼叫。
先上图:
\

\


因为是一次自易做图系,所以功能上并不复杂,但是个人有发现有这样的app在市面上流通,所以做一个对别人有用的练习,还是很有成就感的。下面提出主要的代码

[java]
package abortCall.test; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInte易做图ce; 
import android.content.SharedPreferences; 
import android.content.DialogInte易做图ce.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("您确定要拨号给"+nums+"吗?"); 
        builder.setTitle("提醒"); 
        builder.setPositiveButton("确定", new OnClickListener(){ 
            public void onClick(DialogInte易做图ce 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("取消", new OnClickListener(){ 
            public void onClick(DialogInte易做图ce dialog,int which){ 
                Finish(); 
            } 
        }); 
        builder.create().show(); 
    } 
    private void Finish(){ 
        this.finish(); 
        System.exit(0); 
    } 

package abortCall.test;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInte易做图ce;
import android.content.SharedPreferences;
import android.content.DialogInte易做图ce.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("您确定要拨号给"+nums+"吗?");
  builder.setTitle("提醒");
  builder.setPositiveButton("确定", new OnClickListener(){
   public void onClick(DialogInte易做图ce 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("取消", new OnClickListener(){
   public void onClick(DialogInte易做图ce dialog,int which){
    Finish();
   }
  });
  builder.create().show();
 }
    private void Finish(){
     this.finish();
     System.exit(0);
    }
}

 

[html]
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; 
    @Override 
    public void onReceive(Context context, Intent intent){ 
        String action = intent.getAction(); 
        String PhoneNum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
        this.context = context; 
        SharedPreferences s

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,