Basic Kaa mobile application with android sdk - kaa

Trying to connect to Kaa Server with Android SDK :
Added downloaded android sdk jar as library in application.
Code
public class MainActivity extends AppCompatActivity {
private Context mContext;
private KaaClient mClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = getApplicationContext();
mClient = Kaa.newClient(new AndroidKaaPlatformContext(mContext), new SimpleKaaClientStateListener(){
#Override
public void onStarted(){
Toast.makeText(mContext, "Success", Toast.LENGTH_LONG).show();
}
#Override
public void onStartFailure(KaaException exception){
Toast.makeText(mContext, "Failure", Toast.LENGTH_LONG).show();
}
},true);
mClient.start();
}
}
But not getting Success message.
Is there any tutorial out there to follow for Android SDK ?
Regards,
Hiten

You have to generate SDK right base on your application and choose Target Platform is Android.
And you can recheck way to add library in android studio.

This query is solved now. It's working as expected.

Related

Android flash image

I try to flash an image view for 3 seconds and then return it to its original image. here is my code:
public class MainActivity extends AppCompatActivity
implements View.OnClickListener{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.imageView).setOnClickListener(this);
}
#Override
public void onClick(View v) {
ImageView pic = findViewById(R.id.imageView);
pic.setImageDrawable(getResources().getDrawable(R.drawable.devil));
//Wait Block
try
{
Thread.sleep(3000);
} catch (InterruptedException e){
Toast.makeText(this,"Problem occurred",Toast.LENGTH_LONG).show();
}
//End of wait block
pic.setImageResource(R.drawable.angel);
Toast.makeText(this,"Done",Toast.LENGTH_LONG).show();
}
So basically I want this code flow:
While the actual flow is the following :
Could you tell me the reason for this behavior as well as how to solve this?

Using FirebaseUI for firebase recyclerView in android

i am a new comer in android development and facing some problems using firebase ui.
i wanted to retrieve data from my firebase database and show it on my recyclerView.
but i am constantly getting an error while making FirebaseRecyclerAdapter.
Here is My Code Sample:
public class UsersActivity extends AppCompatActivity {
private Toolbar userToolbar;
private RecyclerView usersList;
private DatabaseReference mUsersDatabase;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_users);
userToolbar = (Toolbar) findViewById(R.id.users_toolbar);
setSupportActionBar(userToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Users");
mUsersDatabase = FirebaseDatabase.getInstance().getReference().child("Users");
usersList = (RecyclerView) findViewById(R.id.users_list);
usersList.setHasFixedSize(true);
usersList.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Users, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.single_user_list_layout,
UsersViewHolder.class,
mUsersDatabase
) {
#Override
protected void onBindViewHolder(#NonNull UsersViewHolder holder, int position, #NonNull Users model) {
holder.setName(model.getName());
}
#NonNull
#Override
public UsersViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return null;
}
};
usersList.setAdapter(firebaseRecyclerAdapter);
}
public static class UsersViewHolder extends RecyclerView.ViewHolder
{
View mView;
public UsersViewHolder(#NonNull View itemView) {
super(itemView);
mView = itemView;
}
public void setName(String name)
{
TextView userNameView = (TextView) mView.findViewById(R.id.single_user_name);
userNameView.setText(name);
}
}
}
The Error i'm getting is this:
please help!!
Sorry wanted to comment but i ain't got enough points to do so.
Try this first, if it doesnt work try using FirebaseRecyclerOptions
(The latest version (3.x) of FirebaseUI implements a different method ofinitializing a FirebaseRecyclerAdapter than previous versions.)
Make your " firebaseRecyclerAdapter " variable global, so you would have something like this.
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(
Users.class,
R.layout.single_user_list_layout,
UsersViewHolder.class,
mUsersDatabase
)

Splash screen prism xamarin.forms

