How can I create a project in Android Studio to function default SMS app - broadcastreceiver

Continuation of the previous query, see: SMS Receiver for AND API 19 and higher
I need to make the application run in the background and I could have it after installing the set as a default as shown here: http://android-developers.blogspot.cz/2013/10/getting-your-sms-apps-ready-for-kitkat.html
So I asked how to create a project to display a list of the "Super Duper SMS," which finally set as default.
The whole program must running as a service, without the need any screen for basic functions Receive SMS and should be registered in the core android
Thanks for any advice

I am tried with this code it help me...
manifests.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsmsapp">
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/smsicon"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.example.newsmsapp.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity android:name="com.example.newsmsapp.ComposeSMS">
<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"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.LAUNCHER" />
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</activity>
<receiver
android:name="com.example.newsmsapp.SMSReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
<activity
android:name="com.example.newsmsapp.NotificationView"
android:label="#string/title_activity_notification_view"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<receiver android:name="com.example.newsmsapp.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>
<service android:name="com.example.newsmsapp.HandlessSMSSendService"
android:exported="true"
android:permission="android.permission.SEND_RESPOND_VIA_MESSAGE">
<intent-filter>
<action android:name="android.intent.action.RESPOND_VIA_MESSAGE"/>
<data android:scheme="sms"/>
<data android:scheme="smsto"/>
<data android:scheme="mms"/>
<data android:scheme="mmsto"/>
</intent-filter>
</service>
</application>
then create 4 file for smsReader,mmsReader,ComposeSMS,HeadlessSMSservice
smsReader.java
public class SMSReceiver extends BroadcastReceiver {
Notification notification;//=new Notification(R.drawable.icon,"New Message",System.currentTimeMillis());
NotificationManager notificationmaneger;
String SMSmsg;
public SMSReceiver() {
}
public static final String SMS_BUNDLE = "pdus";
#Override
public void onReceive(Context context, Intent intent) {
Bundle intentExtras = intent.getExtras();
if (intentExtras != null) {
Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE);
String smsMessageStr = "";
for (int i = 0; i < sms.length; ++i) {
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String smsBody = smsMessage.getMessageBody().toString();
String address = smsMessage.getOriginatingAddress();
smsMessageStr += "SMS From: " + address + "\n";
smsMessageStr += smsBody + "\n";
builder.setAutoCancel(true);
// builder.setTicker("this is ticker text");
builder.setContentTitle("New Messge");
builder.setContentText(SMSmsg);
builder.setSmallIcon(R.drawable.smsicon);
builder.setColor(context.getResources().getColor(R.color.colorAccent));
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
// builder.setSubText("You have pending tax"); //API level 16
//builder.setNumber(100);
builder.build();
}
SMSmsg=smsMessageStr;
}
}
mmsReader.java
public class MMSReceiver extends BroadcastReceiver
{
public MMSReceiver()
{
}
#Override
public void onReceive(Context context, Intent intent) {
}
}
ComposeSMS.java
public class ComposeSMS extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
}
}
HeadlessSMSservices.java
public class HandlessSMSSendService extends Service {
#Nullable
#Override
public IBinder onBind(Intent intent) {
return null;
}
}
if u want to see SMS then add listview in composeSMS.java and bind received data from sms table to listview adapter.

Related

Deep Link for Android with .Net Maui error - Unable to instantiate activity ComponentInfo MainActivity

