Help with Android FireMonkey startForeground()

Hi!

Can somebody help me with using startForeground() in Delphi XE5?
Found nothing with google.

What I tried but it freezes the app.:

{code}
//* This class was copied from "FMX.Notification.Android"
type
  TGeneratorUniqueID = class
  const
    SETTINGS_NOTIFICATION_UNIQUE_ID = 'SETTINGS_NOTIFICATION_UNIQUE_ID2';
  strict private
    class var FNextUniqueID: Int64;
  public
    class constructor Create;
    class function GenerateID: Integer;
  end;

const
  FMX_NOTIFICATION_CENTER = 'FMX_NOTIFICATION_CENTER2';

class constructor TGeneratorUniqueID.Create;
var
  Preference: JSharedPreferences;
begin
  Preference := SharedActivity.getSharedPreferences(StringToJString(FMX_NOTIFICATION_CENTER), TJContext.JavaClass.MODE_PRIVATE);
  FNextUniqueID := Preference.getInt(StringToJString(SETTINGS_NOTIFICATION_UNIQUE_ID), 0);
end;

class function TGeneratorUniqueID.GenerateID: Integer;
var
  PreferenceEditor: JSharedPreferences_Editor;
  Preference: JSharedPreferences;
begin
  Preference := SharedActivity.getPreferences(TJContext.JavaClass.MODE_PRIVATE);
  PreferenceEditor := Preference.edit;
  try
    PreferenceEditor.putInt(StringToJString(SETTINGS_NOTIFICATION_UNIQUE_ID), FNextUniqueID);
  finally
    PreferenceEditor.commit;
  end;
  Result := FNextUniqueID;
  Inc(FNextUniqueID);
end;

//* My code
procedure TFormMain.SetForeground;
var
    Service: JService;
    notification: JNotification;
    NotificationCompat_Builder: JNotificationCompat_Builder;
    Intent: JIntent;
begin
    NotificationCompat_Builder := TJNotificationCompat_Builder.Create;
    NotificationCompat_Builder := NotificationCompat_Builder.setSmallIcon(SharedActivityContext.getApplicationInfo.icon);
    NotificationCompat_Builder := NotificationCompat_Builder.setContentTitle(StrToJCharSequence(GetApplicationTitle));
    NotificationCompat_Builder := NotificationCompat_Builder.setContentText(StrToJCharSequence('Body'));

    notification := NotificationCompat_Builder.build;

    Intent := TJIntent.Create;
    Intent.setClass(SharedActivityContext, SharedActivityContext.getClass);
    Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_SINGLE_TOP or TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP);
    Intent.setAction(TJFMXNotificationAlarm.JavaClass.ACTION_FMX_NOTIFICATION);

    notification.setLatestEventInfo(MainActivity.getApplicationContext, StrToJCharSequence('Title'), StrToJCharSequence('Text'), TJPendingIntent.JavaClass.getActivity(SharedActivityContext, TGeneratorUniqueID.GenerateID, Intent, 0));

    Service.startForeground(1, notification);
end;
 {code}

Thank you!
0
Utf
11/20/2013 7:55:10 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

8 Replies
4837 Views

Similar Articles

[PageSpeed] 51

Getting closer:

{code}
procedure TFormMain.SetForeground;
var
    Service: JService;
    notification: JNotification;
    NotificationBuilder: JNotificationCompat_Builder;
    Intent: JIntent;
begin
    NotificationBuilder := TJNotificationCompat_Builder.JavaClass.init(SharedActivityContext);
    NotificationBuilder := NotificationBuilder.setSmallIcon(SharedActivityContext.getApplicationInfo.icon);
    NotificationBuilder := NotificationBuilder.setContentTitle(StrToJCharSequence(GetApplicationTitle));
    NotificationBuilder := NotificationBuilder.setContentText(StrToJCharSequence('Body'));
    notification := NotificationBuilder.build;

    Intent := TJIntent.Create;
    Intent.setClass(SharedActivityContext, SharedActivityContext.getClass);
    Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_SINGLE_TOP or TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP);
    Intent.setAction(TJFMXNotificationAlarm.JavaClass.ACTION_FMX_NOTIFICATION);

    notification.setLatestEventInfo(MainActivity.getApplicationContext, StrToJCharSequence('Title'), StrToJCharSequence('Text'), TJPendingIntent.JavaClass.getActivity(SharedActivityContext, TGeneratorUniqueID.GenerateID, Intent, 0));

    Service := TJService.JavaClass.init; //* Exception here

    Service.startForeground(1, notification);

