Skip to content

Commit 2dd06e1

Browse files
committed
Enabling User to sent Whatsapp messages to numbers not saved in contact list.
This is final version of the app
1 parent 9ac8153 commit 2dd06e1

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

OpenInWhatsapp/.idea/jarRepositories.xml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OpenInWhatsapp/app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99
android:roundIcon="@mipmap/ic_launcher_round"
1010
android:supportsRtl="true"
1111
android:theme="@style/Theme.OpenInWhatsapp">
12-
<activity android:name=".MainActivity">
12+
<activity android:name=".MainActivity" android:theme="@style/Theme.OpenInWhatsapp">
13+
<intent-filter>
14+
<action android:name="android.intent.action.PROCESS_TEXT"/>
15+
<category android:name="android.intent.category.DEFAULT"/>
16+
<data android:mimeType="text/plain"/>
17+
</intent-filter>
1318
<intent-filter>
1419
<action android:name="android.intent.action.MAIN" />
1520

1621
<category android:name="android.intent.category.LAUNCHER" />
1722
</intent-filter>
23+
1824
</activity>
1925
</application>
2026

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
package com.example.android.openinwhatsapp
22

3+
import android.content.Intent
4+
import android.net.Uri
35
import androidx.appcompat.app.AppCompatActivity
46
import android.os.Bundle
7+
import android.widget.Toast
8+
import androidx.core.text.isDigitsOnly
59

610
class MainActivity : AppCompatActivity() {
711
override fun onCreate(savedInstanceState: Bundle?) {
812
super.onCreate(savedInstanceState)
913
setContentView(R.layout.activity_main)
14+
var number : String = "0"
15+
if(intent.action == Intent.ACTION_PROCESS_TEXT){
16+
number =intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT).toString()
17+
}
18+
if(number.isDigitsOnly()){
19+
startWhatsapp(number)
20+
}else{
21+
Toast.makeText(this,"Please Check The Number",Toast.LENGTH_SHORT).show()
22+
}
23+
}
24+
25+
private fun startWhatsapp(number: String) {
26+
val intent = Intent(Intent.ACTION_VIEW)
27+
intent.setPackage("com.whatsapp")
28+
val data : String = if (number[0] == '+'){
29+
number.substring(startIndex = 1)
30+
}else if(number.length ==10){
31+
"91 $number"
32+
}else{
33+
number
34+
}
35+
intent.data = Uri.parse("https://wa.me/$data")
36+
if(packageManager.resolveActivity(intent,0) != null){
37+
startActivity(intent)
38+
}else{
39+
Toast.makeText(this,"Please install Whatsapp",Toast.LENGTH_SHORT).show()
40+
}
41+
finish()
1042
}
1143
}

OpenInWhatsapp/app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10+
<color name="transparent">#00FFFFFF</color>
1011
</resources>

OpenInWhatsapp/app/src/main/res/values/themes.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,11 @@
1212
<!-- Status bar color. -->
1313
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
1414
<!-- Customize your theme here. -->
15+
<item name="android:windowIsTranslucent">true</item>
16+
<item name="android:windowBackground">@color/transparent</item>
17+
<item name="android:windowContentOverlay">@null</item>
18+
<item name="windowNoTitle">true</item>
19+
<item name="android:backgroundDimEnabled">false</item>
1520
</style>
21+
1622
</resources>

0 commit comments

Comments
 (0)