How can we solve the null excaption in actionbar getactionbar function? - android-actionbar

First I want to say that I am new in android, I have a lot of troubles with android action bar I am trying to not getting null on this line:
ActionBar actionBar = getActionBar();
I tried everything. I understand that it's returning null because the theme is not suitable to the theme of the activity. I don't know how to set a different theme to each one, but after I found a way to avoid this problem I got another problem. What I am trying to do is actionbar, and a tab bar, now I can't see the icons in the action bar, I see them in the overflow.
onCreate:
public class MainViewActivity extends Activity implements RoutesFragment.OnFragmentInteractionListener ,GroupsFragment.OnFragmentInteractionListener
,VideosFragment.OnFragmentInteractionListener,PhotosFragment.OnFragmentInteractionListener
{
private final CharSequence charSequence[] = {"Profile", "New route", "My route", "Liked route", "GroupsFragment", "Settings", "About CTwalk"};
private String charSequence2;
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_view);
getOverflowMenu();
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
Tab tab = actionBar.newTab()
.setText(R.string.tabs_Routes)
.setTabListener(new TabListener<RoutesFragment>(this, "Routes", RoutesFragment.class));
actionBar.addTab(tab);
tab = actionBar.newTab()
.setText(R.string.tabs_Groups)
.setTabListener(new TabListener<GroupsFragment>(
this, "GroupsFragment", GroupsFragment.class));
actionBar.addTab(tab);
tab = actionBar.newTab()
.setText(R.string.tabs_Photos)
.setTabListener(new TabListener<PhotosFragment>(
this, "PhotosFragment", PhotosFragment.class));
actionBar.addTab(tab);
tab = actionBar.newTab()
.setText(R.string.tabs_Videos)
.setTabListener(new TabListener<VideosFragment>(
this, "VideosFragment", VideosFragment.class));
actionBar.addTab(tab);
}
Android manidest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ctwalkapp.ctwalk" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name">
<activity
android:name=".MainActivity"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
</activity>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name=".MainViewActivity"
android:label="#string/title_activity_main_view"
android:parentActivityName=".LoginActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".LoginActivity" />
</activity>
</application>
</manifest>
styles.xml:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:windowActionBar">true</item>
</style>
<style name= "MyCustomTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#3f51b5</item>
</style>
</resources>

Related

Android Actionbar icons appearing to be blurred

My Actionbar icons are appearing to be blurred in the emulator as well as ma phone.
I have tried to increase the dimensions of the icons,the size of icons is increasing but its again showing the same blurred icons.
I have also tried to add the in manifest still thr is no effect.
I also tried to change my min sdk to 14 but still thr is no change in the icons.
Please help i am stucked in this from last one month..
MainActivity
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
openBottomSheet();
return true;
}
else if(id==R.id.action_stories_settings){
Settings();
}
return super.onOptionsItemSelected(item);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.appsfreax.humansofindia.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.appsfreax.humansofindia.permission.C2D_MESSAGE" />
<supports-screens
android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:xlargeScreens="true" />
<application
android:name=".app.ParseApplication"
android:largeHeap="true"
android:allowBackup="true"
android:icon="#drawable/humans_india_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".activity.MainActivity"
android:label="#string/app_name"
android:clearTaskOnLaunch="true"
android:theme="#style/CustomActionBarTheme"
>
</activity>
<activity
android:name=".activity.Submit_story"
android:label="#string/title_activity_sumit_story" >
</activity>
<activity
android:name=".activity.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".activity.All_stories"
android:label="#string/app_name" >
</activity>
<activity
android:name=".activity.Errorview"
android:label="#string/app_name" >
</activity>
<service android:name="com.parse.PushService" />
<receiver
android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<!--
IMPORTANT: If you change the package name of this sample app,
change "com.parse.tutorials.pushnotifications" in the lines
below to match the new package name.
-->
<category android:name="com.appsfreax.humansofindia" />
</intent-filter>
</receiver>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.appsfreax.humansofindia"
minSdkVersion 13
targetSdkVersion 20
versionCode 102
versionName "1.0.2"
}
Menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="#+id/action_settings"
android:icon="#drawable/t"
android:orderInCategory="100"
android:title="Botttom menu"
app:showAsAction="always"
/>
<item
android:id="#+id/action_stories_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings_icon"
android:orderInCategory="200"
app:showAsAction="always" />
Blurred Image
https://drive.google.com/file/d/0B_2xbmgzcrhmcHk2QnR4V3lsWWs/view?usp=sharing
It seems problem with the icon size you're using. I believe you're using small icon which is being stretched and looks blurry.
Try using atleast 70px*70px png canvas with 48x48 icon inside (IMO). Refer the image below.
if you want bigger/lesser icon size you can change the icon size accordingly.
hope this helps :)

Google Map showing Blank Screen

I am currently developing an android app that needs google maps. All of the instructions and procedures are done and working perfectly but when I run it now it displays only blankscreen and zoom.
This is my main activity.java:
package com.example.lrt;
import com.google.android.gms.maps.SupportMapFragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class Googlemapko extends FragmentActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.googlemapko);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction().add(android.R.id.content, fragment).commit();
}
}
This is my Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.lrt.Googlemapko" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/button1"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
MY Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lrt"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<permission android:name="com.example.lrt.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission android:name="com.example.lrt.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyB61vojABlTFrB9QTv9kXWKXPknI0iot_o" />
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.example.lrt.Googlemapko"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Do you try to run signed app or not?
If not, you just will not be able to connect to maps api, so it will show you blank fragnent.

Google Glass: Card not being displayed

