Firebase Extension - Resize - firebase

I wanted to try the Resize-Firebase-Extension. Configuration seemed very easy and pictures i upload to that bucket are being handled. The new /thumbs folder appeared and telling by the given size a much smaller version of these images is displayed in the console. However these pics cant be opened (firebase console seems to crash: a new tab opens and redirects to project overview). Also the preview is not showing in console when in the thumbs folder.
I did add the content metadata like this:
if (byteArray != null){
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("image/jpeg")
.setCustomMetadata("isGroupImage", isGroup)
.setCustomMetadata("areaNumber", userNumber)
.build();
mUploadtask =mStorageRef.putBytes(byteArray, metadata).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
callback.onSuccess(mStorageRef.toString());
Anything else to be taken care of for the function to work? Anyone else facing that problem?

Related

Read (audio) file from subfolder in AndroidAssets in Xamarin.Forms

I try to eneable audio in my Xamarin.Forms application. I want to have the audio files in a Subfolderof the Assetsfolder like this Assets/Subfolder/Audio.mp3
I have found a plugin SimpleAudioPlayer which provide an example.
The following code works like provided.
var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
player.Load("Audio.mp3");
Now I want to place the audio file in a subfolder and I tried to call
player.Load("Subfolder/Audio.mp3");
But I get an Java.IO.FileNotFoundException
I looked then into the implementation of the Load function and I fould the following code
public bool Load(string fileName)
{
player.Reset();
AssetFileDescriptor afd = Android.App.Application.Context.Assets.OpenFd(fileName);
player?.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
return PreparePlayer();
}
where the filename is pasted to the Assets.OpenFd() function. which returns an AndroidFileDesriptor
The documentation does not really provide any information from Microsoft and from the Android site.
My questions are
How can I receive the file from the subfolder in Android Assets?
What can I paste into the Assets.OpenFd() function (subfolders etc)?
I would appreciate any advice, since after a long time trying to resolve it I don't really have an idea.
According to the docs of the package, you won't be able to do just that because you have to use player.Load(GetStreamFromFile("mysound.wav")); where GetStreamFromFile is basically
Stream GetStreamFromFile(string filename)
{
var assembly = typeof(App).GetTypeInfo().Assembly;
var stream = assembly.GetManifestResourceStream("App." + filename);
// Obviously App in the line above should be replaced with your app
return stream;
}
And secondly you have to player.Load(GetStreamFromFile("Subfolder.mysound.wav")); where Subfolder is the name of your subfolder.

Save bitmap to gallery and access it through local notification

In an app, I am taking a screenshot of the content of a page, and I want to save it in the Gallery, create a local notification with the image in it, and when the user taps on it, it open the image from the Gallery.
As of now, I am able to take the snapshot and save it using this :
var path = MediaStore.Images.Media.InsertImage(context.ContentResolver, bitmap, "TestImage.png", "Snapshot taken");
I have a few problems with this approach, I can see the image in the Pictures folders from the Gallery, but the name is not the one I specified in this case "TestImage.png". Also, the path returned from this call has the URI scheme "content://...".
After that, I create the local notification with NotificationCompat.Builder with the embedded image, it works well. But when I try to add the PendingIntent to it to open the image I have an issue with the path returned from InsertImage call. The path returned is :
content://media/external/images/media/1292
I tried this :
var path = FileProvider.GetUriForFile(CrossCurrentActivity.Current.AppContext, "com.myapp.fileprovider", new File(path));
but it doesn't work, I get an exception :
Java.Lang.IllegalArgumentException: Failed to find configured root that contains /content:/media/external/images/media/1292
I also tried this :
global::Android.Net.Uri.FromFile(new File(path)), "image/*")
but I receive another exception :
Android.OS.FileUriExposedException: file:///content%3A/media/external/images/media/1292 exposed beyond app through Intent.getData()
This is the code I use to create the notification:
NotificationCompat.BigPictureStyle picStyle = new NotificationCompat.BigPictureStyle();
picStyle.BigPicture(bitmap);
picStyle.SetSummaryText("The snapshot has been saved to your library");
const int pendingIntentId = 0;
PendingIntent pendingIntent =
PendingIntent.GetActivity(CrossCurrentActivity.Current.Activity, pendingIntentId,
new Intent().SetAction(Intent.ActionView)
.SetDataAndType(global::Android.Net.Uri.FromFile(new File(path)), "image/*"), PendingIntentFlags.OneShot);
NotificationCompat.Builder builder = new NotificationCompat.Builder(CrossCurrentActivity.Current.AppContext, "UniqueID")
.SetContentIntent(pendingIntent)
.SetContentTitle("Security center")
.SetContentText("The snapshot has been saved to your library")
.SetSmallIcon(Resource.Drawable.ic_notification);
builder.SetStyle(picStyle);
Notification notification = builder.Build();
NotificationManager notificationManager =
CrossCurrentActivity.Current.Activity.GetSystemService(Context.NotificationService) as NotificationManager;
const int notificationId = 0;
notificationManager.Notify(notificationId, notification);
Do you guys have any idea on how I could save the image with the right name in the Public Gallery folder then access it in the PendingIntent for the local notification ?
Thank you all !
Okay so after a few hours of trial and error, I found out the issue, when parsing the path returned from the MediaStore.Images.Media.InsertImage, I had to use global::Android.Net.Uri.Parse() and not Uri.FromFile(), the latter is only if your path has the URI scheme "file://". By doing that I was able to make the ContentIntent work on the local notification. Only problem now is the name of the file that's not respected.

Firebase ShortDynamicLink not completing task

