Playlist Rename with Mediastore on Android 11 - rename

In android 11 I cant rename playlists anymore.
Here is the error which I'm getting:
java.lang.IllegalArgumentException: Movement of content://media/external/audio/playlists which isn't part of well-defined collection not allowed
Here is my code:
fun renamePlaylist(id: Long, name: String) {
try {
val values = ContentValues(1)
values.put(MediaStore.Audio.PlaylistsColumns.NAME, name)
context.contentResolver.update(
Playlists.EXTERNAL_CONTENT_URI,
values,
BaseColumns._ID + "=?", arrayOf(id.toString())
)
context.scheduleTask(PlaylistRenamed, null)
} catch (e: Exception) {
firebaseCrashlytics.recordException(e)
}
}
Can you help me to resolve this issue.
Thanks,
Petros

Related

How I can resolve this error in Katalon Groovy:unexpected token: do // Groovy:unexpected token: if // Groovy:expecting EOF, found 'if'

// Read data from XML file
public static String getElementTextByTagName(String tagName) {
try {
String dirPath = System.getProperty('user.dir') + "\\DataFiles\\TestData.xml"
List<File> xmlFiles = getXMLFilesByDirectory(dirPath);
Iterator var3 = xmlFiles.iterator();
XMLSearchResult searchResult;
do {
if (!var3.hasNext()) {
throw new ElementNotFoundInXMLException("Element Not Found");
}
File xmlFile = (File)var3.next();
searchResult = searchForElementInsideFile(xmlFile, tagName);
} while(!searchResult.isFound());
return searchResult.getElementText();
} catch (ElementNotFoundInXMLException var6) {
var6.printStackTrace();
return null;
}
}
enter image description here
The error is appearing on the do statement line and below the same for if statement
Katalon Studio uses a version of Groovy, at the time of this answer, that does not support do-while loops.
For that effect, you'll have to do something like what's outlined in this question.
Consider it a professional courtesy that I take the time to link the answer here, instead of voting to close the question because it's already answered by that other question.
Welcome to StackOverflow.

What is the new button name for Base.Actions["LSPOReceiptLine_binLotSerial"].Press()?

