С помощью этой справки Я хочу восстановить текст внутри файла, долго нажимаю на файл, могу выбрать приложение для использования, поэтому я беру то, которое понимаю, приложение принимает во внимание мои действия, но я не могу восстановить текст из файла. Переменная «sharedText» является нулевой. вот код ниже.
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textHello = findViewById(R.id.hello);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
Log.d(TAG," action = "+action); // = android.intent.action.SEND
Log.d(TAG," type = "+type); // = text/plain
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
Log.d(TAG, " sharedText = " + sharedText); // = null
if (sharedText != null) {
textHello.setText(sharedText);
} else {
sharedText = "it doesn't work for me";
textHello.setText(sharedText);
}
}
}
}
}
вот манифест
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
Спасибо за ваши ответы.