Я работаю над своим мобильным приложением и пытаюсь отправить данные (текст) из моего гостевого приложения в мое приложение администратора. Эти приложения являются двумя отдельными проектами в android studio, и я получаю сообщение об ошибке на гостевой стороне приложения, которое сообщает error: cannot find symbol variable txt
, где, как и в моем приложении администратора, я получаю другую ошибку, сообщающую Error running 'app': Default Activity not found
, которую я предполагаю, что должен сделать с файлом манифеста приложений администратора.
Это мой код гостевого приложения, из которого исходит ошибка txt.
package com.example.prototype;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class CleaningService extends AppCompatActivity implements
View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cleaning_service);
getSupportActionBar().setTitle("Cleaning Service");
Button button5 = findViewById(R.id.button5);
button5.setOnClickListener(this);
}
@Override
public void onClick (View v) {
switch (v.getId()) {
case R.id.button5:
Toast.makeText(this, "Message sent succesfully", Toast.LENGTH_SHORT ).show();
break;
}
}
public void sendMessage(View v)
{
String message;
message = ((TextView)v).getText().toString();
Intent i = new Intent();
i.setAction(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_TEXT, message);
i.setType("text/plain");
startActivity(i);
}
}
Это ошибка из моего проекта приложения администратора. Androidmanifest. xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.prototypeadmin">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".GuestTab"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
<activity
android:name=".guestrequest"
android:label="@string/title_activity_guestrequest"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".AdminMenu"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
<activity
android:name=".GuestRequests"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" />
<activity
android:name=".MainActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<data android:mimeType="text/plain"/>
</intent-filter>
</activity>
</application>
Код приложения администратора:
package com.example.prototypeadmin;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabItem;
import com.google.android.material.tabs.TabLayout;
public class GuestTab extends AppCompatActivity {
private TabLayout tabLayout;
private ViewPager viewPager;
private TabItem tab1, tab2, tab3;
public PageAdapter pageradapter;
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_guest_tab);
txt = (TextView) findViewById(R.id.txt);
Intent i = getIntent(); // added object intent to receive data
String action = i.getAction();
String type = i.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) // Shares Data
{
if ("text/plain".equals(type))
{
String getMessage = i.getStringExtra(Intent.EXTRA_TEXT);
txt.setText("Guest Request :"+getMessage); // checks validation of string getMessage
}
}
getSupportActionBar().setTitle("Guest Request Panel");
tabLayout = (TabLayout) findViewById(R.id.tabMode);
tab1 = (TabItem) findViewById(R.id.Tab1);
tab2 = (TabItem) findViewById(R.id.Tab2);
tab3 = (TabItem) findViewById(R.id.Tab3);
viewPager = findViewById(R.id.viewpager);
pageradapter = new PageAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(pageradapter);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (tab.getPosition() == 0) {
pageradapter.notifyDataSetChanged();
} else if (tab.getPosition() == 1) {
pageradapter.notifyDataSetChanged();
} else if (tab.getPosition() == 3) {
pageradapter.notifyDataSetChanged();
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
}
}
В результате должно получиться, что сообщение, отправленное из гостевого приложения, должно появляются в приложении администратора.
xml файл, из которого будет отправлен текст:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/gradient"
tools:context=".CleaningService">
<com.google.android.material.textfield.TextInputLayout
android:layout_width="399dp"
android:layout_height="299dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="280dp"
android:layout_marginEnd="-4dp"
android:textColorHint="#FFFFFF">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text here.."
android:shadowColor="#F8F1F5F4"
android:textColor="#F8F1F5F4"
android:textColorHighlight="#F8F1F5F4"
android:textColorHint="#F1E9E9"
android:textColorLink="#F8F1F5F4"
android:textSize="24sp"
android:textStyle="normal"
android:id="@+id/et1"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/button5"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="150dp"
android:layout_marginRight="150dp"
android:layout_marginBottom="55dp"
android:text="Send"
android:textSize="24sp"
android:onClick="sendMessage"/>
<ImageView
android:id="@+id/imageView10"
android:layout_width="161dp"
android:layout_height="189dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="24dp"
app:srcCompat="@drawable/mopp" />