Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
3
Erster Beitrag:
vor 2 Jahren, 8 Monaten
Letzter Beitrag:
vor 2 Jahren, 7 Monaten
Beteiligte Autoren:
Tobias, Danny Lauwers

bring up my application WDM 18

Startbeitrag von Tobias am 27.06.2015 22:48

I have an application where a persistent thread shot and generates a notification when a new event arrives. All this does it very well.

I need that shot when the notification prompted the application is in the background and to the foreground so that the user sees.

I have this procedure but has errors


public void startNewActivity(Context context, String packageName) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);
if (intent != null) {
// We found the activity now start the activity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
// Bring user to the market or let them choose an app?
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" + packageName));
context.startActivity(intent);
}
}


Thanks for your help
Tobias

Antworten:

Tobias,

I'm not sure it is perfect, but this does work correctly for my Android application


public static void JBringAppToFront()
{
try {
// Retrieve the current activity
Activity tmpActivity = getCurrentActivity();

// Retrieve the current Context
Context tmpContext = getApplicationContext();

// Get Class name
String packageName = tmpContext.getPackageName();
Intent launchIntent = tmpContext.getPackageManager().getLaunchIntentForPackage(packageName);
String className = launchIntent.getComponent().getClassName();

// Create intent / activity
Intent myIntent = new Intent();
myIntent.setClassName(tmpContext,className);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // You need this if starting the activity from a service
myIntent.setAction(Intent.ACTION_MAIN);
myIntent.addCategory(Intent.CATEGORY_LAUNCHER);

// Start the activity
tmpContext.startActivity(myIntent);
}
catch(Exception e) {
e.printStackTrace();
}
}


If you want to show your application on top of the lockscreen so the user can directly see what is happening you can set some extra flags in the initialization code of that window.


public static boolean SetExtraWindowFlags()
{
// Set Some Extra Window Flags
Activity tmpActivity = getCurrentActivity();
tmpActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

return true;
}


And when you call this code it will wake your device, turn the screen on and show your application fullscreen


public static boolean JWakeDevice(boolean bWakeup)
{
// Wake or rest the device
try {


if (bWakeup) {
//callWLProcedure("ShowMessage","Wake UP");
// Awake the Device
Activity tmpActivity = getCurrentActivity();
tmpActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
// Reset stuff
//callWLProcedure("ShowMessage","Rest");
Activity tmpActivity = getCurrentActivity();
tmpActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
} catch(Exception e) {
e.printStackTrace();
return false;

}
return true;
}


Hope this code helps !

If you apply any improvements, please let me know what you have done to make these functions any better ! ;)

You will have to include the correct import statements before it will compile.

Have a nice day
Danny

von Danny Lauwers - am 29.06.2015 15:07
Danny thank you very much

It is just what was wanted, everything worked perfectly.

Thanks Danny

Tobias :spos::)

von Tobias - am 06.07.2015 00:06
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.