Security Exception App.Utils.getDeviceSerial Error. How to fix it? - android

I will make the file sharing android app like share it and xender.
but my app users face some problems in my app. and in google play console error section it shows Security Exception App.Utils.getDeviceSerial Error.
I am try to find the error but I can not able to find the error.
please help to find the issue in my coding.
This is my manifest file
<?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.genonbeta.TrebleShot">
<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.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="com.IApps.IndianShareIt.App"
android:allowBackup="true"
android:appComponentFactory="#string/app_name"
android:fullBackupContent="true"
android:icon="#drawable/ic_trebleshot_original_white_128dp"
android:label="#string/text_appName"
android:supportsRtl="true"
android:theme="#style/Theme.TrebleShot"
tools:ignore="GoogleAppIndexingWarning"
tools:replace="android:appComponentFactory">
<activity android:name="com.IApps.IndianShareIt.activity.WebView"
android:screenOrientation="locked"
android:theme="#style/Theme.Design.Light.NoActionBar"/>
<activity
android:name="com.IApps.IndianShareIt.activity.HomeActivity"
android:label="#string/text_appName"
android:launchMode="singleTask"
android:screenOrientation="locked"
android:theme="#style/Theme.TrebleShot.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.IApps.IndianShareIt.activity.ShareActivity"
android:label="#string/text_appName"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar">
<intent-filter>
<action android:name="genonbeta.intent.action.TREBLESHOT_SEND_TEXT" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<action android:name="genonbeta.intent.action.TREBLESHOT_SEND" />
<action android:name="genonbeta.intent.action.TREBLESHOT_SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<!--
<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value=".service.DeviceChooserService" />
-->
</activity>
<activity
android:name="com.IApps.IndianShareIt.activity.AddDevicesToTransferActivity"
android:label="#string/text_addDevicesToTransfer"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.FileExplorerActivity"
android:label="#string/text_fileExplorer"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.TextStreamActivity"
android:label="#string/text_textStream"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.ConnectionManagerActivity"
android:label="#string/text_connectDevices"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.ContentSharingActivity"
android:label="#string/text_send"
android:launchMode="singleTask"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.FilePickerActivity"
android:label="#string/text_fileExplorer" />
<activity
android:name="com.IApps.IndianShareIt.activity.ViewTransferActivity"
android:label="#string/text_transactionViewer"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar">
<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="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" />
<data android:host="*" />
<!-- expected file name pattern .5435-4543-4354-ewrw.tshare -->
<data android:pathPattern=".*\\.tshare" />
<data android:pathPattern=".*\\..*\\.tshare" />
</intent-filter>
</activity>
<activity
android:name="com.IApps.IndianShareIt.activity.ManageDevicesActivity"
android:label="#string/text_manageDevices" />
<activity
android:name="com.IApps.IndianShareIt.activity.SearchActivity"
android:label="#string/butn_search" />
<activity
android:name="com.IApps.IndianShareIt.activity.PreferencesActivity"
android:label="#string/text_preferences" />
<activity
android:name="com.IApps.IndianShareIt.activity.TextEditorActivity"
android:label="#string/text_textEditor" />
<activity
android:name="com.IApps.IndianShareIt.activity.ChangeStoragePathActivity"
android:theme="#style/Base.Theme.AppCompat.Dialog">
<intent-filter>
<action android:name="com.genonbeta.intent.action.UPDATE_STORAGE_PATH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="com.IApps.IndianShareIt.activity.ThirdPartyLibrariesActivity"
android:label="#string/text_thirdPartyLibraries" />
<activity
android:name="com.IApps.IndianShareIt.activity.ChangelogActivity"
android:label="#string/text_changelog" /> <!-- todo: Remember, we are always using dark theme for this for better effects -->
<activity
android:name="com.IApps.IndianShareIt.activity.BarcodeScannerActivity"
android:label="#string/text_scanQrCode"
android:theme="#style/Theme.TrebleShot.BarcodeScannerActivity" />
<activity
android:name="com.IApps.IndianShareIt.activity.WelcomeActivity"
android:label="#string/text_welcome"
android:theme="#style/Theme.TrebleShot.NoActionBar" />
<activity
android:name="com.IApps.IndianShareIt.activity.WebShareActivity"
android:label="#string/text_webShare"
android:theme="#style/Theme.TrebleShot.NoActionBar.StaticStatusBar" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths" />
</provider>
<receiver
android:name="com.IApps.IndianShareIt.receiver.NetworkStatusReceiver"
android:process=":transfer">
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.WIFI_AP_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
<action android:name="android.net.wifi.p2p.CONNECTION_STATE_CHANGE" />
</intent-filter>
</receiver>
<receiver
android:name="com.IApps.IndianShareIt.receiver.DialogEventReceiver"
android:process=":transfer" />
<service
android:name="com.IApps.IndianShareIt.service.CommunicationService"
android:enabled="true"
android:label="#string/text_communicationService"
android:process=":transfer" />
<service
android:name="com.IApps.IndianShareIt.service.DeviceChooserService"
android:label="#string/text_chooserTargetService"
android:permission="android.permission.BIND_CHOOSER_TARGET_SERVICE">
<intent-filter>
<action android:name="android.service.chooser.ChooserTargetService" />
</intent-filter>
</service>
<service android:name="com.IApps.IndianShareIt.service.DeviceScannerService">
<intent-filter>
<action android:name="genonbeta.intent.action.SCAN_DEVICES" />
<action android:name="genonbeta.intent.action.ADD_IP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
<service
android:name="com.IApps.IndianShareIt.service.WorkerService"
android:label="#string/text_workerService" />
<service
android:name="com.IApps.IndianShareIt.service.CommunicationToggleTile"
android:icon="#drawable/ic_trebleshot_white_24dp_static"
android:label="#string/text_shareFiles"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
android:process=":transfer">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<!-- sample - ca-app-pub-3940256099942544~3347511713-->
<!-- main - ca-app-pub-2802607728843215~8939176355-->
</application>
</manifest>
and this is my welcome activity with permissions
public class WelcomeActivity extends Activity
{
public final static String TAG = WelcomeActivity.class.getSimpleName();
private ViewGroup mSplashView;
private ViewGroup mProfileView;
private ViewGroup mPermissionsView;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
setSkipPermissionRequest(true);
setWelcomePageDisallowed(true);
final FloatingActionButton nextButton = findViewById(R.id.activity_welcome_view_next);
final AppCompatImageView previousButton = findViewById(R.id.activity_welcome_view_previous);
final ProgressBar progressBar = findViewById(R.id.activity_welcome_progress_bar);
final ViewPager viewPager = findViewById(R.id.activity_welcome_view_pager);
final DynamicViewPagerAdapter pagerAdapter = new DynamicViewPagerAdapter();
{
#ColorInt
int appliedColor = ContextCompat.getColor(this, AppUtils.getReference(this, R.attr.colorSecondary));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Drawable wrapDrawable = DrawableCompat.wrap(progressBar.getProgressDrawable());
DrawableCompat.setTint(wrapDrawable, appliedColor);
progressBar.setProgressDrawable(DrawableCompat.unwrap(wrapDrawable));
} else
progressBar.setProgressTintList(ColorStateList.valueOf(appliedColor));
}
{
mSplashView = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_welcome_page_1, null, false);
pagerAdapter.addView(mSplashView);
}
if (Build.VERSION.SDK_INT >= 23) {
mPermissionsView = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_welcome_page_3, null, false);
pagerAdapter.addView(mPermissionsView);
checkPermissionsState();
mPermissionsView.findViewById(R.id.layout_welcome_page_3_request_button)
.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
requestRequiredPermissions(false);
}
});
}
{
mProfileView = (ViewGroup) getLayoutInflater().inflate(R.layout.layout_welcome_page_2, null, false);
pagerAdapter.addView(mProfileView);
setUserProfile();
}
pagerAdapter.addView(getLayoutInflater().inflate(R.layout.layout_welcome_page_4, null, false));
{
View view = getLayoutInflater().inflate(R.layout.layout_welcome_page_5, null, false);
AlphaAnimation alphaAnimation = new AlphaAnimation(0.3f, 1.0f);
alphaAnimation.setDuration(2000);
alphaAnimation.setRepeatCount(Animation.INFINITE);
alphaAnimation.setRepeatMode(Animation.REVERSE);
view.findViewById(R.id.layout_welcome_page_5_text)
.setAnimation(alphaAnimation);
pagerAdapter.addView(view);
}
progressBar.setMax((pagerAdapter.getCount() - 1) * 100);
previousButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
if (viewPager.getCurrentItem() - 1 >= 0)
viewPager.setCurrentItem(viewPager.getCurrentItem() - 1, true);
}
});
nextButton.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
if (viewPager.getCurrentItem() + 1 < pagerAdapter.getCount())
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
else {
// end presentation
getDefaultPreferences().edit()
.putBoolean("introduction_shown", true)
.apply();
startActivity(new Intent(WelcomeActivity.this, HomeActivity.class));
finish();
}
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener()
{
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
{
progressBar.setProgress((position * 100) + (int) (positionOffset * 100));
if (position == 0) {
progressBar.setAlpha(positionOffset);
previousButton.setAlpha(positionOffset);
} else {
progressBar.setAlpha(1.0f);
previousButton.setAlpha(1.0f);
}
}
#Override
public void onPageSelected(int position)
{
OvershootInterpolator interpolator = new OvershootInterpolator();
nextButton.setImageResource(position + 1 >= pagerAdapter.getCount()
? R.drawable.ic_check_white_24dp
: R.drawable.ic_navigate_next_white_24dp);
}
#Override
public void onPageScrollStateChanged(int state)
{
}
});
viewPager.setAdapter(pagerAdapter);
}
#Override
protected void onResume()
{
super.onResume();
slideSplashView();
setUserProfile();
checkPermissionsState();
}
#Override
public void onUserProfileUpdated()
{
super.onUserProfileUpdated();
setUserProfile();
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults)
{
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
checkPermissionsState();
}
protected void checkPermissionsState()
{
if (Build.VERSION.SDK_INT < 23)
return;
boolean permissionsOk = AppUtils.checkRunningConditions(this);
mPermissionsView.findViewById(R.id.layout_welcome_page_3_perm_ok_image)
.setVisibility(permissionsOk ? View.VISIBLE : View.GONE);
mPermissionsView.findViewById(R.id.layout_welcome_page_3_request_button)
.setVisibility(permissionsOk ? View.GONE : View.VISIBLE);
}
protected void setUserProfile()
{
if (mProfileView != null) {
NetworkDevice localDevice = AppUtils.getLocalDevice(getApplicationContext());
ImageView imageView = mProfileView.findViewById(R.id.layout_profile_picture_image_default);
ImageView editImageView = mProfileView.findViewById(R.id.layout_profile_picture_image_preferred);
TextView deviceNameText = mProfileView.findViewById(R.id.header_default_device_name_text);
TextView versionText = mProfileView.findViewById(R.id.header_default_device_version_text);
deviceNameText.setText(localDevice.nickname);
versionText.setText(localDevice.versionName);
loadProfilePictureInto(localDevice.nickname, imageView);
editImageView.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
startProfileEditor();
}
});
TransitionManager.beginDelayedTransition(mProfileView);
}
}
protected void slideSplashView()
{
mSplashView.findViewById(R.id.layout_welcome_page_1_splash_image)
.setAnimation(AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom_centered));
mSplashView.findViewById(R.id.layout_welcome_page_1_details)
.setAnimation(AnimationUtils.loadAnimation(this, R.anim.enter_from_bottom));
}
}

