78634

solve the error:: revoked permission android.permission.CALL_PHONE

Question:

How to solve this error:

<blockquote>

revoked permission android.permission.CALL_PHONE

</blockquote>

This is my Java code:

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(); }

Error:

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)

here is the mainfest file,hope help::

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.phonedb" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="23" /> <uses-permission-sdk-m android:name="android.permission.READ_CONTACTS" /> <uses-permission-sdk-m android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CALL_PHONE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.phonedb.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> <activity android:name=".AddContactActivity" android:label="@string/title_activity_add_contact" > </activity> <activity android:name="com.example.phonedb.DetailContactActivity" android:label="@string/title_activity_detail_contact" > </activity> <activity android:name=".EditActivity" android:label="@string/title_activity_edit" > </activity> </application>

Answer1:

Switch to <strong>DIAL_PHONE</strong>, as that does not need a permission.

<strong>Just replace this line</strong>

Intent callIntent = new Intent(Intent.ACTION_CALL);

<strong>to</strong>

Intent callIntent = new Intent(Intent.ACTION_DIAL);

Answer2:

Android 6 (SDK 23) allows users to revoke permissions from an app. I guess, thats what happened here. Your app must be able to cope with this situation.

Have a look at the <a href="http://developer.android.com/training/permissions/index.html" rel="nofollow">documentation</a> for the details.

In particular:

<blockquote>

If the device is running Android 6.0 or higher, and your app's target SDK is 23 or higher: The app has to list the permissions in the manifest, and it must request each dangerous permission it needs while the app is running. The user can grant or deny each permission, and the app can continue to run with limited capabilities even if the user denies a permission request.

</blockquote>

Requsting permissions at runtime is <a href="http://developer.android.com/training/permissions/requesting.html" rel="nofollow">described in detail here</a>.

Answer3:

Add this permission in the manifest file:

<uses-permission android:name="android.permission.CALL_PHONE"/>

or else try this too.

<uses-permission android:name="android.permission.CALL_PRIVILEGED"/> <blockquote>

CALL_PRIVILEGED Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed. <strong>Not for use by third-party applications.</strong>

</blockquote>

Answer4:

i'm late. You must request permission dynamically.

// Here, thisActivity is the current activity if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity, Manifest.permission.READ_CONTACTS)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(thisActivity, new String[]{Manifest.permission.READ_CONTACTS}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } }

more details at <a href="https://developer.android.com/training/permissions/requesting.html" rel="nofollow">https://developer.android.com/training/permissions/requesting.html</a>

Recommend

  • Access to many-to-many relation in array format, symfony2
  • ACTION_IMAGE_CAPTURE returns imagefile as Extra instead of Data
  • How to startActivity from Options Menu
  • how to get Location object every 10 minutes in android
  • How do i obtain the setMultiChoiceItems items from my AlertDialog?
  • Null Pointer in Dialog Fragment
  • htaccess rewrite to remove query string
  • Deleting a single SQLite row
  • How to extract data between same html tags
  • Alert Dialog was disappearing when user clicks out side
  • Show list in AlertDialog [duplicate]
  • How to get respective text and image from the respective recyclerview item in floaty upon clicking a
  • show a license agreement in android application
  • ProgressDialog setProgress and setMessage inside asyncTask don't work
  • Eclipse e4 tool Control in trimbars
  • TimePickerDialog widget in landscape mode (PreferenceScreen)
  • Android Alertbox How to dismiss all open Alertbox without any references
  • Could not install package 'Microsoft.Owin.Security 2.0.1'
  • How to force refresh on CallLog.Calls.CACHED_NAME column?
  • Submission of new app with iAds
  • How to set the navigation bar to the top in Table View?
  • UIPickerView without IB?
  • Cassandra NoClassDefFoundError: com/google/common/util/concurrent/AsyncFunction
  • how to set to NULL all the filestream varbinary(max) fields?
  • What is this strange character in chrome's resource css viewer?
  • testing a POST using phpunit in laravel 4
  • Deleting empty Series out of Graph (with VBA)
  • SqlCommand back up Database
  • How do I Dispose a HttpResponseMessage in my Web Api Method?
  • Failed to find version-tag string. File must be updated
  • User messaging system
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • Button click event not firing in jQuery
  • Webgrid not refreshing after delete MVC
  • why overloaded new operator is calling constructor even I am using malloc inside overloading functio
  • Adding a button at the bottom of a table view
  • Getting last autonumber in access
  • what is the difference between the asp.net mvc application and asp.net web application
  • Delete MySQLi record without showing the id in the URL
  • GridView Sorting works once only