I have created a sample android application for receiving push messages from Parse. I had followed this video tutorial. The application is working fine and I am able to receive push notifications.
The classes required are as follows:
ParseApplication class:
public class ParseApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.initialize(this, "ygdC4y3uzCe0TOEPOfB1U469Gg5ZJGxF2OGlNKCG", "Tk5ZlDiWWVJm2Xio5IiXk0KI5JM1jrvGPOSpFxzE");
PushService.setDefaultPushCallback(ParseApplication.this, SampleClass.class);
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
// If you would like all objects to be private by default, remove this line.
defaultACL.setPublicReadAccess(true);
ParseACL.setDefaultACL(defaultACL, true);
}
}
ParseStarterProjectActivity class:
public class ParseStarterProjectActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ParseAnalytics.trackAppOpened(getIntent());
}
}
SampleClass class:
public class SampleClass extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_class);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sample_class, menu);
return true;
}
}
The manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!--
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
-->
<permission
android:name="com.parse.starter.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
<application
android:name="com.parse.starter.ParseApplication"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.parse.starter.ParseStarterProjectActivity"
android:label="Test Push" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.parse.starter.MainActivity"
android:label="Test Push" >
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
<activity
android:name="com.parse.starter.SampleClass"
android:label="#string/title_activity_sample_class" >
</activity>
</application>
</manifest>
Now I want to get text from the push notifications when the user receives them. What should I do to get the text from the notifications?
This is the url to the push notification server.
I even went though this.
I had to change the SampleClass Activity like this:
public class SampleClass extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_class);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String jsonData = extras.getString( "com.parse.Data" );
Log.i("Data Received:", jsonData);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sample_class, menu);
return true;
}
The rest is as it is. I referred this link.
Related
I'm trying to add in-app purchases and when I call OpenIabHelper::launchPurchaseFlow function:
I see Google Play purchase window
onStop and onDestroy are executed in my main activity without calls to onActivityResult
So in the end I left with GooglePlay window and my dead app
I tried to start another activity via startActivityForResult and it worked fine
(nothing was destroyed and onActivityResult was called), so it seems that problem is with OpenIAB library
Therefore there's my question:
What can possibly force my activity to be destroyed after calling OpenIabHelper::launchPurchaseFlow ?
It doesn't seem to be system because it has enough memory and as I said startActivityForResult works fine.
Also there's no exceptions being trown so I'm puzzled
Any help would be appreciated
MyActivity.java
public class MyActivity extends AppCompatActivity {
private OpenIabHelper m_helper;
private Boolean m_bOpenIabInitialized = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OpenIabHelper.Options.Builder builder = new OpenIabHelper.Options.Builder()
.addAvailableStores(new GooglePlay(this,null))
.addPreferredStoreName(OpenIabHelper.NAME_GOOGLE)
.setStoreSearchStrategy(OpenIabHelper.Options.SEARCH_STRATEGY_INSTALLER_THEN_BEST_FIT)
.setVerifyMode(OpenIabHelper.Options.VERIFY_SKIP)
.setCheckInventory(false);
m_helper = new OpenIabHelper(this, builder.build());
m_helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
m_bOpenIabInitialized = result.isSuccess();
}
});
}
public void onListViewItemClicked(String sku, String payload) {
if (m_bOpenIabInitialized == null || !m_bOpenIabInitialized) return;
m_helper.launchPurchaseFlow(this, sku, 10001, null, payload);
}
#Override
public void startActivityForResult(Intent intent, int RequestCode) {
// never reaches here
Log.d(TAG, "startActivityForResult()");
}
#Override
protected void onActivityResult(int RequestCode, int ResultCode, Intent data) {
// never reaches here
Log.d(TAG, "onActivityResult()");
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example" >
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="com.android.vending.BILLING" />
<application
android:allowBackup="true"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Have you tried changing the activity's launchMode? Maybe the singleTop launch mode will preserve your activity:
<activity
android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
You can find more about launch modes here:
https://developer.android.com/guide/topics/manifest/activity-element.html#lmode
Sorry for my english. I have spent 2 days but I can't send push messages to android. I use google cloud message. For example in gcm I create a new project and I have an id:
Then I enabled gcm and added the server key
I have code like this:
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alexy.gcmclient">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.hmkcode.android.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.hmkcode.android.gcm.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".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>
<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.hmkcode.android.gcm" />
</intent-filter>
</receiver>
<service
android:name=".GcmMessageHandler"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
</application>
</manifest>
GcmBroadcastReceiver
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Log.e("GcmBroadcastReceiver", "GcmBroadcastReceiver");
// Explicitly specify that GcmMessageHandler will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
GcmMessageHandler.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
GcmMessageHandler
public class GcmMessageHandler extends IntentService {
String mes;
private Handler handler;
public GcmMessageHandler() {
super("GcmMessageHandler");
}
#Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
handler = new Handler();
Log.e("GcmMessageHandler", "GcmMessageHandler");
}
#Override
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
// The getMessageType() intent parameter must be the intent you received
// in your BroadcastReceiver.
String messageType = gcm.getMessageType(intent);
Log.e("message", messageType);
}
Main
public class MainActivity extends Activity implements OnClickListener{
Button btnRegId, unregister;
EditText etRegId;
GoogleCloudMessaging gcm;
String regid;
String PROJECT_NUMBER = "308****";
private BroadcastReceiver mRegistrationBroadcastReceiver;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
unregister = (Button) findViewById(R.id.unregister);
btnRegId = (Button) findViewById(R.id.btnGetRegId);
etRegId = (EditText) findViewById(R.id.etRegId);
btnRegId.setOnClickListener(this);
}
public void getRegId(){
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
InstanceID instanceID = InstanceID.getInstance(getApplicationContext());
String token = instanceID.getToken(PROJECT_NUMBER,
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
msg = token;
//apiKey = msg;
GcmPubSub.getInstance(getApplicationContext()).subscribe(token, "/topics/users", null);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
#Override
protected void onPostExecute(String msg) {
etRegId.setText(msg + "\n");
Log.e("key", msg);
}
}.execute(null, null, null);
}
#Override
public void onClick(View v) {
getRegId();
}
}
I use service and tried to send some push messages to the device. In service it says Success. But the push in android is not coming (I have no output in the log)
I assume your app package name must be com.example.alexy.gcmclient or replace the package name build.gradle
defaultConfig
applicationId "com.yourpackge"
<permission
android:name="com.example.alexy.gcmclient.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission
android:name="com.example.alexy.gcmclient.permission.C2D_MESSAGE" />
<receiver android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.alexy.gcmclient" />
</intent-filter>
</receiver>
The package names for C2D_MESSAGE are wrong, change them to your package name. Also, make sure you have the configuration file near the build.gradle of your app directory. Edit: go through all of the manifest and change wherever you see hmk to your package name. Your package name should be com.example.alexy.gcmclient as per your manifest.
I'm in Android Studio, work with Parse.com and when I run this code:
public void onClick(View v) {
Log.i(TAG, "Like-button clicked");
ParseUser currentUser = ParseUser.getCurrentUser();
Activity likes = new Activity();
likes.setToUser(photo.getUser());
likes.setFromUser(currentUser);
likes.setType("like");
likes.setPhoto(photo);
ParseACL acl = new ParseACL(currentUser);
acl.setPublicReadAccess(true);
likes.setACL(acl);
likes.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
//....
It crashes at the line Activity likes = new Activity();, and says as ParseException: "You must register this ParseObject subclass before instantiating it."
My class Activity looks like this:
package com.parse.myApp
import com.parse.ParseClassName;
import com.parse.ParseFile;
import com.parse.ParseObject;
import com.parse.ParseUser;
/*
* An extension of ParseObject that makes
* it more convenient to access information
* about a given Photo
*/
#ParseClassName("Activity")
public class Activity extends ParseObject {
public Activity() {
// A default constructor is required.
}
public ParseUser getFromUser(){
return getParseUser("fromUser");
}
public void setFromUser(ParseUser user){
put("fromUser", user);
}
public ParseUser getToUser(){
return getParseUser("toUser");
}
public void setToUser(ParseUser user){
put("toUser", user);
}
public String getType(){
return getString("type");
}
public void setType(String t){
put("type", t);
}
public String getContent(){
return getString("content");
}
public void setContent(String c){
put("content", c);
}
public ParseFile getPhoto(){
return getParseFile("photo");
}
public void setPhoto(ParseFile pf){
put("photo", pf);
}
}
And I have already set in my ApplicationClass:
package com.parse.myApp;
import android.app.Application;
import com.parse.Parse;
import com.parse.ParseACL;
import com.parse.ParseFacebookUtils;
import com.parse.ParseInstallation;
import com.parse.ParseObject;
import com.parse.PushService;
public class AnypicApplication extends Application {
static final String TAG = "Panagram";
#Override
public void onCreate() {
super.onCreate();
/*
* In this tutorial, we'll subclass ParseObjects for convenience to
* create and modify Photo objects.
*
* Also, we'll use an Activity class to keep track of the relationships
* of ParseUsers with each other and Photos. Every time a user follows, likes
* or comments, a new activity is created to represent the relationship.
*/
ParseObject.registerSubclass(Photo.class);
ParseObject.registerSubclass(Activity.class);
/*
* Fill in this section with your Parse credentials
*/
Parse.initialize(this, "myKey", "myKey");
// Set your Facebook App Id in strings.xml
ParseFacebookUtils.initialize("373432736168885");
/*
* For more information on app security and Parse ACL:
* https://www.parse.com/docs/android_guide#security-recommendations
*/
ParseACL defaultACL = new ParseACL();
/*
* If you would like all objects to be private by default, remove this
* line
*/
defaultACL.setPublicReadAccess(true);
/*
* Default ACL is public read access, and user read/write access
*/
ParseACL.setDefaultACL(defaultACL, true);
/*
* Register for push notifications.
*/
PushService.setDefaultPushCallback(this, LoginActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
My Manifest.xmllooks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.anypic"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.parse.anypic.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.parse.anypic.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application
android:name=".AnypicApplication"
android:allowBackup="true"
android:icon="#drawable/anypic_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".HomeListActivity"
android:label="#string/title_activity_home_list" >
<!-- <meta-data -->
<!-- android:name="android.support.PARENT_ACTIVITY" -->
<!-- android:value="android.app.Activity" /> -->
</activity>
<activity
android:name=".NewPhotoActivity"
android:label="#string/title_activity_new_photo" >
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/title_activity_login" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.parse.GcmBroadcastReceiver"
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" />
<!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. -->
<category android:name="com.parse.anypic" />
</intent-filter>
</receiver>
<activity
android:name=".RegisterAcitivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_register_acitivity"
android:theme="#style/FullscreenTheme" >
</activity>
</application>
</manifest>
And even if I already have set the registerSubclass, I get every time the same error.
SOLUTION
My problem was that I had two Activity classes, and I did: ParseObject.registerSubclass(Activity.class);, but android didn't know which Activity class it was. So I deleted one of them, and the problem is solved.
SOLUTION
My problem was that I had two Activity classes, and I did: ParseObject.registerSubclass(Activity.class);, but android didn't know which Activity class it was. So I deleted one of them, and the problem is solved.
I recommend you to rename your Activity class into ActivityParse to be sure that you have registered correct class.
Please be sure that you used your ApplicationClass at AndroidManifest and call initialization at onCreate method.
I build an android app composed by a web view, in parse.com i've got my device registered but when i send a push notification in "pushes sent" there is 0 pushes.
this is my Mainactivity:
import com.party.bparty.MainActivity;
import com.parse.Parse;
import com.parse.ParseInstallation;
import com.parse.ParsePush;
import com.parse.ParseQuery;
import com.parse.PushService;
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
private String url = "http://www.bestparty.altervista.org";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//attivo parse per le notifiche
Parse.initialize(this,"zJxpd9798Ns6A9rzUDpe78ElRY0I99ES3LD6nDQV","kmAmA1iTbC32BTE9ERtzNOoHXbJchhIn6tyPXKMi");
PushService.setDefaultPushCallback(this, MainActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
//...
//...initializing and loading the contentview and the webview
}
//options menu omitted
}
this is my MycustomReceiver
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
try {
if (intent == null)
Log.d(TAG, "Receiver intent null");
else {
String action = intent.getAction();
Log.d(TAG, "got action " + action );
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
String channel = intent.getExtras().getString("com.parse.Channel");
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Log.d(TAG, "got action " + action + " on channel " + channel + " with:");
Iterator itr = json.keys();
while (itr.hasNext()) {
String key = (String) itr.next();
if (key.equals("customdata")) {
Intent pupInt = new Intent(context, ShowPopUp.class);
pupInt.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
context.getApplicationContext().startActivity(pupInt);
}
Log.d(TAG, "..." + key + " => " + json.getString(key));
}
}
}
}
catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}
}
and this is my ShowPopup
public class ShowPopUp extends Activity implements OnClickListener {
Button ok, cancel;
boolean click = true;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Cupon");
setContentView(R.layout.popupdialog);
ok = (Button)findViewById(R.id.popOkB);
ok.setOnClickListener(this);
cancel = (Button)findViewById(R.id.popCancelB);
cancel.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
finish();
}
}
And this is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.party.bparty"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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="com.party.bparty.ShowPopUp"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</activity>
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.RECEIVE_BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
Where's my error?
I do it, but it doesn't work anyway
" if (action.equals("com.party.bparty.UPDATE_STATUS")) {
Pick one, either com.party.bparty.UPDATE_STATUS or com.iakremera.pushnotificationdemo.UPDATE_STATUS"
but Now i have 1 "PUSH SENT" in push sent, but my device doesn't show any push
Your receiver has the wrong filter. Your receiver is declared as this:
<receiver android:name="com.party.bparty.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="com.iakremera.pushnotificationdemo.UPDATE_STATUS" />
</intent-filter>
</receiver>
but you are checking for a different intent action in the code:
if (action.equals("com.party.bparty.UPDATE_STATUS")) {
Pick one, either com.party.bparty.UPDATE_STATUS or com.iakremera.pushnotificationdemo.UPDATE_STATUS and also make sure that Parse knows which one it is when you perform the push itself.
First off i want to tell you i have done all i can. Followed like 10 tutorials on internet and 10 threads on stacked. Still no success.
I know guys that you recommend using scanning via intent,but in my case its not an option and i need to have it native in my app.
I have downloaded the zxing library (2.1) and followed this tutorial
When i run this code on my Galaxy S3 or Galaxy Tab 10.1 as debug, the program crashes, after freezing for like 20 seconds, when i click the button that should start intent for result: com.google.zxing.client.android.SCAN or com.google.zxing.client.android.CaptureActivity.
Note that i have copied all the resources from Barcode Scanner app like beep sound, xml files and other.
Crash Log
My code is below:
MainActivity.java
package com.example.philipscan;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void scanNow(View view)
{
Log.e("test", "button works!");
Intent intent = new Intent("com.google.zxing.client.android.CaptureActivity");
startActivityForResult(intent, 3);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
Log.e("xZing", "Back");
if (requestCode == 3)
{
if (resultCode == RESULT_OK)
{
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.e("xZing", "contents: "+contents+" format: "+format);
// Handle successful scan
}
else if (resultCode == RESULT_CANCELED)
{
// Handle cancel
Log.e("xZing", "Cancelled");
}
}
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.philipscan"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<uses-feature android:name="android.hardware.camera.flash" android:required="false"/>
<uses-feature android:name="android.hardware.screen.landscape"/>
<uses-feature android:name="android.hardware.wifi" android:required="false"/>
<uses-feature android:name="android.hardware.touchscreen" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.FLASHLIGHT"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.philipscan.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
My SRC folder
I'm very thankful for all the help i can get.
Try to create Intent another way
Intent scanIntent = new Intent("com.google.zxing.client.android.SCAN");
scanIntent.putExtra("SCAN_MODE", "ONE_D_MODE");
then startActivityForResult() as usual. ONE_D_MODE is mode to scan 1D barcodes like Code39.
Remove all this code you copied from our project. It's not necessary, you're not understanding it, and it's not supposed to be reused this way under the license: https://code.google.com/p/zxing/wiki/LicenseQuestions
In particular you are not supposed to copy the manifest, and not allowed to copy the UI.
Instead, it is much simpler, since you seem to be trying to use Intents anyway: https://code.google.com/p/zxing/wiki/ScanningViaIntent