I'm trying to get deep links to work for my maui android app but when I click to open the link with the app I get this error:
Java.Lang.RuntimeException: 'Unable to instantiate activity ComponentInfo{app.mydomain/MyApp.Client.MAUI.MainActivity}:
java.lang.ClassNotFoundException: Didn't find class "MyApp.Client.MAUI.MainActivity"
on path: DexPathList[[zip file "/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk"],
nativeLibraryDirectories=[/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/lib/arm64,
/data/app/~~0C9vYHAHNOr9CaB4f63clQ==/app.mydomain-YYQ6ZPc3-KSVnF8_VcuQVQ==/base.apk!/lib/arm64-v8a, /system/lib64,
/system_ext/lib64]]'
My MainActivity.cs looks like this
namespace MyApp.Client.MAUI
{
[Activity(Theme = "#style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
[IntentFilter(new[] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "https", DataHost = "mydomain.app", DataPathPattern = "/.*", AutoVerify = true)]
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
protected override void OnResume()
{
base.OnResume();
Platform.OnResume(this);
}
protected override void OnNewIntent(Intent intent)
{
base.OnNewIntent(intent);
var data = intent.DataString;
if (intent.Action != Intent.ActionView) return;
if (string.IsNullOrWhiteSpace(data)) return;
var path = data.Replace(#"https://mydomain.app", "");
//todo - handle path
StartActivity(typeof(MainActivity));
}
}
The intent filter in the AndroidManifest.xml is like so:
<activity android:name="MyApp.Client.MAUI.MainActivity" android:exported="true">
<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="https" android:host="mydomain.app" android:pathPattern="/.*" />
</intent-filter>
</activity>
I could reproduce your problem.
And I can resolve this problem by adding tag <application> inside of AndroidManifest.xml.
You can refer to the full code of AndroidManifest.xml on my side:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.INTERNET" />
      <application android:allowBackup="true" android:supportsRtl="true" android:theme="#style/AppTheme" android:name="android.app.Application" android:debuggable="true" android:extractNativeLibs="true">
            <activity android:name="MauiBlazorApp.MainActivity" android:exported="true">
                  <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="https" android:host="mydomain.app" android:pathPattern="/.*" />
                  </intent-filter>
            </activity>
            
      </application>
</manifest>
Note: Remember to change the value of android:name(YourAppName) of your activity to yours.
<application android:name="YourAppName.MainActivity">

share list of Images from gallery and any type of files from outside our application:

I'm trying to share a list of images from the gallery into my app to use it recycler view
or any thing else
<activity
android:icon="#mipmap/ic_launcher"
android:name=".MainActivity"
>
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
that works:-
1-specify these lines on the manifest
<activity
android:icon="#mipmap/ic_launcher"
android:name=".MainActivity"
>
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="*/*"/>
<data android:mimeType="image/jpeg" />
<data android:mimeType="image/png" />
<data android:mimeType="image/jpg" />
</intent-filter>
</activity>
2-Second get the action that opened your intent and check if its the one we registered for the activity and then the data is received as ArrayList of Uri
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
if (Intent.ACTION_SEND_MULTIPLE.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
ArrayList<Uri> urisArrayList = extras.getParcelableArrayList(Intent.EXTRA_STREAM);
urisArrayList.forEach(i-> Log.d(TAG, "onCreate: "+i.toString()));
}
}}

Received BOOT broadcast but cannot start Service

I want to make my application's background service start when the device is on, So I make a BOOT receiver to start my service.
Here is My Mainifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<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/Theme.MyApplication">
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here is THE boot receiver:
package com.example.myapplication
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
// This method is called when the BroadcastReceiver is receiving an Intent broadcast.
Log.d("NEWTAG","BOOT is ON!!!!!")
val startIntent = Intent(context,MyService::class.java)
context.startService(startIntent)
Log.d("NEWTAG","SERVICE IS ON!!!!!")
}
}
This is My Service:
package com.example.myapplication
import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.util.Log
class MyService : Service() {
override fun onBind(intent: Intent): IBinder {
TODO("Return the communication channel to the service.")
}
override fun onCreate() {
super.onCreate()
Log.d("NEWTAG","Service OnCreate!!!!!")
}
override fun onDestroy() {
Log.d("NEWTAG","Service OnCreate!!!!!")
super.onDestroy()
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Log.d("NEWTAG","Service OnCreate!!!!!")
return START_STICKY
}
override fun onTaskRemoved(rootIntent: Intent?) {
super.onTaskRemoved(rootIntent)
Log.d("NEWTAG","Service OnCreate!!!!!")
}
}
I can get the
BOOT is ON!!!!!
from the receiver, But I cannot get the
Service OnCreate!!!!!
And the serivce's OnCreate() and OnStartCommand() did not run either.
Can anybody do me a favour?
Your BroadcastReceiver might not be starting after boot. Please check.

Android Facebook Login button XML error

I want to create a test project works 'facebook login'.
I made with reference to the developers site and blog equal, But I met with an error message on xml.
[error massage]
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.facebooktest.zoit.facebooktest/com.facebooktest.zoit.facebooktest.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.facebook.login.widget.LoginButton
[xml]
<com.facebook.login.widget.LoginButton
android:id="#+id/facebook_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp" />
[Manifest]
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.facebooktest.zoit.facebooktest">
<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"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name"
android:theme="#android:style/Theme.Translucent.NoTitleBar" />
</manifest>
[MainActivity]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
facebookLoginButton.registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {...
...
public void onActivityResult(...
void geHashKey(){...
void geHashKey(){ ...
public void onResume(){ ...
public void onPause(){...
Do you know what's wrong? please help.
I know!
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
setContentView(R.layout.activity_main);
"setContentView(R.layout.activity_main);"
I succeeded to move the this code below to Facebook code.

how to open different activities when receiving notification from parse

I have different categories in my app such as news,weather,sports and technology,I use parse to receive notification ,but i want the notification to be customized in which once a notification regarding news is received it should open news activity,if notification regarding technology is received it should open technology activity.
I don't want custom push receiver,i tried lots of examples but i can't get it.any ideas thanks in advance
First you need to create a custom class that extends ParsePushBroadcastReceiver.
and in that class you Override onPushOpen method:
public class ParsePushCustomReceiver extends ParsePushBroadcastReceiver {
protected static String pushTitle="";
#Override
protected void onPushOpen(Context context, Intent intent) {
super.onPushOpen(context, intent);
pushTitle="";
try {
Bundle extras = intent.getExtras();
if (extras != null) {
String jsonData = extras.getString("com.parse.Data");
JSONObject json;
json = new JSONObject(jsonData);
pushTitle = json.getString("title");
String pushContent = json.getString("alert");
//intent to your activity
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Now when you have the title and the content of the push you can direct to the activity that you want to go...
You need to define your custom ParsePushBroadcastReceiver as reciever in AndroidManifest.xml:
<!-- Parse PushService-->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver
android:name="com.appname.appname.ParsePushCustomReceiver"
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.appname.appname" />
</intent-filter>
</receiver>