I would like to create a splash screen in my xamarin.forms application which is using the prism.autofac.forms nuget package. Basically I want to create the same splash screen for each platform. Currently my Android application looks like this
[Activity(Label = "MyApp", Theme = "#style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
ToolbarResource = Resource.Layout.Toolbar;
TabLayoutResource = Resource.Layout.Tabbar;
base.OnCreate(bundle);
Forms.Init(this, bundle);
LoadApplication(new Application(new DroidInitializer()));
}
}
and the application looks like this:
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Application : PrismApplication
{
public Application(IPlatformInitializer initializer) : base(initializer)
{
NavigationService.NavigateHomeAsync();
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>("Navigation");
containerRegistry.RegisterForNavigation<MainPage>("Index");
containerRegistry.RegisterForNavigation<HomePage>();
}
protected override void OnInitialized()
{
InitializeComponent();
}
}
Where should I implement and show the splash screen? I want to NavigateHome when all registering are finished.
Splash screens should be implemented in the platform projects.
For iOS the recommended solution is to use a storyboard for it, https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/launch-screens?tabs=vsmac
For Android I use to create a theme for the splash screen, https://learn.microsoft.com/en-us/xamarin/android/user-interface/splash-screen
You can make them look the same, but you have to do it on each platform.

error on handler.postDelayed (new Runnable () {

I am a novice programmer on android studio, I want to know why does the
delay function does an error on handler.postDelayed (new Runnable(){ do I have to import any library? and what is the shortcut key for :#override..." whenever I does a code. thanks.
heres the code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Handler handler = new Handler();
handler.postDelayed (new Runnable(){
#.
public void run() {
msg();
}
},500);
}
sry i write it as an answer cause i cant post comments yet but can you post the exact error?
i'm pretty sure you should write
public class MainActivity extends AppCompatActivity {
like this :
public class MainActivity extends AppCompatActivity implements runnable {
but thats just an educated guess since I dont know whats the exact error you are getting.

How to play video through FragmentTabHost in android

I made an application that has 4 tabs:
vedio tab, in this tab I want to play video, taking remote url
virtual lab
edit video
help
I have made MainActivity class in which use FragmentTabHost class id for display tab.
public class MainActivity extends FragmentActivity{
private FragmentTabHost mTabHost;
private FragmentTabHost mTabHostabove;
#Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("Vedio").setIndicator("Vedio",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Virtual Lab").setIndicator("Virtual Lab"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Edit Vedio").setIndicator("Edit Vedio"),FragmentTab.class,null);
mTabHost.addTab(mTabHost.newTabSpec("Help").setIndicator("Help1"),FragmentTab.class,null);
mTabHostabove = (FragmentTabHost)findViewById(R.id.tabhostabove);
mTabHostabove.setup(this, getSupportFragmentManager(), R.id.tabcontent);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Logo").setIndicator("Logo"),FragmentTab.class,null);
mTabHostabove.addTab(mTabHostabove.newTabSpec("Vedio Url ").setIndicator("Vedio Url",getResources().getDrawable(R.drawable.ic_launcher)),FragmentTab.class,null);
}
}
I have also made FragmentTab class which extends Fragment.
here is code:
public class FragmentTab extends Fragment {
private TextView tv;
private VideoView mVideoView;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_layout, container, false);
tv = (TextView) v.findViewById(R.id.text);
mVideoView = (VideoView)v.findViewById(R.id.vedioview);
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
String path1="http://commonsware.com/misc/test2.3gp";
MediaController mc = new MediaController(getActivity());
mc.setAnchorView(mVideoView);
mc.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mc);
mVideoView.requestFocus();
// mVideoView.setVideoURI(Uri.parse("android.resource://" +getActivity().getApplicationContext().getPackageName() +"/"+R.raw.song));
mVideoView.setVideoURI(Uri.parse(path1));
mc.show();
mVideoView.start();
} catch (Exception e) {
}
}
});
String tag = this.getTag();
if (tag == "Vedio") {
tv.setText("play vedio");
}
if (tag == "Edit Vedio") {
tv.setText("want to Edit Vedio !!!!!!!");
}
if (tag == "Help") {
tv.setText("do u want help !!!!!!!");
}
if (tag == "Virtual Lab") {
tv.setText("Enter Virtual lab !!!!!!!");
}
return v;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
I am stuck with to play vedio on click vedio tab
anybody solve it if u can . I have searched for 3 days, but i have not found a solution. vedio sound is coming, but vedio is not playing.
Not all devices support all video codecs.
I had the same problem: I work with mp4-format and a resolution of 1280x720. This video format wasn't support by all devices (e.g. HTC Wildfire S). After changing the resolution to 480x360 the video was shown by all devices.
This link should help you:
http://developer.android.com/guide/appendix/media-formats.html

Resources