end;
 {code}

No freezes or crashes but an exception now: Exception: java.lang.InstantiationException: can't instantiate class android.app.Service; abstract class or interface
0
Utf
11/20/2013 10:56:41 PM
Ede Csanádi wrote:

> No freezes or crashes but an exception now: Exception:
> java.lang.InstantiationException: can't instantiate class
> android.app.Service; abstract class or interface

You'll probably want to read this:

http://developer.android.com/reference/android/app/Service.html

-- 
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds: 
http://delphi.radsoft.com.au/blog
0
Dave
11/20/2013 11:25:02 PM
Thank you very much, but I already found that page.

It seems this is beyond my knowledge. I am writing an MP3 player, and it seems that the audio is skipping. I was given a suggestion to make my app. a 'foreground service' so the audio wouldn't skip. But it seems it's too complicated.
0
Utf
11/21/2013 1:40:19 AM
> {quote:title=Ede Csanádi wrote:}{quote}
> Thank you very much, but I already found that page.
> 
> It seems this is beyond my knowledge. I am writing an MP3 player, and it seems that the audio is skipping. I was given a suggestion to make my app. a 'foreground service' so the audio wouldn't skip. But it seems it's too complicated.

at this moment, in delphi is not possible to do a service or extends java/android class, so i think that you can't do it
0
Michele
11/21/2013 9:38:33 AM
Thank you! I was afraid of this, read elsewhere about this but wasn't sure it's the same topic.

If you have any suggestions please let me know!
1
Utf
11/23/2013 11:44:58 PM
Michele Carone wrote:

> at this moment, in delphi is not possible to do a service or extends
> java/android class, so i think that you can't do it

You can extend the class, however you need to do that part in Java, and
then import that into your Delphi project.

This video has a couple of examples of how to do that (amongst a bunch
of other stuff):

http://www.youtube.com/watch?v=GcuYc7F0lIU

The part relevant to extending and importing starts at 33mins 25secs.

-- 
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds: 
http://delphi.radsoft.com.au/blog
0
Dave
11/25/2013 4:24:15 AM
Ede Csanádi wrote:

> It seems this is beyond my knowledge. I am writing an MP3 player, and
> it seems that the audio is skipping. I was given a suggestion to make
> my app. a 'foreground service' so the audio wouldn't skip. But it
> seems it's too complicated.

These articles might be of some use to you, too:

http://blog.blong.com/2013/11/delphi-and-android-services.html
http://blog.blong.com/2013/11/delphi-and-android-services-part-2.html

-- 
Dave Nottage [TeamB]
Find tips and code samples at Delphi Worlds: 
http://delphi.radsoft.com.au/blog
0
Dave
11/25/2013 11:12:47 PM
Thank you very much for giving attention to this topic, but that's way to complicated for me.

I hope there will be some kind of update in the next Delphi release to simplify these things.
0
Utf
12/1/2013 10:02:26 PM
Reply:

Similar Artilces:

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

is possible to build an Android .SO with Delphi Firemonkey XE6 ? Thanks.
is possible to build an Android .SO with Delphi Firemonkey XE6 ? Thanks. > {quote:title=Aldo Lacavalla wrote:}{quote} > is possible to build an Android .SO with Delphi Firemonkey XE6 ? Thanks. Have a look in your Android output directory -- Linden "Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source" > {quote:title=Linden ROTH wrote:}{quote} > > {quote:title=Aldo Lacavalla wrote:}{quote} > > is possible to build an Android .SO with Delphi Firemonkey XE6 ? Thanks. > > > Have a look in ...

