stoped android pdf view When you restart the phone - java

I am trying to open pdf files in this code with a library barteksc
I save a link as a URI in database Then I fetch and open the link in a library barteksc
The code works fine, the problem is when I restart the phone the PDF file is not opened It appears that the error in
load pdf error
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.downloads.DownloadStorageProvider from ProcessRecord{f6420b9 6172:com.azizlabiod.librarypdfpro/u0a218} (pid=6172, uid=10218) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
code java
final int KITKAT_VALUE =1002;
Intent intent;
intent = new Intent();
if (Build.VERSION.SDK_INT < 19){
intent.setAction(Intent.ACTION_GET_CONTENT);
} else {
intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
}
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION );
intent.setType("application/pdf");
try {
startActivityForResult(intent, KITKAT_VALUE);
} catch (ActivityNotFoundException e) {
//alert user that file manager not working
Toast.makeText(getApplicationContext(), R.string.toast_pick_file_error, Toast.LENGTH_SHORT).show();
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
if (requestCode == 1002
&& resultCode == Activity.RESULT_OK) {
Uri uri ;
if (resultData != null) {
uri=resultData.getData();
String name= getFileName(uri);
db.insertRowAdmins(name,uri.toString(),R.drawable.book,23, db.getNameTableId().get(positionTab));
setNotify();
}
}
}
code manifest
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.LibraryPDFPro"
android:requestLegacyExternalStorage="true"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShowBook"
android:exported="false" />
<activity
android:name=".ShowDiatel"
android:exported="false" />
</application>
</manifest>
probleme
/PDFView: load pdf error
java.lang.SecurityException: Permission Denial: opening provider com.android.providers.downloads.DownloadStorageProvider from ProcessRecord{f6420b9 6172:com.azizlabiod.librarypdfpro/u0a218} (pid=6172, uid=10218) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3776)
at android.app.ActivityThread.acquireProvider(ActivityThread.java:5034)
at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2044)
at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1517)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1121)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:958)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:811)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:765)
at com.github.barteksc.pdfviewer.source.UriSource.createDocument(UriSource.java:37)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:53)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:27)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Remove:
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
And, in your onActivityResult(), if the request was for ACTION_OPEN_DOCUMENT, call takePersistableUriPermissions() on a ContentResolver. That's how you get durable access to the content, and without that you lose access after a short while.

Related

AutoUpdate app in Android 9 throws error while parsing

I am trying to update my app from outside Google Play, but I have an error, I have looked at everything and I cannot find a solution.
With the following 3 methods I hope to do the AutoUpdate:
private final String FILE_NAME = "app-release.apk";
public void checkStoragePermission(){
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 123);
} else {
updateApp();}
}
private void updateApp() {
Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", new File(this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + FILE_NAME));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);
}
#Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case 123: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
updateApp();
} else {
checkStoragePermission();
}
return;
}
}
}
My Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.jose.updateinapp">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<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>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
</manifest>
And the .xml for FileProvider
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="files_root"
path="Android/data/${applicationId}" />
<external-path
name="external_files"
path="." />
</paths>
The app that i'm attempting to install is the same but with versionCode 2 and versionName 2.0 instead of versionCode 1 and versionName 2.0
When executed this throws an error on the device: error parsing the package
Nothing comes out in the run console. And in the logcat the following errors appear:
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri
content://com.jose.updateinapp.provider/external_files/Android/data/com.jose.updateinapp/files/Download/app-release.apk
from pid=16603, uid=10035 requires the provider be exported, or
grantUriPermission()
Error staging apk from content URI
java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider uri
content://com.jose.updateinapp.provider/external_files/Android/data/com.jose.updateinapp/files/Download/app-release.apk
from pid=16603, uid=10035 requires the provider be exported, or
grantUriPermission()
Any solution? Thank you!
Sorry,something missed in my head.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="external"
path="" />
<external-files-path
name="Download"
path="" />
</paths>
uri = FileProvider.getUriForFile(context,
"packgeName.provider",
new File(context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "xxx.apk"));
intentInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
just try it. it worked in my project..
private void updateApp() {
Uri uri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", new File(this.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString() + "/" + FILE_NAME));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
//setFlags change addFlags
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
startActivity(intent);
}

