how to write custom platform-specific code in flutter - android

For printing in printer purpose, I am using native code for Android in the android folder of flutter app. So I wanna create MethodChannel but in android activity, all these imports are not found. (showing error)
import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.BasicMessageChannel
import io.flutter.plugin.common.StringCodec
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.MethodChannel

It is happening to me as well and I am still wondering why...
To solve it I open the project from the root, so not only the android libs are loaded but also dart and flutter libs:
I try adding the libs into graddle conf, but still not working... I hope this is useful for you

Related

Import statements are showing erros in flutter project, but working fine in an individual project

I am getting the errors (related to android import statement)like below in flutter project. but if I open the same android project separately in the android studio it was not showing any errors(import statements not showing any errors). Any fixes??
Flutter Activity import statement is not impcolouredproperly means showing with red colored import statement saying that unused import statement
you can try clean project in build menu.

Spotify Android SDK - Cant import player library

I am trying to integrate spotify with my android application. I am using their Android SDK with Android Studio. I followed the tutorial on their official developer guide. I can import and use the authentication api (import com.spotify.sdk.android.authentication;) but cant import the player api (import com.spotify.sdk.android.player;)
Anybody faced this problem or any leads?
EDIT:
I added these dependencies in build.gradle file:
// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta10#aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta10#aar'
Now I tried to try out the demo code mentioned in the link above. But I am getting error in these imports.
import com.spotify.sdk.android.player.Spotify;
import com.spotify.sdk.android.player.ConnectionStateCallback;
import com.spotify.sdk.android.player.Player;
import com.spotify.sdk.android.player.PlayerNotificationCallback;
import com.spotify.sdk.android.player.PlayerState;
However I can import the authentication related imports.
import com.spotify.sdk.android.authentication.*;
Either the player library is not getting imported properly or the import definitions have changed in 'com.spotify.sdk:spotify-player:1.0.0-beta10#aar' version, since the demo code that has been given is for 'com.spotify.sdk:spotify-player:1.0.0-beta9#aar' version.

ZXing imports disappearing

I am trying to install zxing in android studio but i am running into some trouble. I have looked around at lots of different posts and tutorials and they have all said to just add the following lines into the build.gradle dependencies
compile 'com.google.zxing:core:3.1.0'
compile 'com.google.zxing:android-integration:3.1.0'
I have done this and synced everything but when I try and add an import like
import com.google.zxing.integration.android.IntentResult;
at the top of my project it instantly disappears without an errors or warning.
Has anyone else had this problem or know what I am doing wrong?
Your IDE will remove the import if you have some auto-cleaning unused import statements. It depends on the IDE to configure this option but both Android Studio and Eclipse have this feature.
I suggest you to start using this IntentResult and then it will keep the import statement.

How can I import com.android.internal.telephony?

I downloaded an Android Project and got some errors.
How can I use this imports in Android?
import com.android.internal.telephony.IccSmsInterfaceManager;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.SMSDispatcher;
When I import this, I got errors like these:
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
The import com.android.internal.telephony cannot be resolved
Later in the code there are:
Phone phone = PhoneFactory.getDefaultPhone();
With the error:
Multiple markers at this line
- Phone cannot be resolved to a type
- PhoneFactory cannot be resolved
And so on...
I tried to fix it with the https://stackoverflow.com/a/16377968/3203914
but I did not work for me.
Can please someone tell me how to fix it?
Thanks!
How can I use this imports in Android?
Those are not part of the Android SDK. If you are editing the Android source code, the build process for it should resolve those imports. If you are trying to write an Android app, you cannot directly reference them. In fact, com.android suggests they are part of a separate app, not yours and not the Android framework.
CommonsWare is correct, its not in the SDK so you cannot directly reference them. You will either have to
Import all of the android source code, which will resolve these issues
Import the specific project containing this code, then set up your code as a dependency
Stop using those packages

Android SDK Fragment Support

Ok i'm just starting to get into Android programming now, and I'm following the android "TabActivity" tutorial: http://developer.android.com/reference/android/app/TabActivity.html.
Everythings working but it can't seem to find some of the support classes, see the code below that is generating the errors.
mTabManager.addTab(mTabHost.newTabSpec("simple").setIndicator("Simple"),
FragmentStackSupport.CountingFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("contacts").setIndicator("Contacts"),
LoaderCursorSupport.CursorLoaderListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("custom").setIndicator("Custom"),
LoaderCustomSupport.AppListFragment.class, null);
mTabManager.addTab(mTabHost.newTabSpec("throttle").setIndicator("Throttle"),
LoaderThrottleSupport.ThrottledLoaderListFragment.class,null);
For FragmentStackSupport/LoaderCursorSupport/LoaderCustomSupport/LoaderThrottleSupport, it says for all of them cannot be resolved to a type. I've added the latest support library to a folder in the root directory named "libs" and also coppied it into "C:/Eclipse/v4/" directory. My import files are:
import java.util.HashMap;
import android.R;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.widget.TabHost;
import cowdawg.hello_tab.namespace.R.layout;
import cowdawg.hello_tab.namespace.R.id;
Could someone please offer me some advice on how to solve this, thanks :).
It's probably because the following classes are not part of the standard Android API (or the support library), but only exist in the support demos sample code for demonstration purposes:
FragmentStackSupport.CountingFragment
LoaderCursorSupport.CursorLoaderListFragment
LoaderCustomSupport.AppListFragment
LoaderThrottleSupport.ThrottledLoaderListFragment
You will need to add these classes to your own project in order to be able to use them. Here you can find the source files under the subsection 'Files'.
FragmentStackSupport
LoaderCursorSupport
LoaderCustomSupport
LoaderThrottleSupport
On Eclipse IDE: Select your project and then right click on the project -> Android Tools -> Add Support Library.
Required support library will be added on your project build path. You will found this library jar under Java Build Path -> Libraries tab -> Android Dependencies.
Enjoy exploring!
Have you added the library to your build path? Right click on the jar in eclipse -> Build Path -> Add to Build Path.
Try adding by right clicking on the project and opening properties window
Instead of these missing classes you can create your own by subclassing Fragment class (or its subclasses like DialogFragment, ListFragment etc). More info is provided by Android here.

Categories

Resources