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™ Runtime Development

Reply
Trusted Contributor
omar123456789
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
Please use plain text.
BlackBerry Development Advisor
jjasmann
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
Please use plain text.
Trusted Contributor
omar123456789
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.
Please use plain text.
Trusted Contributor
omar123456789
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
Please use plain text.
BlackBerry Development Advisor
jjasmann
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
Please use plain text.
BlackBerry Development Advisor
bbenninger
Posts: 130
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.

Please use plain text.