-
-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated: AutoInitLibrary example by implementing content provider and…
… setting it up so that the library is init on app start
- Loading branch information
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="github.nisrulz.sample.awesomelib" /> | ||
package="github.nisrulz.sample.awesomelib"> | ||
|
||
<application> | ||
<provider | ||
android:name=".AwesomeLibInitProvider" | ||
android:authorities="${applicationId}.awesomelibinitprovider" | ||
android:enabled="true" | ||
android:exported="false"></provider> | ||
</application> | ||
|
||
</manifest> |
70 changes: 70 additions & 0 deletions
70
...ary/awesomelib/src/main/java/github/nisrulz/sample/awesomelib/AwesomeLibInitProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package github.nisrulz.sample.awesomelib; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.content.pm.ProviderInfo; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
|
||
public class AwesomeLibInitProvider extends ContentProvider { | ||
|
||
public AwesomeLibInitProvider() { | ||
} | ||
|
||
@Override | ||
public void attachInfo(Context context, ProviderInfo providerInfo) { | ||
if (providerInfo == null) { | ||
throw new NullPointerException("YourLibraryInitProvider ProviderInfo cannot be null."); | ||
} | ||
// So if the authorities equal the library internal ones, the developer forgot to set his applicationId | ||
String libAuthorityString = "github.nisrulz.sample.awesomelib.awesomelibinitprovider"; | ||
if (libAuthorityString.equals(providerInfo.authority)) { | ||
throw new IllegalStateException("Incorrect provider authority[" + libAuthorityString + "]" + | ||
" in manifest. " + | ||
"Most likely due to a " | ||
+ "missing applicationId variable in application\'s build.gradle."); | ||
} | ||
super.attachInfo(context, providerInfo); | ||
} | ||
|
||
@Override | ||
public boolean onCreate() { | ||
|
||
// get the context (Application context) | ||
Context context = getContext(); | ||
// initialize AwesomeLib here | ||
AwesomeLib.getInstance().init(context); | ||
|
||
return false; | ||
} | ||
|
||
|
||
@Override | ||
public String getType(Uri uri) { | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public Cursor query(Uri uri, String[] projection, String selection, | ||
String[] selectionArgs, String sortOrder) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Uri insert(Uri uri, ContentValues values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int update(Uri uri, ContentValues values, String selection, | ||
String[] selectionArgs) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int delete(Uri uri, String selection, String[] selectionArgs) { | ||
return 0; | ||
} | ||
} |