mercredi 30 décembre 2015

java.lang.IllegalArgumentException: URI: content://com.android.contacts, calling user:

I have created contact change observer, when a user any time change their contact need to know what change they did.

Step 1 :

public class ContactChangeObserver extends ContentObserver {

Context mContext;

public ContactChangeObserver(Handler handler, Context ctx) {
    super(handler);
    mContext = ctx;
}

@Override
public boolean deliverSelfNotifications() {
    return super.deliverSelfNotifications();
}

@Override
public void onChange(boolean selfChange) {
    super.onChange(selfChange);
    Log.e("Content Change", "Added New onChange selfChange");
}

@Override
public void onChange(boolean selfChange, Uri uri) {
    Log.e("NoOf Content Change", "Contant Change Happen");
    super.onChange(selfChange, uri);
    if(mContext != null) {
        Log.e("Content Change Name :", "start checking");
        AppPreferences appPreferences = new AppPreferences(mContext);
        String[] projection = {
                ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                ContactsContract.CommonDataKinds.Phone.NUMBER
        };

        Cursor cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
        if (cursor.moveToFirst()) {
            String sender = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            String mobileno = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
            String status = "phone";
            MaraContactsManager.getInstance().updateContactDB(mContext, mobileno, sender, status, appPreferences.getCountryCode());
        }
    }
}

Step 2: have register this by calling at HomeActivity

contactChangeObserver =  new ContactChangeObserver(new Handler(),getApplicationContext());
    getApplicationContext().getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactChangeObserver);

Step 3: when i change any contact it goes to onChange Methode but I am not getting which contact changes done it says

java.lang.IllegalArgumentException: URI: content://com.android.contacts, calling user: 

Please Help

Create database in External Storage

I know already how create Sqlite database. The point is the database file is created only in Internal Storage (/data/{package name})

Is there a way to directly create Sqlite database right on External Storage?

Exporting a SQlite database (*.db3) to pdf format using javascript

I have a firmware file which is transferring a SQLite data base file (*.db3) to my java script .

Now using the Javascript I want to export the data in the SQLite data base file to a pdf format. Is this possible ?

Getting more info form python sqlite exceptions

I'm using python's builtin sqlite3 DB API.

While inserting objects to my DB tables, following sqlite exception raised:

"PRIMARY KEY must be unique"

Exception got caught in main() by except Exception as e:, so it's only info I've got.

I would want to know in which table insertion failed, value that failed, etc...

What's the right way to get the most info from sqlite exceptions?

Thanks

FragmentPagerAdapter method, getItem() mistake

this is my situation: I want to show a few fragments. In my case, I have a sqlite database with a some students, the fields are: _id, Name, Lastname, sex, photoSize, field1, field2, field3, field4. For example, if field1 == 1 i have to show the fragment 1, if field2 == 2 i have to show the fragment 2 and so. I don't know what i am doing wrong. Here is the code.

public class SectionsPagerAdapter extends FragmentPagerAdapter {

        Bundle b = getIntent().getExtras();
        int i = 2;
        Cursor c;
        Cursor c2;

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            String id = b.getString("id");
            c2 = dbm.buscarAlumno(id);
            if (c.moveToFirst()) {

                switch (position) {
                    case 0:
                        if (c2.getString(5).equals("1")) {
                            return PlaceholderFragment.newInstance(position);
                        } else {
                            break;
                        }
                    case 1:
                        if (c2.getString(6).equals("1")) {
                            return PlaceholderFragment.newInstance(position);
                        } else {
                            break;
                        }
                    case 2:
                        if (c2.getString(7).equals("1")) {
                            return PlaceholderFragment.newInstance(position);
                        } else {
                            break;
                        }
                    case 3:
                        if (c2.getString(8).equals("1")) {
                            return PlaceholderFragment.newInstance(position);
                        } else {
                            break;
                        }
                    case 4:
                        return PlaceholderFragment.newInstance(position);
                }
            }
            return null;
        }

        @Override
        public int getCount() {
            // Show 1 total pages.
            return 5;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            String id = b.getString("id");
            c = dbm.buscarAlumno(id);
            if (c.moveToFirst()) {
                switch (position) {
                    case 0:
                        if (c.getString(5).equals("1")){
                            return "PISTA";
                        }
                    case 1:
                        if (c.getString(6).equals("1")){
                            return "ESTABLO";
                        }else{break;}
                    case 2:
                        if (c.getString(7).equals("1")){
                            return "EMOCIONES";
                        }else{break;}
                    case 3:
                        if (c.getString(8).equals("1")){
                            return "NECESIDADES";
                        }else{break;}
                    case 4:
                        return b.getString("alumno");
                }
            }return null;
        }
    }

The dbm variable is declare in the container class, means DataBaseManager, and buscarAlumno(id) is the method that returns the student, and swear that this method works perfect. Here is the logcat:

12-30 07:43:14.419 3104-3104/? W/EGL_emulation: eglSurfaceAttrib not implemented
12-30 07:43:14.429 3104-3104/? D/OpenGLRenderer: Enabling debug mode 0
12-30 07:43:17.849 1340-1354/? W/Binder: Caught a RuntimeException from the binder stub implementation.
                                         java.lang.NullPointerException
                                             at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)
                                             at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129)
                                             at android.os.Binder.execTransact(Binder.java:404)
                                             at dalvik.system.NativeStart.run(Native Method)
12-30 07:43:17.849 1253-1353/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 3076 uid 10057

If i don't use the database works perfectly.

Please help! Thanks folks!

DataAdapter.Fill is slower in SQLite than SQLServer

I trying to load about 100k rows from SQLite database into a datatable. Fill method requires about 2 seconds for entire operation. I noticed that doing the same operation with SQLServer 2014 database, it requires only 0,7 secs! This is my code:

SQLiteDataAdapter adpt= new SQLiteDataAdapter("SELECT * FROM myTable", sqliteCn);
DataTable dt = new DataTable();
adpt.Fill(dt);

The table has 9 columns, 1 primary key and 1 unique index. Does SQLite is truly slower than SQL Server? If no, there are some specific operations to speed up this query?

How to setup SQLite with eclipse for the very first time?

I am trying to setup SQLite with eclipse using the documentation:

http://ift.tt/1tL95YH

But when I am trying to add new "Generic JDBC" driver, the fields are disabled.

enter image description here

I don't know how to proceed.