0

I'm setting up dynamic notification sound and want to set from expansion file in android. so is this possible?, if yes then how can i set or access expansion file(.wav) to code (notification builder), please share some code for the same

My Try :

FCM Code:

 val AUTHORITY = "com.example.provider.SampleZipFileProvider"
        val CONTENT_URI = Uri.parse("content://$AUTHORITY")

     val defaultSoundUri =    Uri.parse("$CONTENT_URI/${appNotification.sound_name}")


        val notificationBuilder = NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(getString(R.string.app_name))
            .setStyle(NotificationCompat.BigTextStyle().bigText(appNotification.message))
            .setWhen(0)
            .setChannelId(Constants.NOTIFICATION_CHNANEL_ID)
            .setContentText(appNotification.message.decodeUnicode())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent)

SampleZipFileProvider.class

public class SampleZipFileProvider extends APEZProvider {
// main content provider URI
private static final String CONTENT_PREFIX = "content://";

// must match what is declared in the Zip content provider in
// the AndroidManifest.xml file
private static final String AUTHORITY = "com.example";

public static final Uri ASSET_URI = Uri.parse(CONTENT_PREFIX + AUTHORITY);

public String getAuthority() {
    return AUTHORITY;
}

}

Manifest :

 <provider android:name=".zipfile.SampleZipFileProvider"
              android:authorities="com.example"
              android:exported="false"
              android:grantUriPermissions="true"
              android:multiprocess="true">
        <meta-data android:name="mainVersion"
                   android:value="1"/>

    </provider>
Pranav
  • 101
  • 5
  • Possible duplicate of [How to play an android notification sound](https://stackoverflow.com/questions/4441334/how-to-play-an-android-notification-sound) – Morteza Jalambadani May 16 '19 at 05:30

1 Answers1

0

Try reading the docs on expansion files, and then ask a more specific question about what you don't understand. The recommendation is to use the Apk Expansion Zip library if you aren't sure.

Nick Fortescue
  • 13,530
  • 1
  • 31
  • 37
  • i already use zip library for playing media in media player and its works,but i do not get any idea to use expansion sound file as notification sound using URI – Pranav May 17 '19 at 09:31
  • That's much more helpful. Now the only thing missing is explaining what doesn't work. Does it fail to build? Does it crash? Does it run, but the nofitication doesn't play? What's in the logs? You might find https://stackoverflow.com/help/how-to-ask helpful – Nick Fortescue May 17 '19 at 09:56
  • yes run successfully without crash but sound doesn't play – Pranav May 17 '19 at 10:06