当前位置:  开发笔记 > 编程语言 > 正文

解决错误:: revoked permission android.permission.CALL_PHONE

如何解决《解决错误::revokedpermissionandroid.permission.CALL_PHONE》经验,为你挑选了1个好方法。

如何解决这个错误:

撤销权限android.permission.CALL_PHONE

这是我的Java代码:

public class DetailContactActivity extends AppCompatActivity implements
OnClickListener {

    private TextView    phone, email;
    private int         id;
    private ImageView   call, btnEmail;
    private ContactDB   db;

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

        db = ContactDB.getInstance(this);

        phone = (TextView) findViewById(R.id.txt_phone_number);
        email = (TextView) findViewById(R.id.txt_email);
        call = (ImageView) findViewById(R.id.btn_call);
        btnEmail = (ImageView) findViewById(R.id.btn_email);

        Bundle b = getIntent().getExtras();
        if (b != null)
        {
            id = b.getInt("id");
            phone.setText(b.getString("phone"));
            getSupportActionBar().setTitle(b.getString("nama"));
            if (!b.getString("email").equals("null"))
            {
                email.setText(b.getString("email"));
            } else
            {
                email.setText("");
            }

        }

        call.setOnClickListener(this);
        btnEmail.setOnClickListener(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.detail_contact, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
            case R.id.action_edit:
                Bundle b = new Bundle();
                b.putInt("id", id);
                b.putString("name", getSupportActionBar().getTitle().toString());
                b.putString("email", email.getText().toString());
                b.putString("phone", phone.getText().toString());

                Intent i = new Intent(this, EditActivity.class);
                i.putExtras(b);
                startActivity(i);
                finish();
                return true;
            case R.id.action_delete:
                showSettingsAlert();
                return true;
            default:
                return super.onOptionsItemSelected(item);

        }

    }

    @Override
    public void onClick(View v)
    {
        if (v == btnEmail)
        {
            if (!email.getText().toString().equals(""))
            {
                Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
                        Uri.fromParts("mailto", email.getText().toString(),
                                null));

                startActivity(Intent
                        .createChooser(emailIntent, "Send email..."));

            }

        } else if (v == call)
        {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + phone.getText().toString()));
            startActivity(callIntent);

            //Uri call = Uri.parse("tel:" + phone.getText().toString());             
            //Intent surf = new Intent(Intent.ACTION_CALL, call); 
            //startActivity(surf);
        }

    }

    private void showSettingsAlert()
    {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle("Delete");
        alert.setMessage("Contact akan dihapus");

        alert.setPositiveButton("Ya", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                db.deleteContact(id);
                startActivity(new Intent(DetailContactActivity.this,
                        MainActivity.class));
                finish();
            }
        });
        alert.setNegativeButton("Tidak", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                dialog.cancel();
            }
        });

        alert.show();

    }

    @Override
    public void onBackPressed()
    {
        super.onBackPressed();
        startActivity(new Intent(DetailContactActivity.this, MainActivity.class));
        finish();
    }

错误:

01-02 02:05:41.493: D/AndroidRuntime(2927): Shutting down VM
01-02 02:05:41.493: D/AndroidRuntime(2927): --------- beginning of crash
01-02 02:05:41.616: E/AndroidRuntime(2927): FATAL EXCEPTION: main
01-02 02:05:41.616: E/AndroidRuntime(2927): Process: com.example.phonedb, PID: 2927
01-02 02:05:41.616: E/AndroidRuntime(2927): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity } from ProcessRecord{f5320c4 2927:com.example.phonedb/u0a69} (pid=2927, uid=10069) with revoked permission android.permission.CALL_PHONE
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.os.Parcel.readException(Parcel.java:1599)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.os.Parcel.readException(Parcel.java:1552)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2658)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1507)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.Activity.startActivityForResult(Activity.java:3917)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.Activity.startActivityForResult(Activity.java:3877)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:748)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.Activity.startActivity(Activity.java:4200)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.Activity.startActivity(Activity.java:4168)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at com.example.phonedb.DetailContactActivity.onClick(DetailContactActivity.java:127)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.view.View.performClick(View.java:5198)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.view.View$PerformClick.run(View.java:21147)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.os.Handler.handleCallback(Handler.java:739)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.os.Handler.dispatchMessage(Handler.java:95)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.os.Looper.loop(Looper.java:148)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at android.app.ActivityThread.main(ActivityThread.java:5417)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at java.lang.reflect.Method.invoke(Native Method)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-02 02:05:41.616: E/AndroidRuntime(2927):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

这里是mainfest文件,希望帮助::







 



    
        
            

            
        
    
    
    
    
    
    
    



1> chakri Reddy..:

切换到DIAL_PHONE,因为它不需要许可.

只需更换此行即可

Intent callIntent = new Intent(Intent.ACTION_CALL);

Intent callIntent = new Intent(Intent.ACTION_DIAL);

推荐阅读
mobiledu2402851323
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有