Related

How to update firebasemessagingservice to latest version?

I get an error says "error: class, interface, or enum expected" and I found out its from the firebasemessagingservice needs to be updated and I don't know how to do it. Please help.
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
you put an extra " } " in your code. remove it and recompile
Correct code:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
#Override
public void onNewToken(String s) {
super.onNewToken(s);
Log.e("NEW_TOKEN",s);
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
And here is the androidManifest file
<?xml version="1.0" encoding="utf-8"?>
<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" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=""
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!-- Disable opening of launcher Activity -->
<meta-data
android:name="com.onesignal.NotificationOpened.DEFAULT"
android:value="DISABLE" />
<activity
android:name=""
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=""
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=""
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name="com.tools.vactivities.ActivityRecipesDetail"
android:configChanges="orientation|keyboardHidden|screenSize" />
<!--admob-->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!--fcm-->
<service android:name="com.tools.notification.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".MyFirebaseMessagingService"
android:stopWithTask="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.tools.notification.NotificationExtenderExample"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE">
<intent-filter>
<action android:name="com.onesignal.NotificationExtender" />
</intent-filter>
</service>
</application>

SecurityException Permission Denial: telephony.SmsProvider uri content://sms/inbox

my phone is android 5.0 API 22.
I just learn build app Android
I create app fake SMS but crash :(
java.lang.SecurityException: Permission Denial: writing com.android.providers.telephony.SmsProvider uri content://sms/outbox from pid=23774, uid=10308 requires android.permission.WRITE_SMS, or grantUriPermission()
My code:
MainActivity
I want test send sms default from phone number 0901123456 and message "test sent" to my phone.
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
public static final String TAG = MainActivity.class.getName();
public static final int PERMISSION_RESULT_CODE = 123;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupView();
setDefaultApp();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_SMS) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
Manifest.permission.BROADCAST_SMS,
Manifest.permission.READ_SMS,
Manifest.permission.SEND_SMS,
Manifest.permission.RECEIVE_SMS}, PERMISSION_RESULT_CODE);
}
}
}
private void setupView(){
findViewById(R.id.button_draft).setOnClickListener(this);
findViewById(R.id.button_inbox).setOnClickListener(this);
findViewById(R.id.button_outbox).setOnClickListener(this);
findViewById(R.id.button_sent).setOnClickListener(this);
}
private void setDefaultApp(){
final String myPackageName = getPackageName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (!Telephony.Sms.getDefaultSmsPackage(this).equals(myPackageName)) {
Intent intent =
new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
myPackageName);
startActivity(intent);
}
}
}
#Override
public void onRequestPermissionsResult(int requestCode, #NonNull String[] permissions, #NonNull int[] grantResults) {
if (requestCode == PERMISSION_RESULT_CODE){
for (int i= 0; i< permissions.length; i++) {
Log.d(TAG, permissions[i] + " " + grantResults[i]);
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
#Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button_draft:
ContentValues values1 = new ContentValues();
values1.put("address", "0901123456");
values1.put("body", "test draft");
getContentResolver().insert(Uri.parse("content://sms/draft"), values1);
break;
case R.id.button_inbox:
ContentValues values2 = new ContentValues();
values2.put("address", "0901123456");
values2.put("body", "test inbox");
getContentResolver().insert(Uri.parse("content://sms/inbox"), values2);
break;
case R.id.button_outbox:
ContentValues values3 = new ContentValues();
values3.put("address", "0901123456");
values3.put("body", "test outbox");
getContentResolver().insert(Uri.parse("content://sms/outbox"), values3);
break;
case R.id.button_sent:
ContentValues values4 = new ContentValues();
values4.put("address", "0901123456");
values4.put("body", "test sent");
getContentResolver().insert(Uri.parse("content://sms/sent"), values4);
break;
}
}
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
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>
<!-- BroadcastReceiver that listens for incoming SMS messages -->
<receiver
android:name=".SmsReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<!-- BroadcastReceiver that listens for incoming MMS messages -->
<receiver
android:name=".MmsReceiver"
android:permission="android.permission.BROADCAST_WAP_PUSH">
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_DELIVER" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
</receiver>
<receiver
android:name=".FinderReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_SMS">
<intent-filter>
<action
android:name="android.provider.Telephony.SMS_RECEIVED"
android:priority="999" />
</intent-filter>
</receiver>
<!-- Activity that allows the user to send new SMS/MMS messages -->
<activity
android:name=".ComposeSmsActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</activity>
<!-- Service that delivers messages from the phone "quick response" -->
<service
android:name=".HeadlessSmsSendService"
android:exported="true"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="sms" />
<data android:scheme="smsto" />
<data android:scheme="mms" />
<data android:scheme="mmsto" />
</intent-filter>
</service>
</application>
Who can help me? :((
Thank you so much!
You can only write to the SMS provider if your app is the user's chosen SMS client: https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html

How to save data from EditTexts in RecyclerView during screen rotation

I read that EditText doesn't work well with RecyclerView, but I saw an application where it works well (avito). Now I am trying to understand how it was realized there.
I have a fragment with RecyclerView, in recycler view I have EditTexts only in header holder (only one item with EditTexts). In this header I have about five similar EditTexts and TextViews (city,title,description,price etc.) So as not to duplicate the code for all views, I made a custom view class where I located these views, and this class I show below.
public class CustomEditTextView extends LinearLayout implements TextWatcher {
private LayoutInflater inflater;
private TextView textView;
private final EditText editText;
private TextView tvWarning;
private View view;
private String hint;
private String text ;
private String title;
private String warning;
private boolean isNumber = false;
private SpinnerCitySetupListener spinnerCitySetupListener;
public CustomEditTextView(Context context, AttributeSet attrs) {
super(context, attrs);
inflater = LayoutInflater.from(context);
view = inflater.inflate(R.layout.custom_edittext, this, true);
textView = (TextView) view.findViewById(R.id.mycustom_tvTitle);
editText = (EditText) view.findViewById(R.id.mycustom_etTitle);
tvWarning = (TextView) view.findViewById(R.id.mycustom_tvWarning);
textView.setVisibility(GONE);
tvWarning.setVisibility(GONE);
}
public void setCustomVisibility(View view,boolean isVisible){
view.setVisibility(isVisible?VISIBLE:GONE);
}
public void tuningView() {
editText.addTextChangedListener(this);
if(isNumber)editText.setInputType(InputType.TYPE_CLASS_NUMBER);
}
public void setTitle(String title){
textView.setText(title);
this.title = title;
}
public void setHint(String hint){
editText.setHint(hint);
this.hint = hint;
}
public void setWarning(String warning){
tvWarning.setText(warning);
this.warning = warning;
}
public void setText(String text) {
editText.setText(text);
}
public String getText(){
Log.i("CUSTOM VIEW","GET TEXT FROM VIEW: "+ text);
return text;
}
public TextView getTvWarning(){
return tvWarning;
}
public void setInputType(boolean isNumber){
this.isNumber = isNumber;
}
public void setSpinnerCityListener(SpinnerCitySetupListener listener){
spinnerCitySetupListener = listener;
}
//region TextChangedListener
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
text = charSequence.toString();
}
#Override
public void afterTextChanged(Editable editable) {
if (editable.toString().length()!= 0) {
setCustomVisibility(textView,true);
text = editable.toString();
if(spinnerCitySetupListener!= null) spinnerCitySetupListener.spinnerActivation(false);}
else {setCustomVisibility(textView,false);
if(spinnerCitySetupListener!= null) spinnerCitySetupListener.spinnerActivation(true);}
}
//endregion
}
my manifest:`
<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.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<!-- <uses-permission android:name="android.permission.SEND_SMS"/>-->
<permission
android:name="com.android.qrz.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.android.qrz.gcm.permission.C2D_MESSAGE" />
<uses-feature android:name="android.hardware.camera" android:required="true" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:name="android.support.multidex.MultiDexApplication"
android:allowBackup="true"
android:icon="#drawable/qrz_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<!--android:name=".QRZApp"-->
<meta-data
android:name="AA_DB_NAME"
android:value="QRZ.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="1" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyBlOgCglvJdnPS476oiF4MRAo3pV3nQ8w8"/>
<receiver
android:name=".receiver.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.android.qrz.receiver" />
</intent-filter>
</receiver>
<receiver
android:name=".receiver.InternetCheckReceiver"
android:label="NetworkConnection" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<service
android:name=".services.GCMIntentService"
android:process=":remote" />
<activity
android:name=".activity.SplashScreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--<activity-->
<!--android:name=".activity.main_menu.MainMenu"-->
<!--android:label="#string/title_activity_menu" >-->
<!--</activity>-->
<activity
android:name=".activity.main_menu.NewMainMenu"
android:label="#string/title_activity_menu" >
</activity>
<activity
android:name=".activity.LoginActivity"
android:label="#string/title_activity_login" >
</activity>
<!--<activity-->
<!--android:name=".activity.Registration"-->
<!--android:label="#string/title_activity_registration" >-->
<!--</activity>-->
<activity
android:name=".activity.registration.NewRegistration"
android:label="#string/title_activity_registration" >
</activity>
<activity
android:name=".activity.News"
android:label="#string/title_activity_news" >
</activity>
<activity
android:name=".activity.news.DetailNewsActivity"
android:label="#string/title_activity_news" >
</activity>
<!--<activity-->
<!--android:name=".activity.Callbook"-->
<!--android:label="#string/title_activity_callbook" >-->
<!--</activity>-->
<activity
android:name=".activity.NewCallbook"
android:label="Callbook" >
</activity>
<activity
android:name=".activity.PhotoGallery"
android:label="#string/title_activity_photo_gallery" >
</activity>
<!--<activity
android:name=".activity.DiplomsActivity"
android:label="#string/title_activity_diploms" >
</activity>-->
<activity
android:name=".activity.new_diploms.ui.MainDiplomActivity"
android:label="#string/title_activity_new_diploms" >
</activity>
<activity
android:name=".activity.new_diploms.ui.detail_diplom.DiplomDetailActivity"
android:label="#string/title_activity_new_detail_diploms" >
</activity>
<activity
android:name=".activity.new_diploms.ui.searching.SearchingActivity"
android:label="#string/title_activity_searching_diploms" >
</activity>
<activity
android:name=".activity.BirthdaysActivity"
android:label="#string/title_activity_birthdays" >
</activity>
<activity
android:name=".activity.competitions.CompetitionsActivity"
android:label="#string/title_activity_competitions" >
</activity>
<activity
android:name=".activity.DXActivity"
android:label="#string/title_activity_DX" >
</activity>
<activity
android:name=".activity.DXDetailActivity"
android:label="#string/title_activity_DX_detail" >
</activity>
<activity
android:name=".activity.base_of_frequency.BaseFrequencyActivity"
android:label="#string/title_activity_frequency" >
</activity>
<activity
android:name=".activity.qsl.QslActivity"
android:label="#string/title_activity_qsl" >
</activity>
<activity
android:name=".activity.qsl.QSLSearching"
android:label="#string/title_activity_qsl_searching" >
</activity>
<activity
android:name=".activity.declarations.BillboardActivity"
android:label="#string/title_activity_billboard" >
</activity>
<activity
android:name=".activity.declarations.SearchingFilterActivity"
android:label="#string/title_activity_filters_for_search"
>
</activity>
<activity
android:name=".activity.declarations.NewSearchingDeclarationActivity"
android:label="#string/title_activity_searching_declaration" >
</activity>
<activity
android:name=".activity.declarations.ListDeclarationsActivity"
android:label="#string/title_activity_list_declarations" >
</activity>
<activity
android:name=".activity.declarations.DeclarationDetailActivity"
android:label="#string/title_activity_declaration_detail" >
</activity>
<activity
android:name=".activity.personal_activity.PersonalActivity"
android:label="#string/title_activity_personal" >
<intent-filter>
<action android:name="android.intent.action.PICK"></action>
</intent-filter>
</activity>
<activity
android:name=".activity.personal_activity.create_declaration.CreateDeclarationActivity"
android:label="#string/title_activity_create_declaration" >
</activity>
<activity
android:name=".activity.personal_activity.create_qsl_manager.CreateQSLManagerActivity"
android:label="#string/title_activity_create_qsl" >
</activity>
<activity
android:name=".activity.personal_activity.create_dx_reporter.CreateDXReporterActivity"
android:label="#string/title_activity_create_dx_reporter" >
</activity>
<activity
android:name=".activity.personal_activity.create_frequency.CreateFrequencyActivity"
android:label="#string/title_activity_create_frequency" >
</activity>
<activity
android:name=".activity.personal_activity.settings.PersonalSettingsActivity"
android:label="#string/title_activity_settings" >
</activity>
<activity
android:name=".activity.ForumActivity"
android:label="#string/title_activity_forum" >
</activity>
<activity
android:name=".activity.AboutAppActivity"
android:label="#string/title_activity_about_app" >
</activity>
<service
android:name=".rest_service.rest.RestService"
android:enabled="true"
android:exported="true" >
</service><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
`
My problem is variable "text" in afterTextChanged or in onTextChanged "text" is not empty, in this part of code all works well, but when I want to get this text from my headerHolder I calling customView.getText() for sending this data in fragment for OnSavedInstance and this variable "text" become null, but EditText contains text all this time, why does this happen?

Push notification is not working using parse.com android?

I have created simple push notification app using parse.com.
devices registered successfully on parse.com but when i try to send push notification through parse.com no notification have come.
AndroidMainifest.xml Code:
<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.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</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" />
<category android:name="com.parse.starter" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
Reciever Code:
public class Receiver extends ParsePushBroadcastReceiver {
private Intent parseIntent;
public Receiver() {
super();
}
#Override
protected void onPushReceive(Context context, Intent intent) {
super.onPushReceive(context, intent);
if (intent == null)
return;
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
parseIntent = intent;
} catch (JSONException e) {
Log.d("PushJsonException", "" + e.getMessage());
}
}
}
MainActivity Code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Call Methods to Update Your Stuff
}
};
#Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, new IntentFilter("com.example.harrypotter.pushnotificationdemo"));
}
#Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(mBroadcastReceiver);
}
Application Class :
public class ParseApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(this);
ParseInstallation.getCurrentInstallation().saveInBackground();
}
}
You have not changed the Category attribute in your Manifest file:
<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.GET_ACCOUNTS" />
<permission android:protectionLevel="signature"
android:name="com.parse.starter.permission.C2D_MESSAGE" />
<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParsePushBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
to match your app's package name + ".permission.C2D_MESSAGE".
<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" />
<category android:name="YOUR PACKAGE NAME" />
</intent-filter>
</receiver>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="" />
Parse.com Hosted Service is fully retiring on January 28, 2017. If you have an existing application, refer to this link and create your own push notification server. Parse release a database migration tool that lets you migrate data from your Parse app to any MongoDB database.
For More Information Check The LInk