Linking a .a file in firemonkey - Delphi XE5 SP1
I am trying to link .a files from my FireMonkey application in XE5 for an iOS application, but I am running into issues. I have 3 different .a files that I have tried using, all of which give me the same error when I try to link them: *Bad Object file format: 'd:\project...\libzbar.a'* I have tried this with 2 commonly used .a files, one for barcode reading (zbar) and a magtek card stripe reader library. I also have another test library made in xcode with 2 methods. They all produce the same error on compile. During an embarcadero seminar, we were told that any .a file could b...

Android C demo program to Firemonkey Delphi (Will Pay)
I have a C demo program for the Android platform that I need to convert to Firemonkey and Delphi XE5. This demo logic is written in pure C, and reads one of 5 canned barcodes. Page39a contains those barcodes. The goal is to scan those codes and react accordingly. This conversion will serve as a learning process for me. I am willing to pay for this conversion if need be. Thanking you all in advance and I look forward to any recommendations. Andy http://www.odesk.com/ has developers for hire. Thanks Eli. I will check it out. Andy On Thu, 29 May 2014 06:18:43 -0700, Eli...

[Delphi XE 7 UPD1 FireMonkey / Win32] TThread and WebService Help...
Hi, I write this basic thread class: {code} TWebServiceThread = class(TThread) private FOnExecute : TNotifyEvent; FOnCompleted : TNotifyEvent; procedure Completed; protected procedure Execute; override; public procedure LetsGo; property OnExecute : TNotifyEvent read FOnExecute write FOnExecute; property OnCompleted : TNotifyEvent read FOnCompleted write FOnCompleted; end; procedure TWebServiceThread.Completed; begin if Assigned(FOnCompleted) then FOnCompleted(Self); end; procedure TWebServiceThread.Execute; begin try ...

Firemonkey
I am so dammed frustrated with firemonkey and livebindings. The VCL + DB Controls were fast, consistent, and stable. This fmx framework is crap. It's slow on my i5 Macbook. I'd be embarrassed to put out an app like this. The help is lousy and apparently very few people are using it based on my failed Google searches. I can see why. Livebindings is cute when you have a few fields, but it a rats nest when you have a moderately complex form and have to wire up dozens of controls. There is no official support for nullable fields in livebindings which blows my mind....

Ann: TsiLang Components Suite v7.1! (Multilanguage solution for Delphi and C++Builder with full FireMonkey support including Android and iOS)
Hello, We're glad to announce the release of TsiLang Components Suite 7.1! Simple and powerful localization solution for software developers. It's virtually impossible to find popular software that would not be translated (localized) into multiple languages. In fact, even niche and second-tier developers localize their products to increase international sales. Unfortunately, the process of software localizations is both time consuming and very expensive. Luckily, developers who use Delphi, or C++Builder platform can use TsiLang Components Suite to localize their software...

Ann: TsiLang Components Suite v7.1! (Multilanguage solution for Delphi and C++Builder with full FireMonkey support including Android and iOS)
Hello, We're glad to announce the release of TsiLang Components Suite 7.1! Simple and powerful localization solution for software developers. It's virtually impossible to find popular software that would not be translated (localized) into multiple languages. In fact, even niche and second-tier developers localize their products to increase international sales. Unfortunately, the process of software localizations is both time consuming and very expensive. Luckily, developers who use Delphi, or C++Builder platform can use TsiLang Components Suite to localize their software...