I have inherited an older customization to the Purchase Receipts / PO302000 screen that I'm trying to upgrade, and it had customization code to import Lot/Serial nbrs from an Excel spreadsheet. It all seems to work alright, except that at the end, it errors out when pressing a button as follows:
Base.Actions["LSPOReceiptLine_binLotSerial"].Press();
Here's the entire code:
public virtual void importAllocations()
{
try
{
if (Base.transactions.Current != null)
{
var siteid = Base.transactions.Current.SiteID;
if (Base.splits.Select().Count == 0)
{
if (this.NewRevisionPanel.AskExt() == WebDialogResult.OK)
{
const string PanelSessionKey = "ImportStatementProtoFile";
PX.SM.FileInfo info = PX.Common.PXContext.SessionTyped<PXSessionStatePXData>().FileInfo[PanelSessionKey] as PX.SM.FileInfo;
System.Web.HttpContext.Current.Session.Remove(PanelSessionKey);
if (info != null)
{
byte[] filedata = info.BinData;
using (NVExcelReader reader = new NVExcelReader())
{
Dictionary<UInt32, string[]> data = reader.loadWorksheet(filedata);
foreach (string[] textArray in data.Values)
{
if (textArray[0] != GetInventoryCD(Base.transactions.Current.InventoryID))
{
throw (new Exception("InventoryID in file does not match row Inventory ID"));
}
else
{
//Find the location ID based on the location CD provided by the Excel sheet...
INLocation inloc = PXSelect<INLocation,
Where<INLocation.locationCD, Equal<Required<INLocation.locationCD>>,
And<INLocation.siteID, Equal<Required<INLocation.siteID>>>>>.Select(Base
, textArray[1]
, Base.transactions.Current.SiteID);
Base.splits.Insert(new POReceiptLineSplit()
{
InventoryID = Base.transactions.Current.InventoryID,
LocationID = inloc.LocationID, //Convert.ToInt32(textArray[1]), //Base.transactions.Current.LocationID,
LotSerialNbr = textArray[2],
Qty = Decimal.Parse(textArray[3])
});
}
}
}
}
}
}
}
Base.Actions["LSPOReceiptLine_binLotSerial"].Press();
}
catch (FileFormatException fileFormat)
{
// Acuminator disable once PX1053 ConcatenationPriorLocalization [Justification]
throw new PXException(String.Format("Incorrect file format. File must be of type .xlsx", fileFormat.Message));
}
catch (Exception ex)
{
throw ex;
}
}
Now, there seems to be no such button - and I have no idea what it would be called now, or if it even still exists. I don't even really know what this action did.
Any ideas?
Thanks much...
That logic has been moved into the PX.Objects.PO.GraphExtensions.POReceiptEntryExt.POReceiptLineSplittingExtension. That action was doing the following in the PX.Objects.PO.LSPOReceiptLine
// PX.Objects.PO.LSPOReceiptLine
// Token: 0x0600446F RID: 17519 RVA: 0x000EE86C File Offset: 0x000ECA6C
public override IEnumerable BinLotSerial(PXAdapter adapter)
{
if (base.MasterCache.Current != null)
{
if (!this.IsLSEntryEnabled((POReceiptLine)base.MasterCache.Current))
{
throw new PXSetPropertyException("The Line Details dialog box cannot be opened because changing line details is not allowed for the selected item.");
}
this.View.AskExt(true);
}
return adapter.Get();
}
Now it is called ShowSplits and is part of the POReceiptLineSplittingExtension extension.
// PX.Objects.PO.GraphExtensions.POReceiptEntryExt.POReceiptLineSplittingExtension
// Token: 0x06005359 RID: 21337 RVA: 0x00138621 File Offset: 0x00136821
public override IEnumerable ShowSplits(PXAdapter adapter)
{
if (base.LineCurrent == null)
{
return adapter.Get();
}
if (!this.IsLSEntryEnabled(base.LineCurrent))
{
throw new PXSetPropertyException("The Line Details dialog box cannot be opened because changing line details is not allowed for the selected item.");
}
return base.ShowSplits(adapter);
}
Given the fact that ShowSplits is defined in the LineSplittingExtension originally it may be referred to as "LineSplittingExteions_ShowSplits" or "POReceiptLineSplittingExtension_ShowSplits". I would suggest including that POReceiptLineSplittingExtension as part of your extension and simply call the Base1.ShowSplits

How do I convert a string to a JSONObject in kotlin from openweather response?

I would like some help converting an openweather response to a JSONObject right now I am able to get the response using this class.
import java.net.URL
class ConexionClima {
public fun conseguirRespuestaDeAPI(lat: Double, lon: Double): String ?{
val apiKey: String = "99ccac116e6924f62f669458a754299c"
var respuesta: String?
val urlStr = "https://api.openweathermap.org/data/2.5/onecall?lat=2.0&lon=1.0&appid=99ccac116e6924f62f669458a754299c"
try{
respuesta = URL(urlStr).readText(Charsets.UTF_8)
} catch (e: Exception) {
respuesta = null
}
return respuesta
}
}
But when I try to convert it using this function
fun resolverPrimerProblema(latitud: Double, longitud: Double): String{
val cc = ConexionClima()
val datos : String? = cc.conseguirRespuestaDeAPI(latitud, longitud)
if (datos != null) {
val datosJson = JSONObject(datos)
}
return("")
}
It just says that "datosJson" is set to null even though the string used is not null and is the response from openWeather. I know this from debugging.
Can someone tell me what am I doing wrong or what the correct way of doing this is?
Thanks in advance!
This is probably because you are getting an exception and therefore your variable respuesta is returning as null
This is also probably happening because you are executing a network call on the main thread and therefore getting this exception:
NetworkOnMainThreadException
This is why i would recommend using Volley or Retrofit etc, but if you are keen on trying this, execute your code on a different thread by doing something like:
Thread {
resolverPrimerProblema(latValue, longValue)
}.start()

App is crashing without showing any error?

