Hi,
This is Amazon AWS Upload and Download POC.
SourceCode Link:https://github.com/JohnnyIqbal/AmazonAWS_upload_download
This is Amazon AWS Upload and Download POC.
SourceCode Link:https://github.com/JohnnyIqbal/AmazonAWS_upload_download
cd bin/classes
and generate header files of NativeLib.java using this command javah -jni com.iqbal.ndkhello.ndk.NativeLib
3. Copy NativeLib.h file in jni folder (Create if not exist in project root) javah -jni -o ../../jni/NativeLib.h com.iqbal.ndkhello.ndk.NativeLib
Method Signature eg:
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello2
this is the declared method in header files and change to method defination #include"NativeLib.h"
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello (JNIEnv *env, jclass clz){ return (*env)->NewStringUTF(env,"Hello World2"); }
#include"src/main.h"
JNIEXPORT jint JNICALL Java_com_iqbal_ndkhello2_ndk_NativeLib_getAdd(
JNIEnv *env, jclass clz, jint a, jint b) {
int c=add(a,b); //this function declared in main.h and defiened in main.c
return c;
}
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:=hello2
LOCAL_SRC_FILES:=NativeLib.c src/main.c
include $(BUILD_SHARED_LIBRARY)
APP_PLATFORM:=android-8
android-8 is my minsdkversion so be sure about this change according to minsdkversion in AndroidManifest.xml ndk-build
SyncUtils.CreateAccount(instance, user, pass);
AccountManager am = AccountManager.get(instance);
Account[] acclist = am.getAccounts();
for (Account acc : acclist) {
if (acc.type.equals(SyncUtils.ACCOUNT_TYPE)) {
// You need pass bundle to sync
Bundle b = new Bundle();
b.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
b.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver.requestSync(acc, SyncUtils.AUTHORITY, b);
Log.i("MainActivity", "Request to sync Contacts");
}
}
5. After firing this operation onPerformSync() method called in ContactsSyncAdapterService <service
android:name="com.iqbal.contactsyncbg.sync.ContactsSyncAdapterService"
android:exported="true"
android:process=":contacts" >
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="@xml/sync_contacts" />
<meta-data
android:name="android.provider.CONTACTS_STRUCTURE"
android:resource="@xml/contacts" />
</service>
<service
android:name="com.iqbal.contactsyncbg.sync.AuthenticatorService"
android:exported="true"
android:process=":auth" >
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
</service>
7. Be sure of Account Type what you defined in sync_contacts and ContactSyncAdapter must be same. <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
cd bin/classes and
generate header files of NativeLib.java using this command javah -jni com.iqbal.ndkhello.ndk.NativeLib
javah -jni -o ../../jni/NativeLib.h com.iqbal.ndkhello.ndk.NativeLib
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello
(JNIEnv *, jclass);
#include"NativeLib.h"
JNIEXPORT jstring JNICALL Java_com_iqbal_ndkhello_ndk_NativeLib_getHello
(JNIEnv *env, jclass clz){
return (*env)->NewStringUTF(env,"Hello World");
}
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello
LOCAL_SRC_FILES := NativeLib.c
include $(BUILD_SHARED_LIBRARY)
APP_PLATFORM:=android-8
ndk-build
public class RegExTest {
public static void main(String arg[]) {
String str = "0888"; //"+91989898" "9180709709"
String regex="^([\\+](91))+([0-9]+$)|(^(0))+([0-9]+$)"; //{10} if you want to give no limit
Pattern pat = Pattern.compile(regex);
Matcher mat= pat.matcher(str);
if (mat.matches()) {
System.out.println("String matched");
} else {
System.out.println("String not matched");
}
}
}
public class ASmackAsync extends AsyncTask<String, Void, String>{
private ProgressDialog pd;
private Context ctxt;
public ASmackAsync(Context ctxt) {
this.ctxt=ctxt;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd=new ProgressDialog(ctxt);
pd.show();
pd.setContentView(new ProgressBar(ctxt), new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
}
@Override
protected String doInBackground(String... params) {
return ASmack.connectGServer(params[0], params[1]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pd.dismiss();
if(result==ASmack.GCONNECT){
Toast.makeText(ctxt, "Connected",10).show();
}else{
Toast.makeText(ctxt, result,10).show();
}
}
}
public class ASmack {
public static String GCONNECT="GCONNECTED";
public static XMPPConnection gconn;
public static String connectGServer(String user,String pass){
String host="talk.google.com";
int port=5222;
String service="gmail.com";
ConnectionConfiguration config=new ConnectionConfiguration(host,port,service);
gconn=new XMPPConnection(config);
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
config.setDebuggerEnabled(true);
try {
gconn.connect();
Log.i("Host", gconn.getHost());
gconn.login(user, pass);
} catch (XMPPException e) {
e.printStackTrace();
}
return GCONNECT;
}
}
Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...