I cannot set the audio file as ringtone for older version devices. The section I wrote for new android versions works fine - set

Code:
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.TITLE, k.getName());
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
if (RingtoneManager.TYPE_RINGTONE == type) {
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
} else if (RingtoneManager.TYPE_NOTIFICATION == type) {
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
}
values.put(MediaStore.MediaColumns.SIZE,k.length());
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "😕"" + k.getAbsolutePath() + "\"", null);
System.out.println("Uri string: "+uri.toString()); //Do you think the output I got here is normal? Output = content: // media / internal / audio / media
Uri newUri = setandsharejava.this.getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(setandsharejava.this,type,newUri);
k=File
The ringtone is set with the name I want but when playing it uses the default sound for android.
There is no error message.
Thank you for your interest.
Do titles I reviewed:
How to set ringtone in Android from my activity?
Set a selected audio file as ringtone
How to set a file as a ringtone for Android 10?
Set a sound file as ringtone and notification programmatically in Android
How can I change the ringtone in android programmatically?
Set ringtone from res/raw folder
How can I set a ringtone for an individual contact on Android?
and more...

I solved the problem after trying hard.
The problem was that I was trying to get the audio file from the application's cache.
After burning the audio file to the sdcard partition it worked fine.

Related

Save file with custom extension using CreateChooser on Xamarin Android

I have to ask the user to choose a location and save the file with a custom extension (.tdr). I have set intent.SetType to */* and currently I have to save file without any extension. Can anyone please help me to resolve my issue?
Here is my code sample
Intent intent = new Intent();
intent.SetType("*/*");
intent.PutExtra(Intent.ExtraAllowMultiple, false);
intent.SetAction(Intent.ActionCreateDocument);
MainActivity.Instance.persistentStorageService.Write("DataToWrite", projectJson);
MainActivity.Instance.StartActivityForResult(Intent.CreateChooser(intent, "Save TRW Project File"), RequestCodeConstants.FilePickerSaveRequestCode);
In MainActivity.cs
System.IO.Stream output = ContentResolver.OpenOutputStream(data.Data);
var dataToWrite = persistentStorageService.Read("DataToWrite", typeof(string));
var buffer = Encoding.ASCII.GetBytes((string)dataToWrite);
output.Write(buffer, 0, buffer.Length);
output.Close();
result = buffer;
I want to save file in custom extension.
The issue is your MimeType, it needs to be set to octet for custom file types:
intent.SetType("application/octet");
Once you do that all you need to do is StartActivityForResult and you are done.
Activity.StartActivityForResult(intent, resultCode);
Make sure your extension type is a part of the file name itself, you can assign that through intent as well
intent.PutExtra(Intent.ExtraTitle, fileName);

Why is UIDocumentPickerViewController working on iOS, but showing the wrong folder on Mac Catalyst?

The code below works fine on an iPad or iPhone -- saveDocument() (see below) writes to /Users/me/Library/Containers/My-App/Data/Documents, and openDocument() shows me the content of that folder.
On macOS, however, openDocument() shows the Documents folder at the root level of iCloud Drive, not the sandboxed version, which is local to my computer
It's like the documentPickerVC.directoryURL is being ignored. Why is that?
If it helps, the documentURL looks like this:
file:///Users/me/Library/Containers/org.me.My-App/Data/Documents/
Any help would be really, really appreciated!
func saveDocument(){
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
let puzzleData = try? encoder.encode(puzzle)
print("Saving: \(documentURL)")
let saveableURL = documentURL!.appendingPathComponent("\( .puzzle.date)")
try puzzleData!.write(to: saveableURL)
} catch {
displayError(title: "Error while saving document", message: "There was an error: \(error)")
}
}
// when the user taps on the Open button
#objc func openDocument(){
documentPickerVC = UIDocumentPickerViewController(forOpeningContentTypes: [UTType("public.item")!, UTType("public.data")!], asCopy: true )
documentPickerVC.delegate = self
documentPickerVC.modalPresentationStyle = .formSheet
documentPickerVC.directoryURL = documentURL
self.present(documentPickerVC, animated: true)
}
So, the reason documentURL isn't working is because Apple doesn't support it: specifically, “ This property has no effect in Mac apps built with Mac Catalyst.”

Export option doesn't work on Google Pixel device

We have developed an Xamarin.Forms application. We provide option to export file to other apps to explore it. Exported mobi format file to Kindle in Google Pixel device, it couldn't upload in Kindle but this process works in other Android devices. We have used PackageManager.QueryIntentActivities process to list the installed app for export process. Please provide valiable suggestion for this.
Code Snippet:
var mobileFileName = Path.Combine(path, m_documentName);
var shareIntentsLists = new List<Intent>();
Intent sendIntent = new Intent();
sendIntent.SetAction(Intent.ActionSend);
sendIntent.SetType("application/pdf");
sendIntent.SetPackage("com.google.android.apps.docs");
sendIntent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse("file://" + mobileFileName));
Intent chooserIntent = new Intent();
chooserIntent = Intent.CreateChooser(sendIntent, "Share with");
chooserIntent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse(mobileFileName));
if (shareIntentsLists.Count > 0)
{
chooserIntent.PutExtra(Intent.ExtraInitialIntents, shareIntentsLists.ToArray());
}
chooserIntent.SetFlags(ActivityFlags.ClearTop);
chooserIntent.SetFlags(ActivityFlags.NewTask);
context.StartActivity(chooserIntent);
Regards,
Cheran