I am calling apis using retrofit and rxkotlin. But when I start fragment the app gets crash without any notification or does not show any error msg in the studio logcat. Here is the code.
From here I am call the apis interface
try {
if (disposable == null) {
Log.e("disposable","reached")
disposable = api.getUsers(api_key,
"json",
"1",
"flickr.interestingness.getList")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe (
{
data: FlickrPhoto? -> Log.e("flickr photo",data!!.photo?.get(0)?.secret)
}
)
Log.e("disposable1","reached")
}
}
catch (e: Exception){
Log.e("flickr fragment",e.toString())
}
Here is the api interface code :
interface API {
#GET("services/rest")
fun getUsers(#Query("format") format : String,
#Query("api_key") api_key : String,
#Query("nojsoncallback") nojsoncallback : String,
#Query("method") method : String
) : Observable<FlickrPhoto>
companion object{
fun createView():API{
Log.e("apis","creatview")
try {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.flickr.com/")
.addCallAdapterFactory(
RxJava2CallAdapterFactory.create())
.addConverterFactory(
GsonConverterFactory.create())
.build()
Log.e("retrofit",retrofit.toString())
return retrofit.create(API::class.java)
}
catch (e: Exception){
Log.e("api exception",e.message)
}
Log.e("apis","creatview retrofit null")
return null!!
}
}
}
Here is the logcat:
11-07 03:47:07.527 11627-11627/com.redvelvet.abhi.imagesmapling E/disposable: reached
11-07 03:47:07.529 11627-11627/com.redvelvet.abhi.imagesmapling E/apis: creatview
11-07 03:47:07.620 11627-11627/com.redvelvet.abhi.imagesmapling E/retrofit: retrofit2.Retrofit#ec11d24
11-07 03:47:07.751 11627-11627/com.redvelvet.abhi.imagesmapling E/disposable1: reached

Android 6 get path to downloaded file

I our app (Xamarin C#) we download files from a server. At the end of a succeful download we get the URI to the newly-downloaded file and from the URI we get the file path:
Android.Net.Uri uri = downloadManager.GetUriForDownloadedFile(entry.Value);
path = u.EncodedPath;
In Android 4.4.2 and in Android 5 the uri and path look like this:
uri="file:///storage/emulated/0/Download/2.zip"
path = u.EncodedPath ="/storage/emulated/0/Download/2.zip"
We then use path to process the file.
The problem is that in Android 6 (on a real Nexus phone) we get a completely different uri and path:
uri="content://downloads/my_downloads/2802"
path="/my_downloads/2802"
This breaks my code by throwing a FileNotFound exception. Note that the downloaded file exists and is in the Downloads folder.
How can I use the URI I get from Android 6 to get the proper file path so I can to the file and process it?
Thank you,
donescamillo#gmail.com
I didn't get your actual requirement but it looks like you want to process file content. If so it can be done by reading the file content by using file descriptor of downloaded file. Code snippet as
ParcelFileDescriptor parcelFd = null;
try {
parcelFd = mDownloadManager.openDownloadedFile(downloadId);
FileInputStream fileInputStream = new FileInputStream(parcelFd.getFileDescriptor());
} catch (FileNotFoundException e) {
Log.w(TAG, "Error in opening file: " + e.getMessage(), e);
} finally {
if(parcelFd != null) {
try {
parcelFd.close();
} catch (IOException e) {
}
}
}
But I am also looking to move or delete that file after processing.
May you an build your URI with the download folder :
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toURI();
It's work. #2016.6.24
#Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals( action)) {
DownloadManager downloadManager = (DownloadManager)context.getSystemService(Context.DOWNLOAD_SERVICE);
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
Cursor c = downloadManager.query(query);
if(c != null) {
if (c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if (DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
String downloadFileUrl = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
startInstall(context, Uri.parse(downloadFileUrl));
}
}
c.close();
}
}
}
private boolean startInstall(Context context, Uri uri) {
if(!new File( uri.getPath()).exists()) {
System.out.println( " local file has been deleted! ");
return false;
}
Intent intent = new Intent();
intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction( Intent.ACTION_VIEW);
intent.setDataAndType( uri, "application/vnd.android.package-archive");
context.startActivity( intent);
return true;
}

Resources