I got below error when impliment GCM

i have try to implement GCM in android studio got below error in my logcat.
LogCat:
onReceive: com.google.android.c2dm.intent.REGISTRATION GCM
IntentService class: com.project.GCMIntentService Acquiring wakelock
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project">
<permission
android:name="com.project.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" ></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.project.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_SYNC_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.project.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.project.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<application
android:name="com.project.App"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/AppTheme">
<activity
android:name=".SplashScreenActivity"
android:screenOrientation="portrait"
android:theme="#style/FullScreenThemes">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.project.core.account.ManageAccounts" />
<activity android:name=".projectActivity"/>
<activity android:name=".projectLogin"/>
<activity android:name="fieldatom.controls.SearchableItemActivity" />
<activity android:name="com.project.SettingsActivity" />
<activity
android:name="com.project.core.account.AppIntro"
android:screenOrientation="portrait" />
<activity
android:name=".base.addons.mail.widget.MailDetailDialog"
android:theme="#style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".base.addons.mail.widget.MailChatterCompose"
android:theme="#style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".core.account.FieldAtomAccountQuickManage"
android:theme="#style/Theme.AppCompat.Light.Dialog"
android:windowSoftInputMode="adjustPan" />
<activity android:name="com.project.core.account.About" />
<activity android:name="com.project.core.account.Profile" />
<!-- Reminder Receivers// -->
<receiver android:name="com.project.core.utils.reminder.ReminderReceiver" />
<receiver android:name="com.project.core.utils.reminder.ReminderActionReceiver" />
<!--<receiver android:name=".server.notifications.OdooServerNotificationReceiver">
<intent-filter>
<action android:name="com.project.odoo.mobile.SERVER_NOTIFICATION" />
</intent-filter>
</receiver>-->
<service android:name="com.project.core.auth.OdooAuthService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="#xml/authenticator" />
</service>
<provider
android:name="com.project.core.orm.provider.BaseModelProvider"
android:authorities="com.project.core.provider.content"
android:multiprocess="true" />
<provider
android:name="com.project.base.addons.ir.providers.IrModelProvider"
android:authorities="com.project.core.provider.content.sync.ir_model"
android:multiprocess="true" />
<!-- Sync Customer Provider & Service // -->
<provider
android:name="com.project.addons.customers.providers.CustomersSyncProvider"
android:authorities="com.project.core.provider.content.sync.res_partner"
android:label="#string/sync_label_customers"
android:multiprocess="true" />
<service
android:name="com.project.addons.customers.services.CustomerSyncService"
android:exported="true"
android:process=":sync_customer">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/customer_sync_adapter" />
</service>
<!-- Sync Request Provider & Service // -->
<provider
android:name="com.project.addons.requests.providers.RequestSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_service_request"
android:label="#string/sync_label_request"
android:multiprocess="true" />
<service
android:name="com.project.addons.requests.services.RequestSyncService"
android:exported="true"
android:process=":sync_request">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/request_sync_adapter" />
</service>
<!-- Sync Stage Provider & Service // -->
<provider
android:name="com.project.addons.stages.providers.StageSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_service_stage"
android:label="#string/sync_label_stages"
android:multiprocess="true" />
<service
android:name="com.project.addons.stages.services.StageSyncService"
android:exported="true"
android:process=":sync_stage">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/stage_sync_adapter" />
</service>
<!-- Sync Account Analytic Provider & Service // -->
<provider
android:name="com.project.addons.accountanalytics.providers.AccountAnalyticSyncProviders"
android:authorities="com.project.core.provider.content.sync.account_analytic_line"
android:label="#string/sync_label_accountAnalytic"
android:multiprocess="true" />
<service
android:name="com.project.addons.accountanalytics.services.AccountAnalyticSyncService"
android:exported="true"
android:process=":sync_account_analytic">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/account_analytic_sync_adapter" />
</service>
<!-- Sync Product Provider & Service // -->
<provider
android:name=".addons.products.providers.ProductsSyncProviders"
android:authorities="com.project.core.provider.content.sync.product_product"
android:label="#string/sync_label_product"
android:multiprocess="true" />
<service
android:name=".addons.products.service.ProductsSyncService"
android:exported="true"
android:process=":sync_account_analytic">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/product_sync_adapter" />
</service>
<!-- Sync QUOTATION Provider & Service // -->
<provider
android:name=".addons.quotes.providers.QuotationSyncProviders"
android:authorities="com.project.core.provider.content.sync.sale_order"
android:label="#string/sync_label_quotation"
android:multiprocess="true" />
<service
android:name=".addons.quotes.services.QuotationSyncService"
android:exported="true"
android:process=":sync_quotation">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/quote_sync_adapter" />
</service>
<!-- Sync QUOTATIONLine Provider & Service // -->
<provider
android:name=".addons.quotes.providers.QuotationLineSyncProviders"
android:authorities="com.project.core.provider.content.sync.sale_order_line"
android:label="#string/sync_label_quotation_line"
android:multiprocess="true" />
<service
android:name=".addons.quotes.services.QuotationLineSyncService"
android:exported="true"
android:process=":sync_quotation_line">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/quote_line_sync_adapter" />
</service>
<!-- Sync Attachment Provider & Service // -->
<provider
android:name=".addons.attachment.providers.IrAttachmentSyncProviders"
android:authorities="com.project.core.provider.content.sync.ir_attachment"
android:label="#string/sync_label_attachment"
android:multiprocess="true" />
<service
android:name=".addons.attachment.service.IrAttachmentSyncService"
android:exported="true"
android:process=":sync_attachment">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/attachment_sync_adapter" />
</service>
<!-- Sync MailMessage Provider & Service // -->
<provider
android:name=".base.addons.mail.providers.MailMessageSyncProviders"
android:authorities="com.project.core.provider.content.sync.mail_message"
android:label="#string/sync_label_mail_message"
android:multiprocess="true" />
<service
android:name=".base.addons.mail.service.MailMessageSyncService"
android:exported="true"
android:process=":sync_mail_message">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/mail_message_sync_adapter" />
</service>
<!-- Sync Maps Provider & Service // -->
<provider
android:name=".addons.maps.providers.MapsSyncProviders"
android:authorities="com.project.core.provider.content.sync.fa_map"
android:label="#string/sync_label_map_message"
android:multiprocess="true" />
<service
android:name=".addons.maps.service.MapsSyncService"
android:exported="true"
android:process=":sync_map">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data
android:name="android.content.SyncAdapter"
android:resource="#xml/maps_sync_adapter" />
</service>
<service android:name=".addons.requests.services.TimeUpdateService"></service>
<activity
android:name="com.project.addons.customers.CustomerDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan" />
<activity
android:name=".addons.requests.utils.RequestTabDetailAcitivty"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden|adjustPan"
/>
<activity
android:name=".addons.accountanalytics.VisitDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:theme="#style/CustomActionBar"
android:windowSoftInputMode="stateHidden" />
<activity
android:name=".addons.accountanalytics.CreateVisitActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddPartActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddNoteActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.AddQuoteActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.utils.CaptureSignature"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.requests.utils.ProductRequestListActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.quotes.QuoteDetailActivity"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<activity
android:name=".addons.products.ProductDetails"
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
android:windowSoftInputMode="stateHidden"></activity>
<!-- Map Related Metadata -->
<uses-library
android:name="com.google.android.maps"
android:required="false" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCpjJtPYoeVN2dGqCVMCDEoR847OEwzgME" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<!-- Push Notification -->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.project" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService"></service>
</application>
<!--CB:A6:E7:26:97:08:37:4A:D6:60:1B:9B:2C:D0:9A:3B:9F:DF:02:D3;com.project-->
</manifest>
This is my project structure details below.
com.projcet
App.java
ProjcetLogin.java
GCMIntentService.java
This code working perfect in eclipse & android studio...finally i can do it.
MainActivity.java
public class MainActivity extends Activity implements View.OnClickListener{
//Notification Constant
Context context;
Button btn_GCMRegister, btn_Post;
GoogleCloudMessaging gcm;
public static String URL = "192.168.1.39:12069";
String regId;
public final String GOOGLE_PROJECT_ID = "your project id";
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = getApplicationContext();
init();
}
private void init() {
btn_GCMRegister = (Button) findViewById(R.id.btn_gcm_register);
btn_GCMRegister.setOnClickListener(this);
btn_Post = (Button) findViewById(R.id.btn_post_on_server);
btn_Post.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.btn_gcm_register:
registerGCM();
break;
case R.id.btn_post_on_server:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Map<String, Object> params = new HashMap<String, Object>();
params.put("regId", regId);
params.put("user_id", 1);
String server_url = URL;
try {
post(server_url, params);
}catch (IOException e){
e.printStackTrace();
}
break;
default:
break;
}
}
/*
* Issue a POST request to the server.
*/
private static void post(String endpoint, Map<String, Object> params)
throws IOException {
URL url;
try {
url = new URL(endpoint);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("invalid url: " + endpoint);
}
StringBuilder bodyBuilder = new StringBuilder();
Iterator<Map.Entry<String, Object>> iterator = params.entrySet().iterator();
// constructs the POST body using the parameters
while (iterator.hasNext()) {
Map.Entry<String, Object> param = iterator.next();
bodyBuilder.append(param.getKey()).append('=')
.append(param.getValue());
if (iterator.hasNext()) {
bodyBuilder.append('&');
}
}
String body = bodyBuilder.toString();
//Log.v(Config.TAG, "Posting '" + body + "' to " + url);
byte[] bytes = body.getBytes();
HttpURLConnection conn = null;
try {
Log.e("URL", "> " + url);
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setFixedLengthStreamingMode(bytes.length);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded;charset=UTF-8");
// post the request
OutputStream out = conn.getOutputStream();
out.write(bytes);
out.close();
// handle the response
int status = conn.getResponseCode();
System.out.println("Json Data--->" + status);
// If response is not success
if (status != 200) {
throw new IOException("Post failed with error code " + status);
}
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
private void registerGCM() {
// TODO Auto-generated method stub
new AsyncTask<Void, Void, String>() {
#Override
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regId = gcm.register(GOOGLE_PROJECT_ID);
Log.d("Reg Id----->", "" + regId);
Toast.makeText(MainActivity.this,"Register Key from server : " +regId,Toast.LENGTH_LONG).show();
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
Log.d("MainActivity", "Error: " + msg);
}
Log.d("MainActivity", "AsyncTask completed: " + msg);
return msg;
}
#Override
protected void onPostExecute(String msg) {
Toast.makeText(getApplicationContext(),
"Registered On GCM Server." + msg, Toast.LENGTH_LONG)
.show();
}
}.execute(null, null, null);
}
}
GCMIntentService.java
public class GCMIntentService extends GCMBaseIntentService {
#Override
protected void onError(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onError", "gcm...error");
}
public GCMIntentService() {
super("your project id");
}
#Override
protected String[] getSenderIds(Context context) {
return super.getSenderIds(context);
}
#Override
protected void onMessage(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i(TAG, "Received message");
if (intent.getExtras() != null) {
String message = intent.getExtras().getString("message");
String title = intent.getExtras().getString("title");
String ticker = intent.getExtras().getString("ticker");
generateNotification(context,message,title,ticker);
}
}
#Override
protected void onRegistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onRegistered", "gcm Registered");
}
#Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
Log.e("onUnregistered", "gcm...Unregistered...");
}
/**
* Create a notification to inform the user that server has sent a message.
*/
#TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void generateNotification(Context context, String message,String title,String ticker) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
Intent notificationIntent = new Intent(context, MainActivity.class);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
builder.setContentTitle(title)
.setContentText(message)
.setLargeIcon(
BitmapFactory.decodeResource(context.getResources(),
icon))
.setStyle(new Notification.BigTextStyle().bigText(message))
.setContentIntent(intent).setSmallIcon(icon).setTicker(ticker)
.setLights(0xff00ff00, 300, 100)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE).setAutoCancel(true).setWhen(when);
Notification notification = builder.build();
notificationManager.notify(0, notification);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.xxx.gcmnotification" >
<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.example.xxx.gcmnotification.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.xxx.gcmnotification.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<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="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.xxx.gcmnotification" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
build.gradle(Module:app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:+'
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<Button
android:id="#+id/btn_gcm_register"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Register On GCM Server" />
<Button
android:id="#+id/btn_post_on_server"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text="Post On Server" />
</LinearLayout>

Categories

Resources