Proper way to start activity that uses camera

I've found some opensource document scanner app, first (default) "DocumentScannerActivity" of this app is a camera for capturing images of documents for further processing. Works good, without any error.
Then I've add my own (new) "MainActivity" as default with button inside, with onclick listener that opens "DocumentScannerActivity":
scanActivityBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DocumentScannerActivity.class);
startActivity(intent);
}
});
This code opens "DocumentScannerActivity", but after pressing on "Capture image" application crashes with error:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
at az.deep.archiverabitabank.DocumentScannerActivity.saveDocument(DocumentScannerActivity.java:1042)
at az.deep.archiverabitabank.DocumentScannerActivity.saveDocument(DocumentScannerActivity.java:1129)
at az.deep.archiverabitabank.ImageProcessor.processPicture(ImageProcessor.java:161)
at az.deep.archiverabitabank.ImageProcessor.handleMessage(ImageProcessor.java:91)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:172)
at android.os.HandlerThread.run(HandlerThread.java:65)
Here is the problematic part of code (app tries to save captured image to storage) in DocumentScannerActivity:
Uri fileUri = null;
if (intent.getAction().equals("android.media.action.IMAGE_CAPTURE")) {
fileUri = ((Uri) intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT));
Log.d(TAG, "intent uri: " + fileUri.toString()); //LINE 1042, where error occurs
try {
fileName = File.createTempFile("onsFile", ".jpg", this.getCacheDir()).getPath();
} catch (IOException e) {
e.printStackTrace();
return;
}
isIntent = true;
}
Here is the related cut from AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
...
<activity
android:name=".MainActivity"
android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DocumentScannerActivity"
android:label="#string/title_activity_document_scanner"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="#style/FullscreenTheme.NoActionBar">
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
What I'm doing wrong, how to prevent this error?

Google cloud messaging receiver intent does not start (broadcast intent callback: result=CANCELLED forIntent)

I am trying to make a GCM client, registration is fine. I am also successfully sending messages from server. However, the client does not start the intent. It says
09-30 08:39:59.795: W/GTalkService(4667): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[dol.framework] (has extras) }
My Intent
public class GCMService extends IntentService{
public GCMService(String name) {
super("GCMService");
}
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
String messageType = gcm.getMessageType(intent);
android.util.Log.i("hi","test");
if (!extras.isEmpty()) {
if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
Logger.logInUI(tag, "Received: " + extras.toString());
}
}
GCMReceiver.completeWakefulIntent(intent);
}
}
And my receiver
public class GCMReceiver extends WakefulBroadcastReceiver {
public void onReceive(Context context, Intent intent) {
ComponentName comp = new ComponentName(context.getPackageName(),
GCMService.class.getName());
startWakefulService(context, (intent.setComponent(comp)));
Logger.log("hi","eetett");
setResultCode(Activity.RESULT_OK);
}
}
And finally my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dol.framework"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="dol.framework.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="dol.framework.gcm.permission.C2D_MESSAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:name="dol.framework.widget.DolApplication"
android:label="Dol Framework"
android:theme="#style/AppTheme" >
<activity
android:name="dol.framework.activity.DebugActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="dol.framework.GCMReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="dol.framework" />
</intent-filter>
</receiver>
<service android:name="dol.framework.GCMService"/>
</application>
</manifest>
Sorry for the wall of text. Both GCMService and GCMReceiver is at top of my package (dol.framework). What am I doing wrong? Other than those, I am not doing much. Only registering the device and then I am sending a message to this device. Log prints the message at top but does nothing. Shouldn't I start service or something? I didn't see anything related on examples.
In the permission you defined and used for GCM you have dol.framework.gcm.permission. It should be dol.framework.permission, since your app's package is dol.framework.
Try changing the receiver bit of your manifest to this:
<receiver
android:name=".GCMReciever"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="dol.framework" />
</intent-filter>
</receiver>

sync txt file in internal storage with txt file in dropbox dropbox api

