java part one :
package first.learn.datapassingtwo;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.gson.Gson;
import first.learn.datapassingtwo.Person.PersonModel;
public class MainActivity extends AppCompatActivity {
public static String SIMPLE_STRING = null;
public static int SIMPLE_INT = -0;
EditText etOne, etTwo ,etThree,
etFour, etSix,
etFive;
Button btnSimpleInt,
btnSimpleString;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etOne = (EditText) findViewById(R.id.etOne);
etTwo = (EditText) findViewById(R.id.etTwo);
btnSimpleInt = (Button)findViewById(R.id.btnSimpleInt);
btnSimpleString = (Button)findViewById(R.id.btnSimpleString);
etThree = (EditText)findViewById(R.id.etThree);
etFour = (EditText)findViewById(R.id.etFour);
etSix= (EditText)findViewById(R.id.etSix);
etFive= (EditText)findViewById(R.id.etFive);
btnSimpleString.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = etOne.getText().toString();
if(TextUtils.isEmpty(name)){
etOne.setError("Empty");
return;
}
etOne.setError(null);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("####://"+name);
intent.setData(data);
startActivity(intent);
}
});
btnSimpleInt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s = etTwo.getText().toString();
if(TextUtils.isEmpty(s)){
etTwo.setError("Empty");
return;
}
etTwo.setError(null);
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("#####://myhost/"+s);
intent.setData(data);
startActivity(intent);
}
});
}
}
xml part one :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:layout_margin="16dp">
<EditText
android:hint="only by Scheme......"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etOne"/>
<EditText
android:visibility="gone"
android:hint="age....."
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etThree"/>
<EditText
android:visibility="gone"
android:hint="address....."
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etFive"/>
<EditText
android:visibility="gone"
android:hint="MobileNumber.....(optional)"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etSix"/>
<Button
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnSimpleString"
android:text="Data passing with Manifest Scheme"/>
<EditText
android:hint="Scheme and Host ....."
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etTwo"
/>
<EditText
android:visibility="gone"
android:hint="Simple int ....."
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/etFour"
android:inputType="number"/>
<Button
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnSimpleInt"
android:text="Data Passing By Scheme And Host "/>
</LinearLayout>
java part two :
package first.learn.datapassingtwo;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class DataGettingByManifestOnlyScheme extends AppCompatActivity {
TextView tvShow ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_getting_by_manifest_only_scheme);
tvShow = (TextView) findViewById(R.id.tvShow);
if(getIntent()!=null){
if(getIntent().getData()!=null){
Uri data = getIntent().getData();
String host = data.getHost();
System.out.println("Only Scheme Host : "+ host);
tvShow.setText(host);
}
}
}
}
xml part two :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DataGettingByManifestOnlyScheme"
android:orientation="vertical">
<TextView
android:hint="data....."
android:layout_marginTop="25dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/purple_700"
android:textSize="25dp"
android:id="@+id/tvShow"/>
</LinearLayout>
java part three :
package first.learn.datapassingtwo;
import androidx.appcompat.app.AppCompatActivity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;
public class DataGettingBySchemeAndHost extends AppCompatActivity {
TextView tvShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_getting_by_scheme_and_host);
tvShow = (TextView) findViewById(R.id.tvShow);
if(getIntent()!=null){
if(getIntent().getData()!=null){
Uri data = getIntent().getData();
String myString = data.getLastPathSegment();
System.out.println("Scheme and Host : "+ myString);
tvShow.setText(myString);
}
}
}
}
xml part three :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DataGettingBySchemeAndHost"
android:orientation="vertical">
<TextView
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/purple_700"
android:textSize="25dp"
android:id="@+id/tvShow"/>
</LinearLayout>
Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.DataPassingTwo"
tools:targetApi="31">
<activity
android:name=".DataGettingBySchemeAndHost"
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="#####"
android:host="myhost"/>
</intent-filter>
</activity>
<activity
android:name=".DataGettingByManifestOnlyScheme"
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="####" />
</intent-filter>
</activity>
<activity
android:name=".DataGettingActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
No comments:
Post a Comment