Get the fat out from XE5 Android apps
In the modern mobile OSes (like iOS and Android) the applications are run into a sandbox for more control, security and performance reasons and there are no (easy) ways to separate/use a "runtime" library (in Delphi's case RTL + FireMonkey) to be shared by multiple apps. This problem is common to all mobile x-plat runtimes/wrappers like Adobe AIR (http://www.adobe.com/products/air.html) or Mono (http://www.mono-project.com). In Delphi's case the problem with the increasingly fat apps (statically linking RTL + FireMonkey to the application binary) comes from the non-optimi...

Java, Android, Firemonkey
Hallo, ich hatte schon mal angefangen, möchte aber meine Frage präzisieren. In der Zwischenzeit habe ich ein Beispiel zu Firemonkey gefunden. Mit dieser Bibliothek will ich meine Android-Software erstellen. Die Firemonkey-Units sind in C:\Programme (x86)\embarcadero\RAd Studio\9.0\Source\fmx. Dort fine ich aber nur Beispile, die Windows-Applicationen erstellen - und als auswählbare Zielpattformen gibts Win32, win64 und OS X - nix mit Android.Weiß jemand wie es weitergeht?????????? ...

Installing components for FireMonkey HD and FireMonkey iOS
Hi, How do I install components for both FireMonkey HD and FireMonkey iOS? I have one package 'FMXMyFireMonkeyControl' and 'FMIFireMonkeyControl' which both point to the same file with the same registration 'TFireMonkeyControl'. If I compile one package (FMXMyFireMonkeyControl) it installs correctly, then change the include file (FMCompile.INC) to compile for IOS (FMIFireMonkeyControl) which is included in the FMX.FireMonkeyControl.pas file: {$I FMCOMPILE.INC} uses {$IFDEF COMPILEIOS} FMX_Types, FMX_Objects, FMX_Forms, FMX_Dialogs, FMX_Effe...

Problem (FireMonkey for Android)
Hi, I have a problem for an application I'm developing for Android, I added the component "WebBrowser", and I noticed that when I click a text box does not open the virtual keyboard to write, I find this pretty useless because if I browse on the "www.google.com" I should have the ability to run a search on the internet, you know help me to solve this problem? How can I bring up the keyboard when I click on a text box on the web browser? thanks I paid a fortune for the latest release with the Mobile add-on. Only to find this "fineprint" http://docwiki.embar...

Help Help Help Help Help Help
------=_NextPart_000_0074_01C2960E.EBE13A30 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Can someone please help me. I have installed mysql on Unix Solaris and it works fine I have Perl installed previously which is working and with which i have installed other perlmodules before and are working fine. I have also installed DBI and it works fine with the Sybase drivers which i have installed. When i tried to install the Msql-Mysql-modules-1.2219 drivers i get the following error. # make /usr/local/bin/perl -Iblib/arch -Iblib/lib -I/...

HELP!HELP!HELP!HELP!HELP!HELP!
I was using powerbuilder4.0 a month ago I decided that migrate it to PB7.0 When Im using 4.0, in datawindows I was using extra colums additional to stores procedure. I mean that for example; stored proc. returns 4 columns. I was using 2 extra columns to modify something from client. But I cant do the same thing in PB7.0. How can I do that??? please help. Gurcan yucel gyucel@infina.com.tr "I was using 2 extra columns to modify something from client." what does this mean that you added to the result set? If so then just goto the SQL and add a param. Then set the...

Help Help Help Help
i need to create a crosstab report using Crystal reprot for VS 2003 i face aproblem when i need to order my Fileds by their names my data must be like this Basic Cola Housing Gross Deduction1 Deduction2 Deduction3 Net but when i run my report it give my a not sorted data acutally i have acode field which can i order field using it. but i don't knwo how to do thisSo..................? Select Report tab | |-->Select Record Sort expert Choost the fields you want to sort --Select the corresponding sort direction f...

Firemonkey Android Bug? [Edit]
Hello there, i would like to know if this is a bug or my misstake: I use this procedure for the back button: {code}procedure TForm.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState); begin showmessage(inttostr(Key)); if Key = vkHardwareBack then begin showmessage('it works'); Key := 0; end; end;{code} When i start the app it shows me the correct key "137" and "it works". But if i do anything in my app (for example only browser.navigate xy) and try it again the button doesnt do anything. Where is the error? B...

FireMonkey - image3D not displaying
Hi Im new to XE2 Firemonkey and thought id try and follow a video to produce a sample FireMonkey ios app. But my Image3D components won't display Im using XE2 Update 4 - on a PC (dont have a mac yet ) First I created a - FireMonkey HD IOS Application Dropped a ViewPort3D onto the form Then Added a Image3D so it is connected to the Viewport3d, I then tried assigning an image using the Bitmap-Edit but nothing is displayed? I can see the properties, but on screen I can see nothing but the viewport. Any Ideas? Dave If anyone is familiar with the demo ios apps, her...

