我在这里遇到了一个小问题,这让我发疯。 我想在 Android 中用 ACTION_CALL Intent 调用一个人,我在一个 fragment 中使用以下代码来完成:
Intent callIntent = new Intent(Intent.ACTION_CALL);
Ansat a = container.adapter.getItem(position);
callIntent.setData(Uri.parse("tel:" + a.mobil.replace(" ", "").trim()));
container.startActivity(callIntent);
容器 是传递给 fragment 的主要 Activity 上下文,因为 fragment 没有自己的 Activity 。
我已经在 Android manifest 中设置了权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<permission
android:name="mithfogvuc.android.svhfvuc.dk.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="mithfogvuc.android.svhfvuc.dk.app.permission.C2D_MESSAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"
tools:replace="android:icon">
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait" />
<activity
android:name=".NewsActivity"
android:screenOrientation="portrait" />
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="mithfogvuc.android.svhfvuc.dk.app" />
</intent-filter>
</receiver>
<service
android:name=".GCMPushReceiverService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name=".GCMRegistrationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.idd.InstanceID" />
</intent-filter>
</service>
<activity
android:name=".FravaersregistreringActivity"
android:screenOrientation="portrait" />
<activity
android:name=".FremmoederegistreringActivity"
android:screenOrientation="portrait"/>
</application>
为什么会出现以下错误:
FATAL EXCEPTION: main
Process: mithfogvuc.android.svhfvuc.dk, PID: 23045
java.lang.SecurityException: Permission Denial: starting Intent {
act=android.intent.action.CALL dat=tel:xxxxxxxx cmp=com.android.server.telecom/.components.UserCallActivity }
from ProcessRecord{6c1ee2e 23045:mithfogvuc.android.svhfvuc.dk/u0a251} (pid=23045, uid=10251) with revoked permission android.permission.CALL_PHONE
最佳答案
从 Android 6.0(Api lvl 23)开始,操作系统允许用户撤销应用程序的权限。你需要调查Runtime Permissions
看来您的应用需要轮询其中一种 requestPermissions()
方法才能获得访问 call_phone
API 的权限!
关于java - 从 Android fragment 调用时权限被拒绝。使用权限已设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37700587/