特定朋友的铃声!电话重新启动,错误:无法从Display Manager; Android.os.deadobjectE



嗨,我想制作铃声应用程序,并在几天前问了一个考虑权限的问题,您的答案对我有很大帮助。原始问题:应用程序试图将歌曲设置为Android Studio中的特定朋友时崩溃,应用在GetContentResolver崩溃 我通过使用此功能设法为特定朋友设置了铃声:

public void setFriend(Intent data)
    {
        if(data != null) {
            Uri contactData = data.getData();
            String contactId = contactData.getLastPathSegment();
            String[] PROJECTION = new String[] {
                    ContactsContract.Contacts._ID,
                    ContactsContract.Contacts.DISPLAY_NAME,
                    ContactsContract.Contacts.HAS_PHONE_NUMBER,
            };
            Cursor localCursor =  getContentResolver().query(contactData, PROJECTION, null, null, null);
            localCursor.moveToFirst();
            //--> use moveToFirst instead of this:  localCursor.move(Integer.valueOf(contactId)); /*CONTACT ID NUMBER*/
            String contactID = localCursor.getString(localCursor.getColumnIndexOrThrow("_id"));
            String contactDisplayName = localCursor.getString(localCursor.getColumnIndexOrThrow("display_name"));
            Uri localUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactID);
            localCursor.close();
            ContentValues localContentValues = new ContentValues();
            Uri uri = Uri.parse("android.resource://" + getBaseContext().getPackageName() + "/raw/" + nizModela.get(customAdapter.lastSetAsPosition).getNaziv());
            File f = customAdapter.SaveFileOnInternalMemory(uri, customAdapter.lastSetAsPosition, getContentResolver());
            localContentValues.put(ContactsContract.Data.RAW_CONTACT_ID, contactId);
            localContentValues.put(ContactsContract.Data.CUSTOM_RINGTONE, f.getAbsolutePath());
            getContentResolver().update(localUri, localContentValues, null, null);
            Toast.makeText(this, "Ringtone assigned to: " + contactDisplayName, Toast.LENGTH_LONG).show();

        }
    }

活动结果:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == PICK_CONTACT)
        {
            //ako je api nizi od 23 netreba permitioni
            this.data = data;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M )
            {
                int PERMISSION_ALL = 1;
                String[] PERMISSIONS = {
                        //Manifest.permission.READ_CONTACTS,
                        Manifest.permission.WRITE_CONTACTS,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,
                };
                       // Manifest.permission.READ_SMS, Manifest.permission.CAMERA
                if(!hasPermissions(this, PERMISSIONS)){
                    ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
                }
                else{
                    setFriend(data);
                }
            }
            else
                setFriend(data);
        }
        if(callbackManager.onActivityResult(requestCode, resultCode, data)) {
            return;
        }
    }

