I am trying to change the language of the app but it's not happening.I have tried almost all solutions available in SO but none worked. Interesting fact is most of the codes are able to change the language of the Facebook Account Kit activity but other activity's language is not being changed.Below is my application class and manifest file.
public class MyApplication extends Application {
private Locale locale = null;
#Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (locale != null)
{
newConfig.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics());
}
}
#Override
public void onCreate()
{
super.onCreate();
Configuration config = getBaseContext().getResources().getConfiguration();
new SharedPrefManager(this).setLanguage("fr");
String lang = new SharedPrefManager(this).getLanguage();
locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
AccountKit.initialize(getApplicationContext());
}
}
AndroidManifest.xml
<?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.pullerr.pullerrdriver">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
<application
android:name=".MyApplication"
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">
<meta-data android:name="com.facebook.accountkit.ApplicationName"
android:value="#string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="#string/FACEBOOK_APP_ID" />
<meta-data android:name="com.facebook.accountkit.ClientToken"
android:value="#string/ACCOUNT_KIT_CLIENT_TOKEN" />
<meta-data android:name="com.facebook.accountkit.FacebookAppEventsEnabled"
android:value="false"/>
<activity
android:name="com.facebook.accountkit.ui.AccountKitActivity"
android:theme="#style/AppLoginTheme"
tools:replace="android:theme"/>
<activity
android:configChanges="layoutDirection|locale"
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:configChanges="layoutDirection|locale"
android:name=".LoadDetails"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.LOADDETAILS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:configChanges="layoutDirection|locale"
android:name=".Login"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="layoutDirection|locale"
android:name=".Register"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.REGISTER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name="services.LocationService"/>
</application>
</manifest>
check this links maybe it helps
How to programmatically change language?
http://blog.nkdroidsolutions.com/change-language-programmatically-android-app-building-multi-language-supported-app/
https://developer.android.com/training/basics/supporting-devices/languages.html
Change languages in app via strings.xml
You can change your language (i18N) as below :
public static void changeLanguage(String language, Context context) {
try {
if ( null != language) {
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
Log.i(TAG, "Language changed to " + language);
} catch (Exception e) {
Log.e(TAG, "[changeLanguage]" + e.getMessage());
}
}
I have one open-source project on GitHub. Drive-in yourself at https://github.com/configurer/easy-screen-lock/blob/master/EasyScreenLock/src/com/configurer/easyscreenlock/utils/LanguageUtils.java
Related
I am trying to add snap-kit in my application and I have integrated everything as their documentation. App successfully launched Snapchat app but it's not login it shows an error Something is wrong Here is my complete code and other implementation. This is the official documentation that I have followed https://kit.snapchat.com/docs/login-kit-android
MainActivity
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding binding;
private static final String TAG = "MAIN_ACTIVITY";
String query = "{me{bitmoji{avatar},displayName}}";
String variables = null;
boolean isUserLoggedIn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
isUserLoggedIn = SnapLogin.isUserLoggedIn(this);
if (isUserLoggedIn)
binding.btnLogin.setText("Logout");
else
binding.btnLogin.setText("Logout");
binding.btnLogin.setOnClickListener(v -> {
SnapLogin.getAuthTokenManager(this).startTokenGrant();
binding.progress.setVisibility(View.VISIBLE);
});
SnapLogin.getLoginStateController(this).addOnLoginStateChangedListener(mLoginStateChangedListener);
SnapLogin.fetchUserData(this, query, null, new FetchUserDataCallback() {
#Override
public void onSuccess(#Nullable UserDataResponse userDataResponse) {
if (userDataResponse == null || userDataResponse.getData() == null) {
return;
}
MeData meData = userDataResponse.getData().getMe();
if (meData == null) {
return;
}
binding.txtName.setText(userDataResponse.getData().getMe().getDisplayName());
if (meData.getBitmojiData() != null) {
Glide.with(MainActivity.this)
.load(meData.getBitmojiData().getAvatar())
.into(binding.imgProfile);
}
}
#Override
public void onFailure(boolean isNetworkError, int statusCode) {
}
});
}
final LoginStateController.OnLoginStateChangedListener mLoginStateChangedListener =
new LoginStateController.OnLoginStateChangedListener() {
#Override
public void onLoginSucceeded() {
// Here you could update UI to show login success
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginSucceeded: ");
binding.btnLogin.setText("Logout");
}
#Override
public void onLoginFailed() {
// Here you could update UI to show login failure
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLoginFailed: ");
}
#Override
public void onLogout() {
// Here you could update UI to reflect logged out state
binding.progress.setVisibility(View.VISIBLE);
Log.d(TAG, "onLogout: ");
}
};
}
Manifests
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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/Theme.SnapchatAndroidDemo">
<meta-data
android:name="com.snapchat.kit.sdk.clientId"
android:value="**********************" />
<meta-data
android:name="com.snapchat.kit.sdk.redirectUrl"
android:value="*********************" />
<meta-data
android:name="com.snapchat.kit.sdk.scopes"
android:resource="#array/snap_connect_scopes" />
<activity android:name=".ui.sign.SigninActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.intro.IntroActivity"
android:screenOrientation="nosensor"/>
<activity android:name=".ui.login.LoginActivity"
android:screenOrientation="nosensor"/>
<activity
android:name=".ui.splash.SplashActivity"
android:screenOrientation="nosensor"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.MainActivity"
android:screenOrientation="nosensor" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="lmk"
android:path="/oauth2"
android:scheme="lmk" />
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
Dependencies
implementation([
'com.snapchat.kit.sdk:login:1.1.4',
'com.snapchat.kit.sdk:core:1.1.4'
])
You need to add these line in the application tag
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
Use like this
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iotait.snapchatandroid">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.snapchat.android" />
</queries>
<application
android:name=".application.AppController"
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/Theme.SnapchatAndroidDemo">
<meta-data android:name="com.snapchat.kit.sdk.clientId" android:value="1aab4ace-3f06-487d-bc85************"/>
<meta-data android:name="com.snapchat.kit.sdk.redirectUrl" android:value="https:********"/>
<meta-data android:name="com.snapchat.kit.sdk.scopes" android:resource="#array/snap_connect_scopes"/>
<activity android:name=".intro.IntroActivity"/>
<activity android:name=".login.LoginActivity"/>
<activity
android:name=".splash.SplashActivity"
android:theme="#style/Theme.splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity" />
<activity
android:name="com.snapchat.kit.sdk.SnapKitActivity"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="lmk" android:host="lmk" android:path="/oauth2"/>
</intent-filter>
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="#array/preloaded_fonts" />
</application>
</manifest>
I have a payment activity and splash activity that it shows app of contents after user will buy it. payment activity is default Launcher in Manifest.xml that I want to set launcher Activity to splash activity and payment activity disabled after payment.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exa.iu2">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<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=".PaymentActivity" android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="return" android:host=“zrp”/>
</intent-filter>
</activity>
<activity-alias
android:name=".PaymentActivity"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:enabled="false" android:targetActivity=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/AppTheme.NoActionBar"/>
</application>
</manifest>
in Payment Activity and "If payment is success"
public void onCallbackResultVerificationPayment(boolean isPaymentSuccess, String refID, PaymentRequest paymentRequest) {
if(isPaymentSuccess){
Toast.makeText(PaymentActivity.this, “Payment Success” + refID, Toast.LENGTH_SHORT).show();
ComponentName cm = new ComponentName("com.exa.iu2", "com.exa.iu2"+".SplashActivity");
ComponentName cm2 = new ComponentName("com.exa.iu2", "com.exa.iu2"+".PaymentActivity");
PackageManager pm = getApplication().getPackageManager();
pm.setComponentEnabledSetting(cm, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,PackageManager.DONT_KILL_APP);
pm.setComponentEnabledSetting(cm2, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,0);
}else {
Toast.makeText(PaymentActivity.this, “Don’t success”, Toast.LENGTH_SHORT).show();
}
}
});
Thx
I suggest you create a Hub or Startup activity in which decide what to display. The new activity has to be set as Main -> Launcher activity, obviously.
In AndroidManifest do this
<activity android:name=".SplashActivity"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Inside SplashActivity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
// Check condition to open appropriate activity
// like
// if(paymentDone) start some activity
// else start another activity
finish()
}
}
There is an error in the manifest file that when I try to enter reciever it says class or interface expected
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.uzairaslam.silenter" >
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS_" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<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>
</application>
<receiver android:name="AlarmReceiver"/>
The receiver class which is not added is this
public class AlarmReceiver extends BroadcastReceiver {
SQLiteDatabase db;
String d ;
String deviceard;
String roomard ;
boolean status ;
public AlarmReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
d= intent.getStringExtra("DeviceId");
deviceard = intent.getStringExtra("Device_Ard_Id");
roomard = intent.getStringExtra("Room_Ard_id");
status = Boolean.parseBoolean(intent.getStringExtra("Device_Status"));
if(status)
Send_sms("y"+roomard+":"+deviceard+":oz" ,context);
else
Send_sms("y"+roomard+":"+deviceard+":fz" ,context);
Toast.makeText(context,"Mateen",Toast.LENGTH_LONG).show();
}
public void Send_sms(String msg,Context c)
{
Uri alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
if (alarmUri == null) {
alarmUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
Ringtone ringtone = RingtoneManager.getRingtone(c, alarmUri);
ringtone.play();
}
}
<receiver android:name="AlarmReceiver"/>
This line should be with in the application tag and give the fully qualified Receiver name. like below
<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="<receiver package>.AlarmReceiver"/>
</application>
I'm going nuts with this issue I have, showing the keyboard on a webview.
I have done every single thing stackoverflow says, and still no success. Here's my code:
public void openChat(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Chat VM Latino");
WebView wv = new WebView(this);
wv.setFocusable(true);
wv.loadUrl("http://190.171.0.181:3001/");
wv.requestFocus(View.FOCUS_DOWN);
wv.getSettings().setJavaScriptEnabled(true);
wv.requestFocus(View.FOCUS_DOWN);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
alert.setView(wv);
alert.setNegativeButton("Cerrar",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.show();
}
And here's my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vmlatino"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
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.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.NoActionBar" >
<activity
android:name="com.racsa.UI.Splash"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.racsa.UI.EscogerStreamActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.racsa.UI.RadioActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.racsa.UI.RadioChatActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name="com.racsa.UI.VideoViewDemo"
android:configChanges="orientation|keyboard"
android:windowSoftInputMode="stateUnspecified"
android:label="Media/VideoView"
android:theme="#android:style/Theme.Holo.NoActionBar" >
</activity>
<activity
android:name="com.racsa.UI.VMChatActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<activity
android:name="io.vov.vitamio.activity.InitActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden|navigation"
android:launchMode="singleTop"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="stateAlwaysHidden" />
</application>
</manifest>
I'm using the vitamio plugin for video streaming, any help will be appreciated!
Thanks in advance.
In the end, I didn't use a Dialog, I added a float like WebView, and the keyboard was now showing.
I am doing a chat application . In the app i have to do chatting with help of push notifications using parse andorid sdk. I am successfull to generate push notications between different users . But not able to recieve push and add their data in list view . Here is code of maifest file
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="example.chat.ChatApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.facebook.LoginActivity"
android:label="#string/app_name" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/app_id" />
<activity
android:name="example.chat.LoginActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="example.chat.FriendslIst"
android:label="Friend list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.RegisterActivity"
android:label="#string/title_activity_register"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.FriendListActivity"
android:label="#string/title_activity_friend_list"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="example.chat.ChatActivity"
android:label="#string/title_activity_chat"
android:screenOrientation="portrait" >
</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="example.chat.MyCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="example.chat.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
and code for my custom reciever
public class MyCustomReceiver extends BroadcastReceiver {
private static final String TAG = "MyCustomReceiver";
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, ""+intent, Toast.LENGTH_LONG).show();
}
}
and from java code I am sending push like this :
ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
query.whereEqualTo("device_id", target);
ParsePush push = new ParsePush();
push.setQuery(query);
push.setMessage(message);
push.setExpirationTimeInterval(86400);
push.sendInBackground();
Please tell me where I am wrong for recieving data using reciever and what to do when i recive push means any logic or idea to move further . Thanks in advance
here is the manifiest file.....
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your package name"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="16" />
<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" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="your package name.YourActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</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="your package name.YourCustomReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="your package name.UPDATE_STATUS" />
</intent-filter>
</receiver>
</application>
</manifest>
use this code to receive the push...
public class MyCustomReceiver extends BroadcastReceiver {
String title, from, msg;
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = extras != null ? extras.getString("com.parse.Data")
: "";
Log.e("message ", " " + message);
JSONObject jObject;
try {
if (message != null && !message.equals("")) {
jObject = new JSONObject(message);
from = jObject.getString("from");
msg = jObject.getString("title");
title = jObject.getString("msg");
GCMMessage gcmMessage = new GCMMessage();
gcmMessage.setMsg_body(msg);
gcmMessage.setMsg_title(title);
gcmMessage.setType(0);
gcmMessage.setDateTime(time);
DatabaseUtil.insertMessage(context, gcmMessage);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
}
and here is the code to send push...
JSONObject obj;
try {
obj =new JSONObject();
obj.put("alert","oman expert ");
obj.put("action","Your Package name.UPDATE_STATUS");
data.put("from", ParseUser.getCurrentUser().getUsername());
obj.put("msg","hi");
obj.put("title","msg");
ParsePush push = new ParsePush();
ParseQuery query = ParseInstallation.getQuery();
push.setQuery(query);
push.setData(obj);
push.sendInBackground();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for any further query please let me know....
In the above code example, you have missed out few things,
Check your AndroidManifest.xml file, and add c2dm permissions,
permission android:name="your package.permission.C2D_MESSAGE" android:protectionLevel="signature"
uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"
uses-permission android:name="your package.permission.C2D_MESSAGE"
While sending the data, set the action in your data,
JSONObject data = new JSONObject();
try {
data.put("action", "your package.GOT_MESSAGE");
data.put("ya", ya);
data.put("from", ParseUser.getCurrentUser().getUsername());
}catch (Exception e){
e.printStackTrace();
return;
}
ParsePush parsePush = new ParsePush();
parsePush.setData(data);