How is application Help implemented in FireMonkey?
My legacy app has CHM help. Is there a cross platform solution for application Help? My FireMonkey app is for Windows and Macintosh. Any documentation or videos would be gratefully appreciated. What I do is change over to regular HTML pages. You should be able to extract your CHM file pages to separate HTML pages and images and deploy them to a directory along with the app. In your app have a link to the index page and it will open up automatically in the browser on both Windows and Mac. > {quote:title=Douglas Rudd wrote:}{quote} > What I do is change over to regular HTML ...

idTelnet on Firemonkey Help [Edit]
Hi im using XE5 Firemonkey Android project & i have tested the component idTelnet but seem's to be there's a problem with it when i compile i have this error : [DCC Error] Unit1.pas(52): E2003 Undeclared identifier: 'TIdBytes' and this error is with Indy version : 10.6.0.5040 procedure TForm1.IdTelnet1DataAvailable(Sender: TIdTelnet; const Buffer: TIdBytes); const CR = #13; LF = #10; var Start, Stop : Integer; begin if memo3.Lines.Count = 0 then memo3.Lines.Add(''); Start := 1; Stop := Pos(CR, Buffer); if Stop = 0 t...

help help help help
Name: chef mario Email: chefusa_at_pacbell.net Product: Firefox Summary: help help help help Comments: Heard great reports about Firefox!!! Downloaded & installed Firefox !!!! Lost All my very very valuable BOOKMARKS!!! CAN ANYONE HELP!!!!! All bookmarks were in Internet Explorer Did bookmark transfer to Firefox. Seem the Fox eat all m,y bookmarks Need serious help anyone. chef mario Browser Details: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8) Gecko/20051025 Firefox/1.5 ...

firemonkey android
is it possible to do something in background when the application has not been opened? like a service.(for notification or somethings similar) > {quote:title=Fabio Giovanetti wrote:}{quote} > is it possible to do something in background when the application has not been opened? like a service.(for notification or somethings similar) when the user hits the home button, the app is just hidden from view....its still running and not hibernated (like on iOS) also there is a video/info about app notifications I saw somewhere...try the doc wiki or googling it > {quote:title=Brian Ha...

InitApp for Android in XE8 Firemonkey
Hi, I am trying to get the following code examples to work: http://cc.embarcadero.com/Item/29684  Crossplatform OpenGL XE2/XE5 CubeMan3D Demo; http://cc.embarcadero.com/Item/29682 They work fine in Windows, but fail for the Android because InitApp is not found. I assume this is because it moved to another unit, but I cannot find it in the document, on the web, or in any units I have looked for. Does anyone know where it is? From the author of CubeMan: Well CubeMan3D works under XE8 if you add the unit Androidapi.NativeActivity and replace "InitApp" by "PA...

Firemonkey TWebBrowser Android TPopup
Hi There, We're trying to add an overlay on a webbrowser to display some information. In Firemokey (iOS,Android) there is no way to add FMX controls over the TWebbrowser for they will not be visable. The workaround is to create a TForm or TPopup and call Popup1.Popup;. We have done this and it does work for iOS. but in Andriod the TPopup appears behind the TWebBrowser. is there anyway to overcome this problem? regards, Peter-Paul > {quote:title=Joke van den Broek wrote:}{quote} > The workaround is to create a TForm or TPopup and call Popup1.Popup;. > We have ...

Web resources about - Help with Android FireMonkey startForeground() - embarcadero.delphi.firemonkey

Changes - azilink - usb tethering application for android - Google Project Hosting
... Source Checkout Browse Changes 10 - 1 of 10 Committed Changes Rev Scores Commit log message Date Author r10 Change setForeground to startForeground ...

Service API changes starting with Android 2.0
Background on services Before going into the details of 2.0, it may be useful to go over a quick summary of services. The Service API in Android ...

Android Developers Blog
Background on services Before going into the details of 2.0, it may be useful to go over a quick summary of services. The Service API in Android ...

Resources last updated: 2/15/2016 2:51:18 PM