I want to sync a txt file in android internal storage (or sdcard for that matter) and have it automatically sync to a txt in my dropbox. i've used dropbox api but don't have hold on on how to achieve this. help needed please.
Update:
Here's my function to get the txt content to LogCat for now:
public void getFromDbx(){
try {
mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);
final String TEST_DATA = " Database does not exist yet";
final String TEST_FILE_NAME = "data.txt";
DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);
// Create DbxFileSystem for synchronized file access.
DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());
// Print the contents of the root folder. This will block until we can
// sync metadata the first time.
//dont need this code -- ahmed
// Create a test file only if it doesn't already exist.
if (!dbxFs.exists(testPath)) {
DbxFile testFile = dbxFs.create(testPath);
try {
testFile.writeString(TEST_DATA);
} finally {
testFile.close();
}
}
// Read and print the contents of test file. Since we're not making
// any attempt to wait for the latest version, this may print an
// older cached version. Use getSyncStatus() and/or a listener to
// check for a new version.
if (dbxFs.isFile(testPath)) {
String resultData;
DbxFile testFile = dbxFs.open(testPath);
try {
resultData = testFile.readString();
} finally {
testFile.close();
}
Log.i("dbx",resultData);
} else if (dbxFs.isFolder(testPath)) {
}
} catch (IOException e) {
}
My OnCreate:
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
//connect dbx to account
mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);
//get data from ems_data.txt from dropbox account
getFromDbx();
My OnActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_LINK_TO_DBX) {
if (resultCode == Activity.RESULT_OK) {
getFromDbx();
} else {
Log.i("dbxems", "Link to Dropbox failed or was cancelled.");
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
My Manifest File:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testdatabaseactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CALL_PHONE" >
</uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:debuggable="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.testdatabaseactivity.TestDatabaseActivity"
android:label="#string/app_name" >
<intent-filter>
</intent-filter>
</activity>
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:label="your tests label"
android:targetPackage="com.example.testdatabaseactivity" />
<uses-library android:name="android.test.runner" />
<activity
android:name="com.example.testdatabaseactivity.MainScreenActivity"
android:label="#string/title_activity_main_screen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.testdatabaseactivity.SearchByName"
android:label="#string/title_activity_search_by_name"
android:windowSoftInputMode="stateHidden" >
</activity>
<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask" >
<intent-filter>
<data android:scheme="db-KEY_HERE" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android:label="Dropbox Sync" />
</application>
</manifest>
EDIT: there is no error, the app shows the auth screen, I click allow and then nothing happens. I can press allow 10 times and nothing happens at all..
In getFromDbx, you call startLink, which brings up the UI to link an account. When that succeeds, your onActivityResult is executed, where you call getFromDbx, which calls startLink again. :-) Looks like an infinite loop to me.

broadcast intent cancelled. Android GCM

I've been struggling with this error for a lot and I just gave up. Every time I try to send a message using GCM this error appears on LogCat. What I'm failing to do? I've followed Android examples to set up GCM Notifications.
This is the LogCat Error
Edit: The message actually gets through but I don't think this error is normal.
08-12 17:13:15.888: W/GTalkService(2237): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[com.testing.encuesta] (has extras) }
AndroidManifest.xml
<permission android:name="com.testing.encuesta.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.testing.encuesta.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.testing.encuesta.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Inicio">
</activity>
<receiver android:name=".GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.testing.encuesta" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.testing.encuesta" />
</intent-filter>
</receiver>
My class GCMBroadcastReceiver
public class GCMBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
try {
String action=intent.getAction();
if(action.equals("com.google.android.c2dm.intent.REGISTRATION"))
{
String registrationID=intent.getStringExtra("registration_id");
Log.d("ID",registrationID);
String error=intent.getStringExtra("error");
String unregistered=intent.getStringExtra("unregistered");
}
else if(action.equals("com.google.android.c2dm.intent.RECEIVE"))
{
String data1=intent.getStringExtra("data1");
String data2=intent.getStringExtra("data2");
Toast.makeText(context, data1, Toast.LENGTH_LONG);
}
} catch (Exception e) {
Log.d("Error", "error en C2DM"+e.toString());
}
}
Fixed, you just need to add setResultCode(Activity.RESULT_OK); at the end of the onReceive(); method

Categories

Resources