Need help to display a sample card in the glass timeline(refer image). All i need is to launch the card when one taps when "ok glass" is displayed and scroll to view the card(image 2), the same via voice command also does not work.
I tried launching the same activity via adb shell it works perfectly fine, also i added an intent filter with MAIN/LAUNCHER category to the activity - it runs. I referred this link for this POC but nothing like the image is being displayed. Please help as to where am i going wrong - TIA
Activity:
package de.androidzeitgeist.glass.helloworld.immersion;
import android.app.Activity;
import android.os.Bundle;
import com.google.android.glass.app.Card;
public class HelloWorldActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Card card = new Card(this);
card.setText("Hello world!");
card.setFootnote("android.com");
setContentView(cardroid.getView());
}
}
Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.androidzeitgeist.glass.helloworld.immersion"
android:versionCode="1"
android:versionName="1.0" >
<application
android:allowBackup="true"
android:icon="#drawable/helloworld_icon"
android:label="#string/app_name" >
<activity
android:name="de.androidzeitgeist.glass.helloworld.immersion.HelloWorldActivity"
android:icon="#drawable/helloworld_icon"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger" />
</activity>
</application>
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
</manifest>
voice_trigger.xml
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="#string/show_hello_word" />
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">HelloWorldImmersion</string>
<string name="hello_world"></string>
<string name="show_hello_word">show hello world</string>
</resources>
If you are using an unregistered voice command, your manifest.xml must include
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
See https://developers.google.com/glass/develop/gdk/starting-glassware for more details about using registered commands and unlisted commands and Why is my voice command missing from the ok glass menu in XE16? for some clarification and examples.

Selectively setting voice input constraints on submenu items

As I found on a Glass Developers page, it is possible to set voice constraints to disable your voice trigger if certain features are unavailable. I thought this would work for the disambiguation submenu as well, so I tried putting a constraint on one Activity in the submenu but not the others. Instead of just disabling that one submenu item ("Choose from list"), however, this disabled the entire menu ("Make a request"). Here's my manifest and voice trigger xml resources:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.twintitanium.glassapps.decisionmaker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<service
android:name="com.twintitanium.glassapps.decisionmaker.DecisionMakerService"
android:enabled="true"
android:exported="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
</service>
<activity
android:name="com.twintitanium.glassapps.decisionmaker.MenuActivity"
android:enabled="true"
android:theme="#style/MenuTheme" >
</activity>
<activity
android:name="com.twintitanium.glassapps.decisionmaker.ChooseFromListActivity"
android:label="#string/choice_from_list"
android:icon="#drawable/ic_choose_from_list" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/make_a_request_with_network_constraint_trigger" />
</activity>
<activity
android:name="com.twintitanium.glassapps.decisionmaker.RollDieActivity"
android:label="#string/die_roll"
android:icon="#drawable/ic_roll_die" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/make_a_request_trigger" />
</activity>
<activity
android:name="com.twintitanium.glassapps.decisionmaker.FlipCoinActivity"
android:label="#string/coin_flip"
android:icon="#drawable/ic_flip_coin" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/make_a_request_trigger" />
</activity>
<activity
android:name="com.twintitanium.glassapps.decisionmaker.YesNoActivity"
android:label="#string/yes_or_no"
android:icon="#drawable/ic_yes_no" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/make_a_request_trigger" />
</activity>
</application>
</manifest>
As you can see, I use make_a_request_with_network_constraint_trigger for ChooseFromListActivity but make_a_request_trigger for the other Activities.
make_a_request_with_network_constraint_trigger.xml:
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="#string/glass_voice_trigger">
<constraints
network="true" />
</trigger>
make_a_request_trigger.xml:
<?xml version="1.0" encoding="utf-8"?>
<trigger keyword="#string/glass_voice_trigger" />
(Just to clarify, "#string/glass_voice_trigger" is "Make a request".)
Is there a reason that the network constraint given to one Activity disables the entire menu, even though the other Activities don't have the same constraint? Is there another way to selectively constrain one Activity and not the others?
This doesn't sound like the desired behavior. Can you please file a bug on our issue tracker so we can investigate further?

GDK: Give Hint in Voice Prompt

Is it possible to give the user "hints" using voice trigger's input prompt? This is would be similar to what the action "make a call" displays, giving you a list of possible options.
For instance using the following...
<trigger keyword="#string/start_scan" >
<constraints
camera="true"
network="true" />
<input prompt="#string/prompt_scan_what" />
</trigger>
I would like the user flow to be as follows...
------------
"Ok, Glass"
------------
"Scan"
------------
What would you like to scan?
QR Code
Product
Barcode
------------
"Barcode"
Found a workaround with a few cons:
Bloats AndroidManifest depending on number of options.
Different method of getting selected option.
Can't be done programmatically.
Workflow is more like...
---------
"Ok, Glass"
---------
"Scan"
---------
ok glass, scan...
QR Code
Product
Barcode
---------
"Barcode"
Android Manifest:
<activity android:name="com.cantilsoftware.barcodeeye.LaunchActivity">
</activity>
<activity-alias
android:name="Product"
android:label="Product"
android:targetActivity="com.cantilsoftware.barcodeeye.LaunchActivity" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger_scan" />
</activity-alias>
<activity-alias
android:name="Barcode"
android:label="Barcode"
android:targetActivity="com.cantilsoftware.barcodeeye.LaunchActivity" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger_scan" />
</activity-alias>
<activity-alias
android:name="QR Code"
android:label="QR Code"
android:targetActivity="com.cantilsoftware.barcodeeye.LaunchActivity" >
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="#xml/voice_trigger_scan" />
</activity-alias>
Selection detection:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
try {
ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(), 0);
processVoiceAction(activityInfo.loadLabel(getPackageManager()).toString());
} catch (NameNotFoundException e) {
e.printStackTrace();
processVoiceAction(null);
}
}
Have you tried adding a line feed character (i.e. '/n') after the question mark in the prompt text to get a fresh new line?