2016-09-10 9 views
3

I follow this video tutorial以前は問題ありません。StartActivityコールにアクセス許可の問題が必要です

今日私はもう一度やり直しますが、それにはいくつか問題があります。 This picture

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.fooddeliverycaller"> 


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

<uses-sdk 
    android:minSdkVersion="15" 
    android:targetSdkVersion="24" /> 


<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version"/> 

    <activity android:name="com.google.android.gms.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 
</application> 
+3

https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it法の下

private void callNumber() { if (ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CALL_PHONE)) { // 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(this, new String[]{Manifest.permission.CALL_PHONE}, MY_PERMISSIONS_REQUEST_READ_CONTACTS); } } else { //This is for lower version <23 Intent callIntent = new Intent(Intent.ACTION_DIAL); callIntent.setData(Uri.parse("tel:" + MyCellNumber); startActivity(callIntent); } } 

そして上書き – CommonsWare

答えて

0

API 23の後、ユーザーは、ユーザーの機密データにアクセスする可能性のあるアクセス許可を明示的に許可する必要があります。このようなアクセス許可には、Calendar, Camera, Contact, Location, Microphone, Phone, Sensor, SMS, Storage.

が含まれています。以下は、変更したDocumentationから取得したコードです。

@Override 
public void onRequestPermissionsResult(int requestCode, 
             String permissions[], int[] grantResults) { 
    switch (requestCode) { 
     case MY_PERMISSIONS_REQUEST_READ_CONTACTS: { 
      // If request is cancelled, the result arrays are empty. 
      if (grantResults.length > 0 
        && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 

       Intent callIntent = new Intent(Intent.ACTION_DIAL); 
       callIntent.setData(Uri.parse("tel:" + MyCellNumber)); 
       startActivity(callIntent); 
       // permission was granted, yay! Do the 
       // contacts-related task you need to do. 
      } else { 
       // permission denied, boo! Disable the 
       // functionality that depends on this permission. 
      } 
      return; 
     } 

     // other 'case' lines to check for other 
     // permissions this app might request 
    } 
} 
1

(実行時)権限チェックを追加する必要があります。 Android API 23以降では、実行時に特定のタスク(例:呼び出し、位置情報など)を実行する権限を求める必要があります。これを行うには、次のコードをクリックしてください:

startActivity(callIntent); 

コードに残っている赤い警告の三角形/記号に移動してください。それをクリックし、権限チェックを追加するをクリックします。今あなたがあなたのアプリを実行すると、 "ダイアログ"がポップアップし、アプリケーションに電話をかけるようにユーザーに依頼します。

これが役に立ちます。

Android permission checks

か、これは以前に質問(@CommonsWareにより示唆されるように)答えをチェックアウト:あなたは

Intent.ACTION_DIAL 

を使用する必要があります

Android permission doesn't work even if I have declared it

0

の詳細情報については、このリンクを参照してください。 Intent.ACTION_CALLの代わりに。 Intent.ACTION_DIALこれは、ダイヤラーに渡した番号で事前入力します。許可は必要ありません。

問題を解決することを願っています!

関連する問題