como desde qt establecer un tono de llamada en android



  • esto me funciona para llamar al tono en cuestion en el dispositivo pero como lo cambio.

    void otro(){
    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
    if ( activity.isValid() )
    {
    jint notifcationType = QAndroidJniObject::getStaticField<jint>("android/media/RingtoneManager", "TYPE_RINGTONE");
    QAndroidJniObject notification = QAndroidJniObject::callStaticObjectMethod("android/media/RingtoneManager", "getDefaultUri", "(I)Landroid/net/Uri;", notifcationType);
    if ( notification.isValid() )
    {
    // Note that package and class names needs to be separated with '/' and not '.'
    QAndroidJniObject ring = QAndroidJniObject::callStaticObjectMethod("android/media/RingtoneManager",
    "getRingtone",
    "(Landroid/content/Context;Landroid/net/Uri;)Landroid/media/Ringtone;",
    activity.object<jobject>(),
    notification.object<jobject>());
    if ( ring.isValid() )
    {
    ring.callMethod<void>("play", "()V");
    }
    else
    qDebug()<<"ring is faild";
    }
    }
    }



  • @jchaviano estaría bueno si pudieses marcar el código con los tags apropiados (ícono </>) para que quede más claro y se pueda entender un poco más... Gracias



  • @jchaviano
    hasta ahora llegue un poco mas lejos.
    miren:::

    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.app.Activity;
    import java.io.File;
    import android.provider.MediaStore;
    import android.content.ContentValues;
    import android.media.RingtoneManager;
    import android.util.Log;
    import android.os.Environment;
    import org.qtproject.qt5.android.bindings.QtActivity;

    public class Tonos {
    public static void init_tones(QtActivity activity)
    {
    Uri path = null;
    String fileName = "/media/audio/ringtones/eltono.mp3";
    // no logro hacer este metodo
    //sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
    //Uri.parse("file://" + Environment.getExternalStorageDirectory() + filename)));

            File file = new File(Environment.getExternalStorageDirectory(), fileName);
            if (file.exists()) {
                Log.i("Ringtone", "File already exists");
                path = getMediaUri(file, activity);
                if (path != null) {
                    path = Uri.fromFile(file);
                    RingtoneManager.setActualDefaultRingtoneUri(activity,
                          RingtoneManager.TYPE_NOTIFICATION, path);
                }
            }
        }
    public static Uri getMediaUri(File outFile, QtActivity activity) {
                // To set any tone as ringtone on sd-card, it should have appropriate content values.
                ContentValues values = new ContentValues();
                values.put(MediaStore.MediaColumns.DATA, outFile.getAbsolutePath());
                values.put(MediaStore.MediaColumns.TITLE,getNameMusic(outFile.getName()));
                values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg");
                //if(type == TYPE_NOTIFICATION_CHOICE) {
                //  values.put(MediaStore.Audio.Media.IS_RINGTONE, false);
                //values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
                //}
              //  if(type == TYPE_RINGTONE_CHOICE) {
                    values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
                    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
                //}
                values.put(MediaStore.Audio.Media.IS_ALARM, false);
                values.put(MediaStore.Audio.Media.IS_MUSIC, false);
    
                //Delete if present and insert it into the media database
                Uri uri = MediaStore.Audio.Media.getContentUriForPath(outFile.getAbsolutePath());
                activity.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + outFile.getAbsolutePath() + "\"", null);
                Uri newUri = activity.getContentResolver().insert(uri, values);
                return newUri;
            }
        public static String getNameMusic(String name){
            return name.substring(0,name.length()-4);
            }
        }

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.