How to open native video player to play local contents in Xamarin forms

I have some video file embedded with the project, that to be opened in the native video player using Xamarin forms.
Note: Having in-app video player is limited here.
Any idea for this?
Sorry for late, you could refer to FormsNativeVideoPlayer.
When you load your video file from Raw folder, you just need to modify the VideoPlayer_CustomRenderer code like this :
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.View> e)
{
base.OnElementChanged (e);
...
string uriPath = "android.resource://" + Forms.Context.PackageName + "/" + Resource.Raw.audio;
var uri = Android.Net.Uri.Parse((uriPath));
//Set the videoView with our uri, this could also be a local video on device
videoView.SetVideoURI (uri);
...
}

Sending Query Parameters to Chromecast

We are trying to play HLS video on Chromecast device.
We have enabled CORS.
We can successfully play a normal HLS video. but we have problem with URL hashing.
We send chromecast, an url with hashing (for security purpose)
Example:
http://domainname.com/70000871V/70000871V.m3u8?cp=%2FsFcurrent%2F70000871V%2F*&cf=1403&e=1493&h=cbc90
The above is basically an m3u8 video index file, chromecast looks into the index file and chooses a resolution to play, when it accesses the child file, it removes the hashing provided in the url. This results in chromecast not able to access the child file because it removed the hashing paramaters in url.
Consider m3u8 file contains some files like 70000871V_iphone_med.m3u8, so when it tries to access them, it removes the hashing...
How to tell chromecast to keep the hashing parameters when it accesses the index file.
Note: This url successfully playing in Mobile device.
The Console showing the below issue:
### MEDIA ELEMENT LOAD START sample_media_receiver.html:573
XMLHttpRequest cannot load http://domainname.com/s/web_vod/current/90002466V/ROTOX013V_iphone_med.m3u8. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://' is therefore not allowed access. sample_media_receiver.html:1
HOST ERROR - Fatal Error: code = 3 sample_media_receiver.html:487
### MEDIA ELEMENT STALLED
video url: http://domainname.com/70000871V/70000871V.m3u8?cp=%2FsFcurrent%2F70000871V%2F*&cf=1403&e=1493&h=cbc90
The .m3u8 file has,
EXTM3U
EXT-X-VERSION:3
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2037261,CODECS="avc1.4d001f,mp4a.40.5",RESOLUTION=960x540
ROTOX013V_iphone_hi.m3u8
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=740606,CODECS="avc1.66.30,mp4a.40.5",RESOLUTION=640x360
ROTOX013V_iphone_med.m3u8
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=296618,CODECS="avc1.66.30,mp4a.40.5",RESOLUTION=416x234
ROTOX013V_iphone_low.m3u8
EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=5094217,CODECS="avc1.4d001f,mp4a.40.5",RESOLUTION=1280x720
ROTOX013V_ipad_hi.m3u8
How to make this?
you might want to look at chromecast's mediaList/MediaInfo.
and at a sample implementation thereof. -> 'buildMedia()'
Chromecast media support does not have built in support for m3u8 lists.
Instead of trying to push m3u8 handling down into a stack that does not support it, you might want to implement a simple List wrapper at the interface ??
Like "m3u8-to-mediaInfoList" and "mediainfoList-to-m3u8".
OR
do it at the list item level. If you look at that 'buildMedia' method in the source, its a good example of how to get a MediaInfo item from a m3u8 item.
minor mods to one of the CC samples on github....
public static List<MediaInfo> buildMedia(String url, Context ctx) throws JSONException {
//check nulls
mediaList = new ArrayList<MediaInfo>();
JSONObject jsonObj = new VideoProvider().parseUrl(url, ctx);
JSONArray categories = jsonObj.getJSONArray(TAG_RESULTS);
if (null != categories) {
for (int i = 0; i < categories.length(); i++) {
JSONObject category = categories.getJSONObject(i);
String title = category.getString(TAG_MSG);
String subTitle = category.getString(TAG_MSG);
JSONObject media3 = category.getJSONObject(TAG_MEDIA3);
String videoUrl = media3.getString(TAG_URL);
JSONObject media4 = category.getJSONObject(TAG_MEDIA4);
String imageurl = media4.getString(TAG_URL);
String bigImageurl = media4.getString(TAG_URL);
String studio = category.getJSONObject(TAG_CREATEDBY).getString(TAG_USERNAME);
mediaList.add(buildMediaInfo(title, studio, subTitle, videoUrl, imageurl,
bigImageurl));
Log.d(TAG, "MediaInf " +i +" " +imageurl +" " +bigImageurl +" " +videoUrl);
}
}
return mediaList;
}
You need to write a custom receiver (using MPL) and use host overrides updateManifestRequestInfo / updateSegmentRequestInfo to achieve the desired behavior.

Resources