
看起来我没有权限问题,但系统不会让创建记录:
07-28 18:11:44.799 2304 10616 I UpdateIcingCorporaServi: Updating corpora: APPS=com.example.aero.myapplication,CONTACTS=MAYBE07-28 18:11:45.362 2304 10648 I UpdateIcingCorporaServi: Updating corpora: APPS=com.example.aero.myapplication.test,CONTACTS=MAYBE07-28 18:11:45.651 10663 10678 I GrantPermissionCallable: Permission: androID.permission.WRITE_CONTACTS is already granted!07-28 18:11:46.255 10663 10678 I OK : contact Permission to record allowed07-28 18:11:46.255 10663 10678 D Info : Creating contact: 12345678907-28 18:11:46.259 2097 2114 E DatabaseUtils: java.lang.SecurityException: Proxy package com.androID.provIDers.contacts from uID 10001 or calling package com.example.aero.myapplication.test from uID 10097 not allowed to perform WRITE_CONTACTS07-28 18:11:46.260 10663 10678 E Error : Exception encountered while inserting contact: java.lang.SecurityException: Proxy package com.androID.provIDers.contacts from uID 10001 or calling package com.example.aero.myapplication.test from uID 10097 not allowed to perform WRITE_CONTACTS
有任何想法吗?为什么那神秘?
一旦我运行app它安装2 apk:
$adb push /Users/aero/AndroIDStudioProjects/MyApplication/app/build/outputs/apk/app-deBUG.apk /data/local/tmp/com.example.aero.myapplication$adb shell pm install -r "/data/local/tmp/com.example.aero.myapplication"
和
$adb push /Users/aero/AndroIDStudioProjects/MyApplication/app/build/outputs/apk/app-deBUG-androIDTest.apk /data/local/tmp/com.example.aero.myapplication.test$adb shell pm install -r "/data/local/tmp/com.example.aero.myapplication.test"
并且只有com.example.aero.myapplication在系统中具有权限,com.example.aero.myapplication.test没有任何权限.我失去了一点点.
package com.example.aero.myapplication;import androID.Manifest;import androID.app.Instrumentation;import androID.content.ContentProvIDerOperation;import androID.content.Context;import androID.content.Intent;import androID.content.pm.PackageManager;import androID.os.Bundle;import androID.os.Environment;import androID.provIDer.ContactsContract;import androID.support.test.InstrumentationRegistry;import androID.support.test.filters.SdkSuppress;import androID.support.test.rule.GrantPermissionRule;import androID.support.test.runner.AndroIDJUnit4;import androID.support.test.uiautomator.By;import androID.support.test.uiautomator.UIDevice;import androID.support.v4.app.ActivityCompat;import androID.support.v7.app.AppCompatActivity;import androID.util.Log;import org.junit.Before;import org.junit.Rule;import org.junit.runner.RunWith;import java.util.ArrayList;import static org.hamcrest.CoreMatchers.notNullValue;import static org.junit.Assert.assertthat;@RunWith(AndroIDJUnit4.class)public class MainActivity{ @Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_CONTACTS); public Instrumentation instrumentation; private UIDevice mDevice; private static final int RECORD_REQUEST_CODE = 101; @Before public voID before() { // Initialize UIDevice instance mDevice = UIDevice.getInstance(InstrumentationRegistry.getInstrumentation()); //instrumentation = InstrumentationRegistry.getInstrumentation(); assertthat(mDevice,notNullValue()); // Start from the home screen mDevice.pressHome(); } @org.junit.Test public voID test() throws InterruptedException { Context context = InstrumentationRegistry.getInstrumentation().getContext(); String name = "TEST RECORD"; String NMBR = "123456789"; CreatePhoneBookEntry(context,name,NMBR); } public voID CreatePhoneBookEntry(Context context,String name,String NMBR) { //ActivityCompat.requestPermissions(context,// new String[]{Manifest.permission.WRITE_CONTACTS},// RECORD_REQUEST_CODE) int permission = ActivityCompat.checkSelfPermission(context,Manifest.permission.WRITE_CONTACTS); if (permission != PackageManager.PERMISSION_GRANTED) { Log.i("Error","contact Permission to record denIEd"); } else { Log.i("OK","contact Permission to record allowed"); }; /* * Gets values from the UI */ // Creates a new array of ContentProvIDerOperation objects. ArrayList<ContentProvIDerOperation> ops = new ArrayList<ContentProvIDerOperation>(); /* * Creates a new raw contact with its account type (server type) and account name * (user's account). Remember that the display name is not stored in this row,but in a * Structuredname data row. No other data is required. */ ContentProvIDerOperation.Builder op = ContentProvIDerOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE,null) .withValue(ContactsContract.RawContacts.ACCOUNT_name,null); // Builds the operation and adds it to the array of operations ops.add(op.build()); // Creates the display name for the new raw contact,as a Structuredname data row. op = ContentProvIDerOperation.newInsert(ContactsContract.Data.CONTENT_URI) /* * withValueBackReference sets the value of the first argument to the value of * the ContentProvIDerResult indexed by the second argument. In this particular * call,the raw contact ID column of the Structuredname data row is set to the * value of the result returned by the first operation,which is the one that * actually adds the raw contact row. */ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0) // Sets the data row's MIME type to Structuredname .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Structuredname.CONTENT_ITEM_TYPE) // Sets the data row's display name to the name in the UI. .withValue(ContactsContract.CommonDataKinds.Structuredname.disPLAY_name,name); // Builds the operation and adds it to the array of operations ops.add(op.build()); // Inserts the specifIEd phone number and type as a Phone data row op = ContentProvIDerOperation.newInsert(ContactsContract.Data.CONTENT_URI) /* * Sets the value of the raw contact ID column to the new raw contact ID returned * by the first operation in the batch. */ .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0) // Sets the data row's MIME type to Phone .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) // Sets the phone number and type .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER,NMBR) .withValue(ContactsContract.CommonDataKinds.Phone.TYPE,"MOBILE"); // Builds the operation and adds it to the array of operations ops.add(op.build()); // Ask the Contacts ProvIDer to create a new contact Log.d("Info","Creating contact: " + NMBR); /* * ApplIEs the array of ContentProvIDerOperation objects in batch. The results are * discarded. */ try { context.getContentResolver().applyBatch(ContactsContract.AUTHORITY,ops); } catch (Exception e) { // Log exception Log.e("Error","Exception encountered while inserting contact: " + e); } }}解决方法 陷入同样的问题,但获得了不同的许可. 对我的修复很简单,我忘了添加< uses-permission androID:name =“androID.permission.THE_PERMISSION”/>到AndroIDManifest.xml
所以也许你应该确保你有所需的< uses-permission ... />和< uses-feature ... />在那里.
希望能帮助到你..
总结以上是内存溢出为你收集整理的android sdk 23检测权限问题(java.lang.SecurityException)全部内容,希望文章能够帮你解决android sdk 23检测权限问题(java.lang.SecurityException)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)