URLの受け渡しの処理を追加しました。
This commit is contained in:
parent
4b4f3b8666
commit
f51b1b52ce
|
@ -26,7 +26,8 @@ import com.journeyapps.barcodescanner.ScanOptions;
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
public class QRFragment extends Fragment {
|
public class QRFragment extends Fragment {
|
||||||
|
//QRコードから受け取ったURLの受け渡しの宣言
|
||||||
|
OnDataPass dataPass;
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private static final String ARG_PARAM1 = "param1";
|
||||||
|
@ -69,25 +70,23 @@ public class QRFragment extends Fragment {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FragmentからActivityへデータの受け渡しをするためのInterface
|
||||||
|
public interface OnDataPass{
|
||||||
|
void onDataPass(String urlPass);
|
||||||
|
}
|
||||||
private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
|
private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
|
||||||
result -> {
|
result -> {
|
||||||
//QRコードからデータを読み取れたかの確認
|
//QRコードからデータを読み取れたかの確認
|
||||||
if(result.getContents() == null) {
|
if(result.getContents() == null) {
|
||||||
Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
|
Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
//共有プリファレンス全体の準備
|
dataPass.onDataPass(result.getContents());
|
||||||
SharedPreferences sharedPreferences = getActivity().getSharedPreferences("default", 0);
|
//画面遷移
|
||||||
//共有プリファレンス書き込みの準備
|
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
||||||
//共有プリファレンスにURLの書き込み
|
|
||||||
editor.putString(result.getContents(),"");
|
|
||||||
//確定処理
|
|
||||||
editor.apply();
|
|
||||||
Intent intent=new Intent(getActivity(),UrlPageActivity.class);
|
Intent intent=new Intent(getActivity(),UrlPageActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.example.childguard;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
public class UrlPageActivity extends AppCompatActivity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_url_page);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user