Start app menu item for registered apps

This commit is contained in:
Dominik Schürmann 2014-05-07 15:03:24 +02:00
parent 2a33eae9eb
commit b771276611
7 changed files with 31 additions and 4 deletions

View File

@ -40,6 +40,9 @@ public class AppSettingsActivity extends ActionBarActivity {
private AppSettingsFragment mSettingsFragment;
private AccountsListFragment mAccountsListFragment;
// model
AppSettings mAppSettings;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -80,22 +83,39 @@ public class AppSettingsActivity extends ActionBarActivity {
case R.id.menu_api_settings_revoke:
revokeAccess();
return true;
case R.id.menu_api_settings_start:
startApp();
return true;
}
return super.onOptionsItemSelected(item);
}
private void startApp() {
Intent i;
PackageManager manager = getPackageManager();
try {
i = manager.getLaunchIntentForPackage(mAppSettings.getPackageName());
if (i == null)
throw new PackageManager.NameNotFoundException();
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
Log.e(Constants.TAG, "startApp", e);
}
}
private void loadData(Bundle savedInstanceState, Uri appUri) {
AppSettings settings = new ProviderHelper(this).getApiAppSettings(appUri);
mSettingsFragment.setAppSettings(settings);
mAppSettings = new ProviderHelper(this).getApiAppSettings(appUri);
mSettingsFragment.setAppSettings(mAppSettings);
String appName;
PackageManager pm = getPackageManager();
try {
ApplicationInfo ai = pm.getApplicationInfo(settings.getPackageName(), 0);
ApplicationInfo ai = pm.getApplicationInfo(mAppSettings.getPackageName(), 0);
appName = (String) pm.getApplicationLabel(ai);
} catch (PackageManager.NameNotFoundException e) {
// fallback
appName = settings.getPackageName();
appName = mAppSettings.getPackageName();
}
setTitle(appName);

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 778 B

View File

@ -2,6 +2,12 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_api_settings_start"
android:title="@string/api_settings_start"
android:icon="@drawable/ic_action_play"
app:showAsAction="always" />
<item
android:id="@+id/menu_api_settings_revoke"
android:title="@string/api_settings_revoke"

View File

@ -424,6 +424,7 @@
<string name="api_settings_save">Save</string>
<string name="api_settings_cancel">Cancel</string>
<string name="api_settings_revoke">Revoke access</string>
<string name="api_settings_start">Start application</string>
<string name="api_settings_delete_account">Delete account</string>
<string name="api_settings_package_name">Package Name</string>
<string name="api_settings_package_signature">SHA-256 of Package Signature</string>