Following is how I'm creating dynamic link
//Buiid dynamic link
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.chefcookrecipe.com/"))
.setDynamicLinkDomain("chefcookrecipe.page.link")
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildDynamicLink();
String dynamicLongUri = dynamicLink.getUri().toString();
Toast.makeText(Edit_Recipes.this, dynamicLongUri, Toast.LENGTH_SHORT).show();
The same url:"https://www.chefcookrecipe.com/" is what I set as Deep link URL in firebase, and https://chefcook.page.link is my domain in firebase.
I'm getting the long link correctly. However, when I tried to generate short link with the following code
shortLinkTask.addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
// Short link created
shortLink = task.getResult().getShortLink().toString();
Uri flowchartLink = task.getResult().getPreviewLink();
Toast.makeText(Edit_Recipes.this, shortLink, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Edit_Recipes.this, "null", Toast.LENGTH_SHORT).show();
}
}
});
I always get null. Please help I don't know what I'm missing.
I ran into same error couple of months ago. I spent all day finding what was wrong.
As long as it is reaching the conditional (if-else) statement, Your code is completely correct and nothing wrong at all.
Solution
It is usually a typographical error.
Calm yourself.
Make sure that both Deep link URL and Domain name are the same.(This is where the error usually lies). Do a copy and paste instead of typing.
I saw this issue, Don't use emulator, use real device.

c:\windows\system32\inetsrv\Test.pdf is denied

I have a requirement to generate a pdf document on a button click on using visual web part- sharepoint 2010.
I am using the the open source library http://www.itextpdf.com/ for the same. I am able to execute the below code using the project type as a Windowns Application. But, when I want do it on a button click , I am receiving c:\windows\system32\inetsrv\Test.pdf' is denied. error.
Below is the code that I am using
public static void Main(string[] args) --Console Application
{
Console.WriteLine("PDF demo");
Document myDoc = new Document(PageSize.A4.Rotate());
try
{
PdfWriter.GetInstance(myDoc, new FileStream("Salman.pdf", FileMode.Create));
myDoc.Open();
myDoc.Add(new Paragraph("First pdf File made by Salman using Itext"));
}
catch (DocumentException ex)
{
Console.Error.WriteLine(ex.Message);
}
myDoc.Close();
}
}
But I want do the same on a button click event.
protected void pdfGenerator_OnClick(object sender, EventArgs e)
{
Document myDoc = new Document(PageSize.A4.Rotate());
try
{
PdfWriter.GetInstance(myDoc, new FileStream("Salman.pdf", FileMode.Create));---I get an error here
myDoc.Open();
myDoc.Add(new Paragraph("First pdf File made by Salman using Itext"));
}
catch (DocumentException ex)
{
Console.Error.WriteLine(ex.Message);
}
myDoc.Close();
}
}
Please help me , i dont understand the reason for the error. I am tyring it for the first time.
The problem is you are trying to create a PDF in a directory you do not have access to. This is because you are not specifying the directory to save the path; which causes it to default in the same location as the current working directory. In many cases, such as for ASP.NET; the default is the same as the location of the process. For ASP.NET, the process is w3wp.exe and resides in c:\windows\system32\inetsrv. Most identities that w3wp will run as (Network Service or AppPoolIdentity) do not have access to that directory. In fact, only system administrators do.
You need to save it somewhere else that the process has write permissions to here:
PdfWriter.GetInstance(myDoc, new FileStream("Janaki.pdf", FileMode.Create))
Should be something like:
PdfWriter.GetInstance(myDoc, new FileStream(#"C:\directoryIcanWriteTo\Janaki.pdf", FileMode.Create))
If you want to save it in the same place as the website, you would use HttpContext.Current.Server.MapPath:
PdfWriter.GetInstance(myDoc, new FileStream(HttpContext.Current.Server.MapPath("~/Janaki.pdf", FileMode.Create))
Regardless, the identity will still need write permissions to the directory if it doesn't have them. But you definitely shouldn't put them in inetsrv.
Just don't use "FileStream" which requires write permissions on the server. Replace it with MemoryStream and then flush its content on the user's browser.

Blackberry - Cannot create SQLite database

I am making an app that runs in the background, and starts on device boot.
I have read the docs, and have the SQLiteDemo files from RIM, and I am using them to try create a database on my SD Card in the simulator.
Unfortunately, I am getting this error:
DatabasePathException:Invalid path name. Path does not contains a proper root list. See FileSystemRegistry class for details.
Here's my code:
public static Database storeDB;
public static final String DATABASE_NAME = "testDB";
private String DATABASE_LOCATION = "file:///SDCard/Databases/MyDBFolder/";
public static URI dbURI;
dbURI = URI.create(DATABASE_LOCATION+DATABASE_NAME);
storeDB = DatabaseFactory.openOrCreate(dbURI);
I took out a try/catch for URI.create and DatabaseFactory.openOrCreate for the purposes of this post.
So, can anyone tell me why I can't create a database on my simulator?
If I load it up and go into media, I can create a folder manually. The SD card is pointing to a folder on my hard drive, and if I create a folder in there, it is shown on the simulator too, so I can create folders, just not programatically.
Also, I have tried this from the developer docs:
// Determine if an SDCard is present
boolean sdCardPresent = false;
String root = null;
Enumeration enum = FileSystemRegistry.listRoots();
while (enum.hasMoreElements())
{
root = (String)enum.nextElement();
System.err.println("root="+root);
if(root.equalsIgnoreCase("sdcard/"))
{
sdCardPresent = true;
}
}
But it only picks up store/ and never sdcard/.
Can anyone help?
Thanks.
FYI,
I think I resolved this.
The problem was I was trying to write to storage during boot-up, but the storage wasn't ready. Once the device/simulator was loaded, and a few of my listeners were triggered, the DB was created.
See here:
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/832062/How_To_-_Write_safe_initialization_code.html?nodeid=1487426&vernum=0

Resources