Hi guys I am trying to make ringtone app, and had asked couple of days ago a question considering permissions, and your answers helped me a lot. Original question : App crashes when trying to set song as specific friend in android studio, app crashes at getContentresolver I managed to set ringtone for specific friend, by using this function:

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


        }
    }

On activity result :

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

    }

And on request permission result:

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

So the thing is when I run this through debugger everything runs smoothly. However when I set ringtone for specific friend and try and test it, when that specific contact calls me on my phone, my phone restarts and I managed to catch this error in device monitor, has something to do with DISPLAY.I honestly have no idea what to do, please help!!:

/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)
1

There are 1 answers

1
Petar On

Thanks, I do not know which service it might be, app works fine, my phone restarts when specific contact call me (which has previously been assigned with specific ringtone ), whether I close my app or not. I only release player on destroy, and pause it on pause :

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

    }