Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Development


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

retrive name of current running app

Hi All,

how we can get the name of the current running application on BB10 using ported Andriod App.

thanks
Highlighted
Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B
My Carrier: Bell

Re: retrive name of current running app

You get it the same way you do in Android:

 

    private String getAppName()
    {
        final PackageManager packageManager = getApplicationContext().getPackageManager();
        ApplicationInfo applicationInfo;
        try
        {
            applicationInfo = packageManager.getApplicationInfo(this.getPackageName(), 0);
        }
        catch (final NameNotFoundException e)
        {
            applicationInfo = null;
        }
        return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "(unknown)");
    }

 

This will return the app name as defined in the <application> tag of the AndroidManifest.xml

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com
Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: retrive name of current running app

this will return your application package name,
i need to close my application and put a runningservice or broadcastreceiver in the background which will check every set of seconds for the current opened app.
Trusted Contributor
Posts: 103
Registered: ‎11-07-2010
My Device: Not Specified

Re: retrive name of current running app

i tries this

private String getAppName(Context context) {

ActivityManager am = (ActivityManager) context
.getSystemService(context.ACTIVITY_SERVICE);

// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);

ComponentName componentInfo = taskInfo.get(0).topActivity;
Log.w("BBBBB10000", componentInfo.getPackageName());
Log.w("BBBBB10000 fffff ", componentInfo.flattenToShortString());

return componentInfo.getPackageName();
}

but is always return " com.qnx.android.app.launcher " not the actual opend app name
Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B
My Carrier: Bell

Re: retrive name of current running app

With the code that I posted, I have this in the manifest

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.bbbuildserial.BbBuildSerialActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

 

and receive my entry for @string/app_name, not the package.

 

    Justin

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: retrive name of current running app

You will only ever be able to retreive an Android Activity that's on top of the Android ActivityStack.  And if there's no Android app in the foreground, this will always be "com.qnx.android.app.launcher" (which is a "homescreen" you never see).

 

I.e. you may notice when you thumbnail your app, your app gets paused / stopped.  That's because on thumbnail we foreground this launcher, and so it's at the top of the stack as far as Android's concerned.  When you fullscreen your app again we behave as though you've just resumed your app from the recent Activity list.