20 Simple Content Provider Example

 
 
 
AndroidManifest.xml 
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.aslam.contentproviderexample2" >
<uses-permission android:name="android.permission.READ_CONTACTS" />
    <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:roundIcon="@mipmap/ic_launcher_round" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme" >
    <activity android:name=".MainActivity" >
      <intent-filter>
         <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
   </activity>
    </application>

</manifest>
 
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
   xmlns:android="http://schemas.android.com/apk/res/android" 
   xmlns:tools="http://schemas.android.com/tools" 
   xmlns:app="http://schemas.android.com/apk/res-auto" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   tools:context=".MainActivity">

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Hello World!" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" />

<ListView        
   android:id="@+id/list_view" 
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content"/>

</android.support.constraint.ConstraintLayout>
 
MainActivity.java 
import android.Manifest;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ListView listView;
    ArrayList al=new ArrayList();
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.READ_CONTACTS},1);
        listView=(ListView)findViewById(R.id.list_view);

        Cursor cursor=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);

         while (cursor.moveToNext()){
             String name= cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
            al.add(name);
         }
         listView.setAdapter(new ArrayAdapter(MainActivity.this,android.R.layout.simple_list_item_1,al));
    }
}
 

Comments

  1. Thanks for sharing the useful blog about the Example Programs for Content Provider.

    Android App development Company in Coimbatore

    ReplyDelete
  2. Hey Nice Blog!!! Thank you for sharing information. Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!

    Android Mobile App Developement Company
    Graphic and Logo Designing Services
    Best Web Hosting Provider Company in India

    ReplyDelete
  3. Thanks for your post. This is excellent information. It is amazing and wonderful to visit his site. digiorbite.com

    ReplyDelete
  4. (Thanks for this blogspot)
    High class infrastructure ensures that our Android developers have ample of scope to show their creativity and deliver highly effective Android apps that can win more business for your organization. Elsner is a Leading Android App Development Company in the USA.

    ReplyDelete
  5. We are Ahmedabad based website Development and website Design Company. As a leading website development company, we have extensive website design and website development skills blended with the quality spirit of expertise must have element to help you establish your Internet presence or take it to the next level.

    ReplyDelete
  6. And I appreciate your work, I'm a great blogger.
    This article bothered me a lot.
    I will bookmark your site and continue searching for new information.
    crystaldiskinfo crack
    wysiwyg web builder crack
    anytrans crack
    poweriso crack

    ReplyDelete
  7. Your website has a great design. Colors and themes that pop!
    Is this a work of your own? Please respond again since I want to construct one of my own.
    and I'd want to know where you've came from on this site
    The item's name is derived from this location.
    Sincerely,
    tweakbit fixmypc crack
    sandboxie crack
    advanced video compressor crack
    norton security crack

    ReplyDelete
  8. Let me introduce myself. I suspect that your website is having issues with browser compatibility.
    Displays your site without any issues, however Internet Explorer has some overlapping issues.
    As a matter of fact, I just wanted to let you know what was going on. However, except from that, this is an excellent blog!
    minitab crack
    coreldraw graphics suite 12 crack
    minitab crack

    ReplyDelete
  9. Thanks for writing this excellent article for us.
    I have gained good stuff from this website. I am looking forward to your next article.
    Not only that, but I am happy to share this post with my friends. Keep it up.

    teracopy pro crack
    teracopy pro crack
    teracopy pro crack
    teracopy pro crack
    teracopy pro crack
    teracopy pro crack
    teracopy pro crack

    ReplyDelete
  10. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.
    fuel crack
    Red Dead Redemption 2 Crack
    heavy rain crack
    Far Cry 5 Crack

    ReplyDelete
  11. Oh my goodness! Impressive article dude! Thanks, However I am having troubles with your RSS. I don’t understand the reason why I am unable to join it. Is there anybody having the same RSS issues? Anyone that knows the answer will you kindly respond? Thanx!!
    avast premier crack
    last day on earth survival apk
    idm build crack
    keyshot pro crack
    surviving mars green planet crack
    ccleaner professional crack
    euro truck driver apk cracked mod

    ReplyDelete
  12. I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me. this blog has detailed information, its much more to learn from your blog post.I would like to thank you for the effort you put into writing this page.
    I also hope that you will be able to check the same high-quality content later.Good work with the hard work you have done I appreciate your work thanks for sharing it. It Is very Wounder Full Post.This article is very helpful, I wondered about this amazing article.. This is very informative.
    “you are doing a great job, and give us up to dated information”.
    1click dvd copy pro crack
    magix sound forge pro suite crack
    adobe media encoder crack
    tenorshare 4ukey for android crack
    ram saver professional crack

    ReplyDelete
  13. Hello, I Am Mari. Nice Content. Thanks for presenting this enlightening article!! I appreciate your hard work behind this great article. Realizzer 3D

    ReplyDelete

Post a Comment

Popular posts from this blog

14 Popup Menu

17 Simple Notification Program