并应要求许可结果:

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
        switch (requestCode) {
            case REQUEST_ID_MULTIPLE_PERMISSIONS: {
                Map<String, Integer> perms = new HashMap<>();
                // Initialize the map with both permissions
                perms.put(Manifest.permission.WRITE_CONTACTS, PackageManager.PERMISSION_GRANTED);
                perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
                // Fill with actual results from user
                if (grantResults.length > 0) {
                    for (int i = 0; i < permissions.length; i++)
                        perms.put(permissions[i], grantResults[i]);
                    // Check for both permissions
                    if (perms.get(Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED
                            && perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(this,"Permisije dozvoljene ",Toast.LENGTH_SHORT).show();
                       setFriend(data);
                       // Log.d(TAG, "sms & location services permission granted");
                        // process the normal flow
                        //else any one or both the permissions are not granted
                    } else {
                        Toast.makeText(this,"Permisije nisu dozvolje",Toast.LENGTH_SHORT).show();
                        //permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission
//                        // shouldShowRequestPermissionRationale will return true
                        //show the dialog or snackbar saying its necessary and try again otherwise proceed with setup.
                    }
                }
                break;
            }
        }

所以,当我通过调试器运行它时,一切都顺利运行。但是,当我为特定朋友设置铃声并尝试对其进行测试时,当该特定联系人在手机上打电话给我时,我的手机重新启动,我设法在设备中捕获此 error 监视器,与显示有关。我不知道该怎么办,请帮助!

/DisplayManager: Could not get display information from display manager.
                                                   android.os.DeadObjectException
                                                       at android.os.BinderProxy.transactNative(Native Method)
                                                       at android.os.BinderProxy.transact(Binder.java:503)
                                                       at android.hardware.display.IDisplayManager$Stub$Proxy.getDisplayInfo(IDisplayManager.java:265)
                                                       at android.hardware.display.DisplayManagerGlobal.getDisplayInfo(DisplayManagerGlobal.java:119)
                                                       at android.view.Display.updateDisplayInfoLocked(Display.java:864)
                                                       at android.view.Display.getMetrics(Display.java:779)
                                                       at com.facebook.acra.CrashTimeDataCollector.toString(:21499)
                                                       at com.facebook.acra.CrashTimeDataCollector.getConstantDeviceData(:21230)
                                                       at com.facebook.acra.CrashTimeDataCollector.populateConstantDeviceData(:21314)
                                                       at com.facebook.acra.CrashTimeDataCollector.gatherCrashData(:21179)
                                                       at com.facebook.acra.ErrorReporter.handleExceptionInternal(:4307)
                                                       at com.facebook.acra.ErrorReporter.uncaughtExceptionImpl(:4914)
                                                       at com.facebook.acra.ErrorReporter.uncaughtException(:4878)
                                                       at X.0LG.uncaughtException(:49365)
                                                       at X.04b.uncaughtException(:14078)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
09-09 14:07:29.976 17670-17850/? E/DisplayManager: Could not get display information from display manager.
                                                   android.os.DeadObjectException
                                                       at android.os.BinderProxy.transactNative(Native Method)
                                                       at android.os.BinderProxy.transact(Binder.java:503)
                                                       at android.hardware.display.IDisplayManager$Stub$Proxy.getDisplayInfo(IDisplayManager.java:265)
                                                       at android.hardware.display.DisplayManagerGlobal.getDisplayInfo(DisplayManagerGlobal.java:119)
                                                       at android.view.Display.updateDisplayInfoLocked(Display.java:864)
                                                       at android.view.Display.updateCachedAppSizeIfNeededLocked(Display.java:888)
                                                       at android.view.Display.getWidth(Display.java:562)
                                                       at com.facebook.acra.CrashTimeDataCollector.toString(:21501)
                                                       at com.facebook.acra.CrashTimeDataCollector.getConstantDeviceData(:21230)
                                                       at com.facebook.acra.CrashTimeDataCollector.populateConstantDeviceData(:21314)
                                                       at com.facebook.acra.CrashTimeDataCollector.gatherCrashData(:21179)
                                                       at com.facebook.acra.ErrorReporter.handleExceptionInternal(:4307)
                                                       at com.facebook.acra.ErrorReporter.uncaughtExceptionImpl(:4914)
                                                       at com.facebook.acra.ErrorReporter.uncaughtException(:4878)
                                                       at X.0LG.uncaughtException(:49365)
                                                       at X.04b.uncaughtException(:14078)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
09-09 14:07:29.977 17670-17850/? E/DisplayManager: Could not get display information from display manager.
                                                   android.os.DeadObjectException
                                                       at android.os.BinderProxy.transactNative(Native Method)
                                                       at android.os.BinderProxy.transact(Binder.java:503)
                                                       at android.hardware.display.IDisplayManager$Stub$Proxy.getDisplayInfo(IDisplayManager.java:265)
                                                       at android.hardware.display.DisplayManagerGlobal.getDisplayInfo(DisplayManagerGlobal.java:119)
                                                       at android.view.Display.updateDisplayInfoLocked(Display.java:864)
                                                       at android.view.Display.getRefreshRate(Display.java:644)
                                                       at com.facebook.acra.CrashTimeDataCollector.toString(:21503)
                                                       at com.facebook.acra.CrashTimeDataCollector.getConstantDeviceData(:21230)
                                                       at com.facebook.acra.CrashTimeDataCollector.populateConstantDeviceData(:21314)
                                                       at com.facebook.acra.CrashTimeDataCollector.gatherCrashData(:21179)
                                                       at com.facebook.acra.ErrorReporter.handleExceptionInternal(:4307)
                                                       at com.facebook.acra.ErrorReporter.uncaughtExceptionImpl(:4914)
                                                       at com.facebook.acra.ErrorReporter.uncaughtException(:4878)
                                                       at X.0LG.uncaughtException(:49365)
                                                       at X.04b.uncaughtException(:14078)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
                                                       at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

谢谢,我不知道它可能是哪种服务,应用程序正常,我的手机在特定联系人打电话给我时重新启动(以前已用特定的铃声分配),是否关闭我应用与否。我仅在销毁上释放播放器,然后停下来暂停:

@Override
    protected void onDestroy() {
        super.onDestroy();
        if(customAdapter.plejer() != null && customAdapter.plejer().isPlaying())
        customAdapter.plejer().release();
    }
    @Override
    protected void onPause() {
        super.onPause();
        if(customAdapter.plejer() != null && customAdapter.plejer().isPlaying())
        customAdapter.plejer().pause();
    }
    @Override
    protected void onStop() {
        super.onStop();
        /*if(customAdapter.plejer() != null && customAdapter.plejer().isPlaying())
        customAdapter.plejer().stop();*/
        if(customAdapter.plejer() != null && customAdapter.plejer().isPlaying())
            customAdapter.plejer().pause();
    }

最新更新